SyncMoonrakerClient¶
pymoonraker.sync_client.SyncMoonrakerClient
¶
Blocking wrapper for MoonrakerClient.
Runs an event loop in a background daemon thread so that async operations are transparent to the caller.
Limitation: The sync client is currently limited and cannot be used
with API namespaces (e.g. client.printer, client.files). Use the
convenience methods on this client (e.g. server_info(), gcode(),
print_start()) or use :class:MoonrakerClient for full namespace
access.
Usage::
with SyncMoonrakerClient("192.168.1.100") as client:
info = client.server_info()
print(info.klippy_state)
Source code in src/pymoonraker/sync_client.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
call
¶
call(method: str, params: dict[str, Any] | None = None, *, timeout: float | None = None) -> Any
Send a Moonraker JSON-RPC request and block for the response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
Moonraker JSON-RPC method. |
required |
params
|
dict[str, Any] | None
|
Optional request params. |
None
|
timeout
|
float | None
|
Optional timeout override in seconds. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Decoded |
Source code in src/pymoonraker/sync_client.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
connect
¶
connect() -> None
Start the background loop and connect the underlying async client.
Source code in src/pymoonraker/sync_client.py
72 73 74 75 76 77 78 79 80 | |
disconnect
¶
disconnect() -> None
Disconnect and stop the background event loop thread.
Source code in src/pymoonraker/sync_client.py
82 83 84 85 86 87 88 89 90 91 92 93 94 | |
download_file
¶
download_file(root: str, file_path: str) -> bytes
Download a file through the underlying HTTP transport.
Source code in src/pymoonraker/sync_client.py
169 170 171 | |
emergency_stop
¶
emergency_stop() -> None
Trigger an emergency stop.
Source code in src/pymoonraker/sync_client.py
134 135 136 | |
gcode
¶
gcode(script: str) -> str
Execute a G-code script.
Source code in src/pymoonraker/sync_client.py
130 131 132 | |
klippy_state
¶
klippy_state() -> KlippyState
Return the current Klippy state.
Source code in src/pymoonraker/sync_client.py
106 107 108 | |
on
¶
on(event: str | EventType, callback: Callback) -> Callable[[], None]
Register a persistent event callback.
Returns:
| Type | Description |
|---|---|
Callable[[], None]
|
Callable with no arguments that unregisters the callback. |
Source code in src/pymoonraker/sync_client.py
181 182 183 184 185 186 187 188 | |
once
¶
once(event: str | EventType, callback: Callback) -> None
Register a one-shot event callback.
Source code in src/pymoonraker/sync_client.py
190 191 192 | |
print_cancel
¶
print_cancel() -> None
Cancel the current print.
Source code in src/pymoonraker/sync_client.py
150 151 152 | |
print_pause
¶
print_pause() -> None
Pause the current print.
Source code in src/pymoonraker/sync_client.py
142 143 144 | |
print_resume
¶
print_resume() -> None
Resume the paused print.
Source code in src/pymoonraker/sync_client.py
146 147 148 | |
print_start
¶
print_start(filename: str) -> None
Start printing a file.
Source code in src/pymoonraker/sync_client.py
138 139 140 | |
printer_info
¶
printer_info() -> PrinterInfo
Query printer.info.
Source code in src/pymoonraker/sync_client.py
102 103 104 | |
query_objects
¶
query_objects(objects: dict[str, list[str] | None]) -> dict[str, Any]
Query one or more printer objects and return current status.
Source code in src/pymoonraker/sync_client.py
173 174 175 | |
server_info
¶
server_info() -> ServerInfo
Query server.info.
Source code in src/pymoonraker/sync_client.py
98 99 100 | |
subscribe_objects
¶
subscribe_objects(objects: dict[str, list[str] | None]) -> dict[str, Any]
Subscribe to printer object updates for status notifications.
Source code in src/pymoonraker/sync_client.py
177 178 179 | |
upload_file
¶
upload_file(file_path: str, content: bytes, *, root: str = 'gcodes', target_path: str | None = None) -> Any
Upload a file through the underlying HTTP transport.
Source code in src/pymoonraker/sync_client.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |