Network Clients¶
Synchronous network clients for interacting with the XRPL.
- class xrpl.clients.JsonRpcClient(url: str)¶
A sync client for interacting with the rippled JSON RPC.
- request(request: xrpl.models.requests.request.Request) → xrpl.models.response.Response¶
Makes a request with this client.
- Parameters
request – The Request to send.
- Returns
The Response for the given Request.
- class xrpl.clients.WebsocketClient(url: str, timeout: Optional[Union[int, float]] = None)¶
A sync client for interacting with the rippled WebSocket API.
Instead of calling
open
andclose
yourself, you can use a context like so:with WebsocketClient(url) as client: # do stuff with client
Doing this will open and close the client for you and is preferred.
To read messages from the client, you can iterate over the client like so:
with WebsocketClient(url) as client: for message in client: # do something with a message
NOTE: doing the above will cause the client to listen for messages indefinitely. For this reason,
WebsocketClient
takes an optionaltimeout
parameter which will stop iterating on messages if none are received in that timeframe. Generally, if you have complex needs with python, xrpl, and websockets, you should consider using theasyncio
support provided by this library and thexrpl.asyncio.clients.AsyncWebsocketClient
instead.- close() → None¶
Closes the connection.
- is_open() → bool¶
Returns whether the WebsocketClient is currently open.
- Returns
Whether the WebsocketClient is currently open.
- open() → None¶
Connects the client to the Web Socket API at the given URL.
- request(request: xrpl.models.requests.request.Request) → xrpl.models.response.Response¶
Makes a request with this client.
- Parameters
request – The Request to send.
- Returns
The Response for the given Request.
- send(request: xrpl.models.requests.request.Request) → None¶
Submit the request represented by the request to the rippled node specified by this client’s URL.
- Parameters
request – A Request object representing information about a rippled request.
- Raises
XRPLWebsocketException – If there is already an open request by the request’s ID, or if this WebsocketClient is not open.
- exception xrpl.clients.XRPLRequestFailureException(result: Dict[str, Any])¶
XRPL Request Exception, when the request fails.
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- xrpl.clients.json_to_response(json: Dict[str, Any]) → xrpl.models.response.Response¶
Converts a JSON response from the rippled server into a Response object.
- Parameters
json – A dictionary representing the contents of the json response from the rippled server.
- Returns
A Response object containing the information in the rippled server’s response.
- xrpl.clients.request_to_json_rpc(request_object: xrpl.models.requests.request.Request) → Dict[str, Any]¶
Converts a request model object to the appropriate JSON format for interacting with the rippled API.
- Parameters
request_object – A Request object representing the parameters of a request to the rippled JSON RPC.
- Returns
A dictionary containing the attributes of this Request object formatted for submission to the rippled JSON RPC.
- xrpl.clients.request_to_websocket(request_object: xrpl.models.requests.request.Request) → Dict[str, Any]¶
Converts a request model object to the appropriate format for interacting with the rippled API via the WebSocket API.
- Parameters
request_object – A Request object representing the parameters of a request to the rippled JSON RPC.
- Returns
A dictionary containing the attributes of this Request object formatted for submission to the rippled WebSocket API.
- xrpl.clients.websocket_to_response(response_dict: Dict[str, Any]) → xrpl.models.response.Response¶
Converts a WebSocket API response from the rippled server into a Response object.
- Parameters
response_dict – A dictionary representing the contents of the WebSocket API response from the rippled server.
- Returns
A Response object containing the information in the rippled server’s response.