lexrpc package
Reference documentation.
client
XRPC client implementation.
- class lexrpc.client.Client(address, lexicons, **kwargs)[source]
Bases:
Base
XRPC client.
- __init__(address, lexicons, **kwargs)[source]
Constructor.
- Parameters:
lexicon – sequence of dict lexicons
- Raises:
jsonschema.SchemaError – if any schema is invalid
- call(nsid, input, **params)[source]
Makes a remote XRPC method call.
- Parameters:
nsid – str, method NSID
input – dict, input body
params – optional method parameters
Returns: decoded JSON object, or None if the method has no output
- Raises:
NotImplementedError – if the given NSID is not found in any of the loaded lexicons
jsonschema.ValidationError – if the parameters, input, or returned output don’t validate against the method’s schemas
requests.RequestException – if the connection or HTTP request to the remote server failed
server
XRPC server implementation.
- class lexrpc.server.Server(*args, **kwargs)[source]
Bases:
Base
XRPC server base class. Subclass to implement specific methods.
- __init__(*args, **kwargs)[source]
Constructor.
- Parameters:
lexicon – sequence of dict lexicons
- Raises:
jsonschema.SchemaError – if any schema is invalid
- method(nsid)[source]
XRPC method decorator. Use on each function that implements a method.
- Parameters:
fn – callable
nsid – str
- call(nsid, input, **params)[source]
Calls an XRPC query or procedure method.
- Parameters:
nsid – str, method NSID
input – dict, input body
params – optional parameters
- Raises:
NotImplementedError – if the given NSID is not implemented or found in any of the loaded lexicons
jsonschema.ValidationError – if the parameters, input, or returned output don’t validate against the method’s schemas
flask_server
Flask handler for /xrpc/… endpoint.
- lexrpc.flask_server.init_flask(xrpc_server, app)[source]
Connects a
lexrpc.Server
to serve on /xrpc/… on a Flask app.- Parameters:
xrpc_server –
lexrpc.Server
app –
flask.Flask
base
Base code shared by both server and client.
- class lexrpc.base.Base(lexicons, validate=True)[source]
Bases:
object
Base class for both XRPC client and server.
- __init__(lexicons, validate=True)[source]
Constructor.
- Parameters:
lexicons – sequence of dict lexicons
validate – boolean, whether to validate schemas, parameters, and input and output bodies
- Raises:
jsonschema.SchemaError – if any schema is invalid
- __weakref__
list of weak references to the object (if defined)
- encode_params(params)[source]
Encodes decoded parameter values.
Based on https://atproto.com/specs/xrpc#path
- Parameters:
params – dict mapping str names to boolean, number, or str values
Returns: dict mapping str names to str encoded values
- decode_params(method_nsid, params)[source]
Decodes encoded parameter values.
Based on https://atproto.com/specs/xrpc#path
- Parameters:
method_nsid – str
params – dict mapping str names to encoded str values
Returns: dict mapping str names to decoded boolean, number, and str values
- Raises:
ValueError – if a parameter value can’t be decoded
NotImplementedError – if no method lexicon is registered for the given NSID