JSON-RPC¶
JSON-RPC client and data models.
JSONValueType = Union[str, int, float, bool, None]
module-attribute
¶
JSONRPCPayload
¶
Bases: typing_extensions.TypedDict
A rpc call is represented by sending a Request object to a Server.
See: https://www.jsonrpc.org/specification#request_object
JSONRPCResponse
¶
Bases: typing_extensions.TypedDict
When a rpc call is made, the Server MUST reply with a Response.
See: https://www.jsonrpc.org/specification#response_object
JSONRPCError
¶
JSONRPCResponseError(error: JSONRPCError)
¶
Bases: Exception
Exception used when a rpc call encounters an error.
Source code in pytvpaint/george/client/rpc.py
60 61 | |
JSONRPCClient(url: str, timeout: int | None = 60, version: str = '2.0')
¶
Simple JSON-RPC 2.0 client over websockets with thread-safe automatic reconnection.
See: https://www.jsonrpc.org/specification#notification
Initialize a new JSON-RPC client with a WebSocket url endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
the WebSocket url endpoint |
required |
timeout
|
int | None
|
the continuous reconnection timeout threshold |
60
|
version
|
str
|
The JSON-RPC version. Defaults to "2.0". |
'2.0'
|
Source code in pytvpaint/george/client/rpc.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
ws_handle = WebSocket()
instance-attribute
¶
url = url
instance-attribute
¶
rpc_id = 0
instance-attribute
¶
timeout = timeout
instance-attribute
¶
jsonrpc_version = version
instance-attribute
¶
stop_ping = threading.Event()
instance-attribute
¶
run_forever = False
instance-attribute
¶
ping_thread: threading.Thread | None = None
instance-attribute
¶
is_connected: bool
property
¶
Returns True if the client is connected and the socket is physically active.
connect() -> None
¶
Connects to the WebSocket endpoint and initializes the monitoring thread.
Source code in pytvpaint/george/client/rpc.py
136 137 138 139 140 141 142 143 144 145 146 | |
disconnect() -> None
¶
Disconnects from the server and halts the monitoring thread.
Source code in pytvpaint/george/client/rpc.py
148 149 150 151 152 153 154 155 156 | |
increment_rpc_id() -> None
¶
Increments the internal RPC id until it reaches sys.maxsize.
Source code in pytvpaint/george/client/rpc.py
158 159 160 | |
execute_remote(method: str, params: list[JSONValueType] | None = None) -> JSONRPCResponse
¶
Executes a remote procedure call synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
the name of the method to be invoked |
required |
params
|
list[pytvpaint.george.client.rpc.JSONValueType] | None
|
the parameter values to be used during the invocation of the method. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ConnectionError
|
if the client is not connected |
pytvpaint.george.client.rpc.JSONRPCResponseError
|
if there was an error server-side |
Returns:
| Name | Type | Description |
|---|---|---|
JSONRPCResponse |
pytvpaint.george.client.rpc.JSONRPCResponse
|
the JSON-RPC response payload |
Source code in pytvpaint/george/client/rpc.py
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 | |