Server#

Misc#

JSON-RPC server package.

class pjrpc.server.AsyncDispatcher(*, executor=None, json_loader=<function loads>, json_dumper=<function dumps>, json_encoder=<class 'pjrpc.server.dispatcher.JSONEncoder'>, json_decoder=None, middlewares=(), max_batch_size=None)[source]#

Bases: BaseDispatcher, Generic[ContextType]

Asynchronous method dispatcher.

Parameters:
async dispatch(request_text, context)[source]#

Deserializes request, dispatches it to the required method and serializes the result.

Parameters:
  • request_text (str) – request text representation

  • context (ContextType) – application context (if supported)

Returns:

response text representation and error codes

Return type:

Optional[tuple[str, tuple[int, …]]]

class pjrpc.server.AsyncMiddlewareType(*args, **kwargs)[source]#

Bases: Protocol[ContextType]

Asynchronous middleware type

class pjrpc.server.BaseDispatcher(*, request_class=<class 'pjrpc.common.request.Request'>, response_class=<class 'pjrpc.common.response.Response'>, batch_request=<class 'pjrpc.common.request.BatchRequest'>, batch_response=<class 'pjrpc.common.response.BatchResponse'>, json_loader=<function loads>, json_dumper=<function dumps>, json_encoder=<class 'pjrpc.server.dispatcher.JSONEncoder'>, json_decoder=None, middlewares=())[source]#

Bases: object

Method dispatcher.

Parameters:
class pjrpc.server.Dispatcher(*, executor=None, json_loader=<function loads>, json_dumper=<function dumps>, json_encoder=<class 'pjrpc.server.dispatcher.JSONEncoder'>, json_decoder=None, middlewares=(), max_batch_size=None)[source]#

Bases: BaseDispatcher, Generic[ContextType]

Synchronous method dispatcher.

Parameters:
dispatch(request_text, context)[source]#

Deserializes request, dispatches it to the required method and serializes the result.

Parameters:
  • request_text (str) – request text representation

  • context (ContextType) – application context (if supported)

Returns:

response text representation and error codes

Return type:

Optional[tuple[str, tuple[int, …]]]

class pjrpc.server.JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#

Bases: JSONEncoder

Server JSON encoder. All custom server encoders should be inherited from it.

default(o)[source]#

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
Parameters:

o (Any) –

Return type:

Any

class pjrpc.server.Method(func, name=None, *, pass_context=False, validator_factory=None, metadata=())[source]#

Bases: object

JSON-RPC method wrapper. Stores method itself and some metainformation.

Parameters:
class pjrpc.server.MethodRegistry(validator_factory=None, metadata=(), metadata_processors=())[source]#

Bases: object

Method registry.

Parameters:
get(item)[source]#

Returns a method from the registry by name.

Parameters:

item (str) – method name

Returns:

found method or None

Return type:

Optional[Method]

add(name=None, *, pass_context=False, metadata=())[source]#

Decorator adding decorated method to the registry.

Parameters:
  • name (Optional[str]) – method name to be used instead of __name__ attribute

  • pass_context (Union[bool, str]) – pass application context if supported

  • metadata (Iterable[Any]) – method metadata

Returns:

decorated method or decorator

Return type:

Callable[[FunctionT], FunctionT]

add_method(method, name=None, *, pass_context=False, metadata=())[source]#

Adds the method to the registry.

Parameters:
  • method (Callable[[...], Any]) – method to be added

  • name (Optional[str]) – method name to be used instead of __name__ attribute

  • pass_context (Union[bool, str]) – pass application context if supported

  • metadata (Iterable[Any]) – method metadata

Returns:

decorated method or decorator

Return type:

MethodRegistry

class pjrpc.server.MiddlewareType(*args, **kwargs)[source]#

Bases: Protocol[ContextType]

Synchronous middleware type

Types#

pjrpc.server.typedefs.AsyncHandlerType#

Async RPC handler method, passed to middlewares

alias of Callable[[Request, ContextType], Awaitable[Union[UnsetType, Response]]]

class pjrpc.server.typedefs.AsyncMiddlewareType(*args, **kwargs)[source]#

Bases: Protocol[ContextType]

Asynchronous middleware type

pjrpc.server.typedefs.ContextType#

Context argument for RPC methods and middlewares

alias of TypeVar(‘ContextType’)

pjrpc.server.typedefs.HandlerType#

Blocking RPC handler method, passed to middlewares

alias of Callable[[Request, ContextType], Union[UnsetType, Response]]

pjrpc.server.typedefs.MiddlewareResponse#

middlewares and handlers return Response or UnsetType

alias of Union[UnsetType, Response]

class pjrpc.server.typedefs.MiddlewareType(*args, **kwargs)[source]#

Bases: Protocol[ContextType]

Synchronous middleware type

Integrations#

aiohttp#

aiohttp JSON-RPC server integration.

class pjrpc.server.integration.aiohttp.Application(prefix='', http_app=None, status_by_error=<function Application.<lambda>>, executor=None, json_loader=<function loads>, json_dumper=<function dumps>, json_encoder=<class 'pjrpc.server.dispatcher.JSONEncoder'>, json_decoder=None, middlewares=(), max_batch_size=None)[source]#

Bases: object

aiohttp based JSON-RPC server.

Parameters:
property http_app: Application#

aiohttp application.

property endpoints: Mapping[str, AsyncDispatcher[Request]]#

JSON-RPC application registered endpoints.

add_methods(registry, endpoint='')[source]#

Adds methods to the provided endpoint.

Parameters:
Return type:

Application

add_subapp(prefix, subapp)[source]#

Adds sub-application accessible under provided prefix.

Parameters:
  • prefix (str) – path under which sub-application is accessed.

  • subapp (Application) – sub-application instance

Return type:

None

add_spec(spec, endpoint='', path='')[source]#

Adds JSON-RPC specification of the provided endpoint to the provided path.

Parameters:
  • spec (Specification) – JSON-RPC specification

  • endpoint (str) – specification endpoint

  • path (str) – path under witch the specification will be accessible.

Return type:

None

add_spec_ui(path, ui, spec_url)[source]#

Adds JSON-RPC specification ui.

Parameters:
  • path (str) – path under which ui will be accessible.

  • ui (BaseUI) – specification ui instance

  • spec_url (str) – specification url

Return type:

None

generate_spec(spec, base_path='', endpoint='')[source]#

Generates JSON-RPC specification of the provided endpoint.

Parameters:
  • spec (Specification) – JSON-RPC specification

  • base_path (str) – specification base path

  • endpoint (str) – endpoint the specification is generated for

Return type:

dict[str, Any]

flask#

aio_pika#

werkzeug#

Validators#

JSON-RPC method parameters validators.

class pjrpc.server.validators.BaseValidator(method, exclude=None)[source]#

Bases: object

Base method parameters validator.

Parameters:
validate_params(params)[source]#

Validates params against method signature.

Parameters:

params (Optional[JsonRpcParamsT]) – parameters to be validated

Raises:

pjrpc.server.validators.ValidationError

Returns:

bound method parameters

Return type:

dict[str, Any]

class pjrpc.server.validators.BaseValidatorFactory(exclude=None)[source]#

Bases: object

Base method parameters validator factory. Uses inspect.signature() for validation.

Parameters:

exclude (Optional[Callable[[int, str, Optional[type[Any]], Optional[Any]], bool]]) – a function that decides if the parameters must be excluded from validation (useful for dependency injection)

exception pjrpc.server.validators.ValidationError[source]#

Bases: Exception

Method parameters validation error. Raised when parameters validation failed.

pydantic#

Specification#

class pjrpc.server.specs.JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#

Bases: JSONEncoder

Schema JSON encoder.

default(o)[source]#

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
Parameters:

o (Any) –

Return type:

Any

class pjrpc.server.specs.BaseUI[source]#

Bases: ABC

Base UI.

abstract get_static_folder()[source]#

Returns ui statics folder.

Return type:

Path

abstract get_index_page(spec_url)[source]#

Returns ui index webpage.

Parameters:

spec_url (str) – specification url.

Return type:

str

class pjrpc.server.specs.Specification[source]#

Bases: ABC

JSON-RPC specification.

abstract generate(root_endpoint, methods)[source]#

Returns specification schema.

Parameters:
  • root_endpoint (str) – root endpoint all the methods are served on

  • methods (Mapping[str, Iterable[Method]]) – methods map the specification is generated for. Each item is a mapping from a endpoint to methods on which the methods will be served

Return type:

dict[str, Any]

extractors#

class pjrpc.server.specs.extractors.BaseMethodInfoExtractor[source]#

Bases: object

Base method schema extractor.

extract_params_schema(method_name, method, ref_template)[source]#

Extracts params schema.

Parameters:
Return type:

tuple[dict[str, Any], dict[str, dict[str, Any]]]

extract_request_schema(method_name, method, ref_template)[source]#

Extracts request schema.

Parameters:
Return type:

tuple[dict[str, Any], dict[str, dict[str, Any]]]

extract_result_schema(method_name, method, ref_template)[source]#

Extracts result schema.

Parameters:
Return type:

tuple[dict[str, Any], dict[str, dict[str, Any]]]

extract_response_schema(method_name, method, ref_template, errors=None)[source]#

Extracts response schema.

Parameters:
Return type:

tuple[dict[str, Any], dict[str, dict[str, Any]]]

extract_error_response_schema(method_name, method, ref_template, errors=None)[source]#

Extracts error response schema.

Parameters:
Return type:

tuple[dict[str, Any], dict[str, dict[str, Any]]]

extract_description(method)[source]#

Extracts method description.

Parameters:

method (Callable[[...], Any]) –

Return type:

Union[UnsetType, str]

extract_summary(method)[source]#

Extracts method summary.

Parameters:

method (Callable[[...], Any]) –

Return type:

Union[UnsetType, str]

extract_errors(method)[source]#

Extracts method errors.

Parameters:

method (Callable[[...], Any]) –

Return type:

Union[UnsetType, list[type[pjrpc.common.exceptions.TypedError]]]

extract_deprecation_status(method)[source]#

Extracts method deprecation status.

Parameters:

method (Callable[[...], Any]) –

Return type:

Union[UnsetType, bool]

schemas#

openapi#

OpenAPI Specification generator. See https://swagger.io/specification/.

class pjrpc.server.specs.openapi.ApiKeyLocation(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: str, Enum

The location of the API key.

class pjrpc.server.specs.openapi.Components(schemas=UnsetType.UNSET, responses=UnsetType.UNSET, parameters=UnsetType.UNSET, examples=UnsetType.UNSET, requestBodies=UnsetType.UNSET, headers=UnsetType.UNSET, securitySchemes=UnsetType.UNSET, links=UnsetType.UNSET, pathItems=UnsetType.UNSET)[source]#

Bases: object

Holds a set of reusable objects for different aspects of the OAS.

Parameters:
class pjrpc.server.specs.openapi.Contact(name=UnsetType.UNSET, url=UnsetType.UNSET, email=UnsetType.UNSET)[source]#

Bases: object

Contact information for the exposed API.

Parameters:
class pjrpc.server.specs.openapi.Encoding(contentType=UnsetType.UNSET, headers=UnsetType.UNSET, style=UnsetType.UNSET, explode=UnsetType.UNSET, allowReserved=UnsetType.UNSET)[source]#

Bases: object

A single encoding definition applied to a single schema property.

Parameters:
class pjrpc.server.specs.openapi.ExampleObject(value=UnsetType.UNSET, summary=UnsetType.UNSET, description=UnsetType.UNSET, externalValue=UnsetType.UNSET)[source]#

Bases: object

Method usage example.

Parameters:
class pjrpc.server.specs.openapi.ExternalDocumentation(url, description=UnsetType.UNSET)[source]#

Bases: object

Allows referencing an external resource for extended documentation.

Parameters:
  • url (str) – a short description of the target documentation.

  • description (Union[UnsetType, str]) – the URL for the target documentation

pjrpc.server.specs.openapi.Header#

alias of Parameter

class pjrpc.server.specs.openapi.Info(title, version, summary=UnsetType.UNSET, description=UnsetType.UNSET, contact=UnsetType.UNSET, license=UnsetType.UNSET, termsOfService=UnsetType.UNSET)[source]#

Bases: object

Metadata about the API.

Parameters:
class pjrpc.server.specs.openapi.License(name, identifier=UnsetType.UNSET, url=UnsetType.UNSET)[source]#

Bases: object

License information for the exposed API.

Parameters:
  • name (str) – the license name used for the API

  • identifier (Union[UnsetType, str]) – an SPDX license expression for the API

  • url (Union[UnsetType, str]) – a URL to the license used for the API

Bases: object

The Link object represents a possible design-time link for a response.

Parameters:
  • operationRef (Union[UnsetType, str]) – a relative or absolute URI reference to an OAS operation

  • operationId (Union[UnsetType, str]) – the name of an existing, resolvable OAS operation, as defined with a unique operationId

  • parameters (Union[UnsetType, dict[str, Any]]) – a map representing parameters to pass to an operation as specified with operationId or identified via operationRef

  • requestBody (Union[UnsetType, Any]) – a literal value or {expression} to use as a request body when calling the target operation

  • description (Union[UnsetType, str]) – a description of the link

  • server (Union[UnsetType, Server]) – a server object to be used by the target operation.

class pjrpc.server.specs.openapi.MediaType(schema=UnsetType.UNSET, example=UnsetType.UNSET, examples=UnsetType.UNSET, encoding=UnsetType.UNSET)[source]#

Bases: object

Each Media Type Object provides schema and examples for the media type identified by its key.

Parameters:
pjrpc.server.specs.openapi.metadata(params_schema=UnsetType.UNSET, result_schema=UnsetType.UNSET, errors=UnsetType.UNSET, examples=UnsetType.UNSET, tags=UnsetType.UNSET, summary=UnsetType.UNSET, description=UnsetType.UNSET, external_docs=UnsetType.UNSET, deprecated=UnsetType.UNSET, security=UnsetType.UNSET, parameters=UnsetType.UNSET, servers=UnsetType.UNSET, component_name_prefix=UnsetType.UNSET)[source]#

Adds Open Api specification annotation to the method.

Parameters:
Return type:

MethodMetadata

class pjrpc.server.specs.openapi.MethodExample(params, result, version='2.0', summary=UnsetType.UNSET, description=UnsetType.UNSET)[source]#

Bases: object

Method usage example.

Parameters:
  • params (dict[str, Any]) – example parameters

  • result (Any) – example result

  • summary (Union[UnsetType, str]) – short description for the example pairing

  • description (Union[UnsetType, str]) – a verbose explanation of the example pairing

  • version (str) –

class pjrpc.server.specs.openapi.MethodMetadata(params_schema: Union[pjrpc.common.common.UnsetType, dict[str, dict[str, Union[str, int, float, dict[str, 'Json'], bool, list['Json'], tuple['Json'], set['Json'], NoneType]]]] = UNSET, result_schema: Union[pjrpc.common.common.UnsetType, dict[str, Union[str, int, float, dict[str, 'Json'], bool, list['Json'], tuple['Json'], set['Json'], NoneType]]] = UNSET, examples: Union[pjrpc.common.common.UnsetType, list[pjrpc.server.specs.openapi.spec.MethodExample]] = UNSET, tags: Union[pjrpc.common.common.UnsetType, list[pjrpc.server.specs.openapi.spec.Tag]] = UNSET, summary: Union[pjrpc.common.common.UnsetType, str] = UNSET, description: Union[pjrpc.common.common.UnsetType, str] = UNSET, external_docs: Union[pjrpc.common.common.UnsetType, pjrpc.server.specs.openapi.spec.ExternalDocumentation] = UNSET, deprecated: Union[pjrpc.common.common.UnsetType, bool] = UNSET, security: Union[pjrpc.common.common.UnsetType, list[dict[str, list[str]]]] = UNSET, parameters: Union[pjrpc.common.common.UnsetType, list[pjrpc.server.specs.openapi.spec.Parameter]] = UNSET, servers: Union[pjrpc.common.common.UnsetType, list[pjrpc.server.specs.openapi.spec.Server]] = UNSET, component_name_prefix: Union[pjrpc.common.common.UnsetType, str] = UNSET, errors: Union[pjrpc.common.common.UnsetType, list[type[pjrpc.common.exceptions.TypedError]]] = UNSET)[source]#

Bases: object

Parameters:
class pjrpc.server.specs.openapi.OAuthFlow(authorizationUrl, tokenUrl, scopes, refreshUrl=UnsetType.UNSET)[source]#

Bases: object

Configuration details for a supported OAuth Flow.

Parameters:
  • authorizationUrl (str) – the authorization URL to be used for this flow

  • tokenUrl (str) – the token URL to be used for this flow

  • refreshUrl (Union[UnsetType, str]) – the URL to be used for obtaining refresh tokens

  • scopes (dict[str, str]) – the available scopes for the OAuth2 security scheme

class pjrpc.server.specs.openapi.OAuthFlows(implicit=UnsetType.UNSET, password=UnsetType.UNSET, clientCredentials=UnsetType.UNSET, authorizationCode=UnsetType.UNSET)[source]#

Bases: object

Configuration of the supported OAuth Flows.

Parameters:
class pjrpc.server.specs.openapi.OpenAPI(info, servers=UnsetType.UNSET, external_docs=UnsetType.UNSET, tags=UnsetType.UNSET, security=UnsetType.UNSET, security_schemes=UnsetType.UNSET, openapi='3.1.0', json_schema_dialect=UnsetType.UNSET)[source]#

Bases: Specification

OpenAPI Specification.

Parameters:
generate(root_endpoint, methods)[source]#

Returns specification schema.

Parameters:
  • root_endpoint (str) – root endpoint all the methods are served on

  • methods (Mapping[str, Iterable[Method]]) – methods map the specification is generated for. Each item is a mapping from a endpoint to methods on which the methods will be served

Return type:

dict[str, Any]

class pjrpc.server.specs.openapi.Operation(responses=UnsetType.UNSET, requestBody=UnsetType.UNSET, tags=UnsetType.UNSET, summary=UnsetType.UNSET, description=UnsetType.UNSET, externalDocs=UnsetType.UNSET, operationId=UnsetType.UNSET, deprecated=UnsetType.UNSET, servers=UnsetType.UNSET, security=UnsetType.UNSET, parameters=UnsetType.UNSET)[source]#

Bases: object

Describes a single API operation on a path.

Parameters:
class pjrpc.server.specs.openapi.Parameter(name, location, description=UnsetType.UNSET, required=UnsetType.UNSET, deprecated=UnsetType.UNSET, allowEmptyValue=UnsetType.UNSET, style=UnsetType.UNSET, explode=UnsetType.UNSET, allowReserved=UnsetType.UNSET, schema=UnsetType.UNSET, example=UnsetType.UNSET, examples=UnsetType.UNSET, content=UnsetType.UNSET)[source]#

Bases: object

Describes a single operation parameter.

Parameters:
class pjrpc.server.specs.openapi.ParameterLocation(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: str, Enum

The location of the parameter.

class pjrpc.server.specs.openapi.Path(get=UnsetType.UNSET, put=UnsetType.UNSET, post=UnsetType.UNSET, delete=UnsetType.UNSET, options=UnsetType.UNSET, head=UnsetType.UNSET, patch=UnsetType.UNSET, trace=UnsetType.UNSET, summary=UnsetType.UNSET, description=UnsetType.UNSET, servers=UnsetType.UNSET, parameters=UnsetType.UNSET)[source]#

Bases: object

Describes the interface for the given method name.

Parameters:
class pjrpc.server.specs.openapi.Reference(ref, summary=UnsetType.UNSET, description=UnsetType.UNSET)[source]#

Bases: object

A simple object to allow referencing other components in the OpenAPI document, internally and externally.

Parameters:
  • ref (str) – the reference identifier.

  • summary (Union[UnsetType, str]) – a short summary which by default SHOULD override that of the referenced component.

  • description (Union[UnsetType, str]) – a description which by default SHOULD override that of the referenced component

class pjrpc.server.specs.openapi.RequestBody(content, required=UnsetType.UNSET, description=UnsetType.UNSET)[source]#

Bases: object

Describes a single request body.

Parameters:
class pjrpc.server.specs.openapi.Response(description, headers=UnsetType.UNSET, content=UnsetType.UNSET, links=UnsetType.UNSET)[source]#

Bases: object

A container for the expected responses of an operation.

Parameters:
class pjrpc.server.specs.openapi.SecurityScheme(type, scheme=UnsetType.UNSET, name=UnsetType.UNSET, location=UnsetType.UNSET, bearerFormat=UnsetType.UNSET, flows=UnsetType.UNSET, openIdConnectUrl=UnsetType.UNSET, description=UnsetType.UNSET)[source]#

Bases: object

Defines a security scheme that can be used by the operations.

Parameters:
class pjrpc.server.specs.openapi.SecuritySchemeType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: str, Enum

The type of the security scheme.

class pjrpc.server.specs.openapi.Server(url, description=UnsetType.UNSET, variables=UnsetType.UNSET)[source]#

Bases: object

Connectivity information of a target server.

Parameters:
class pjrpc.server.specs.openapi.ServerVariable(default, enum=UnsetType.UNSET, description=UnsetType.UNSET)[source]#

Bases: object

An object representing a Server Variable for server URL template substitution.

Parameters:
  • default (str) – the default value to use for substitution, which SHALL be sent if an alternate value is not supplied

  • enum (Union[UnsetType, list[str]]) – an enumeration of string values to be used if the substitution options are from a limited set

  • description (Union[UnsetType, str]) – an optional description for the server variable

class pjrpc.server.specs.openapi.SpecRoot(info, paths, components, servers=UnsetType.UNSET, externalDocs=UnsetType.UNSET, tags=UnsetType.UNSET, security=UnsetType.UNSET, openapi='3.1.0', jsonSchemaDialect=UnsetType.UNSET)[source]#

Bases: object

The root object of the OpenAPI description.

Parameters:
class pjrpc.server.specs.openapi.StyleType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: str, Enum

Describes how the parameter value will be serialized depending on the type of the parameter value.

class pjrpc.server.specs.openapi.Tag(name, description=UnsetType.UNSET, externalDocs=UnsetType.UNSET)[source]#

Bases: object

A list of tags for API documentation control. Tags can be used for logical grouping of methods by resources or any other qualifier.

Parameters:

openrpc#

OpenRPC specification generator. See https://spec.open-rpc.org/.

class pjrpc.server.specs.openrpc.Components(contentDescriptors=UnsetType.UNSET, schemas=UnsetType.UNSET, examples=UnsetType.UNSET, links=UnsetType.UNSET, errors=UnsetType.UNSET, examplePairingObjects=UnsetType.UNSET, tags=UnsetType.UNSET)[source]#

Bases: object

Set of reusable objects for different aspects of the OpenRPC.

Parameters:
class pjrpc.server.specs.openrpc.Contact(name=UnsetType.UNSET, url=UnsetType.UNSET, email=UnsetType.UNSET)[source]#

Bases: object

Contact information for the exposed API.

Parameters:
class pjrpc.server.specs.openrpc.ContentDescriptor(name, schema, summary=UnsetType.UNSET, description=UnsetType.UNSET, required=UnsetType.UNSET, deprecated=UnsetType.UNSET)[source]#

Bases: object

Content Descriptors are objects that describe content. They are reusable ways of describing either parameters or result.

Parameters:
class pjrpc.server.specs.openrpc.Error(code, message, data=UnsetType.UNSET)[source]#

Bases: object

Defines an application level error.

Parameters:
  • code (int) – a Number that indicates the error type that occurred

  • message (str) – a String providing a short description of the error

  • data (Union[UnsetType, Any]) – a Primitive or Structured value that contains additional information about the error

class pjrpc.server.specs.openrpc.ExampleObject(value, name, summary=UnsetType.UNSET, description=UnsetType.UNSET, externalValue=UnsetType.UNSET)[source]#

Bases: object

The ExampleObject object is an object the defines an example.

Parameters:
  • value (Any) – embedded literal example

  • name (str) – canonical name of the example

  • summary (Union[UnsetType, str]) – short description for the example

  • description (Union[UnsetType, str]) – a verbose explanation of the example

  • externalValue (Union[UnsetType, str]) – a URL that points to the literal example.

class pjrpc.server.specs.openrpc.ExternalDocumentation(url, description=UnsetType.UNSET)[source]#

Bases: object

Allows referencing an external resource for extended documentation.

Parameters:
  • url (str) – A verbose explanation of the target documentation

  • description (Union[UnsetType, str]) – The URL for the target documentation. Value MUST be in the format of a URL

class pjrpc.server.specs.openrpc.Info(title, version, description=UnsetType.UNSET, contact=UnsetType.UNSET, license=UnsetType.UNSET, termsOfService=UnsetType.UNSET)[source]#

Bases: object

Metadata about the API.

Parameters:
  • title (str) – the title of the application

  • version (str) – the version of the OpenRPC document

  • description (Union[UnsetType, str]) – a verbose description of the application

  • contact (Union[UnsetType, Contact]) – the contact information for the exposed API

  • license (Union[UnsetType, License]) – the license information for the exposed API

  • termsOfService (Union[UnsetType, str]) – a URL to the Terms of Service for the API

class pjrpc.server.specs.openrpc.License(name, url=UnsetType.UNSET)[source]#

Bases: object

License information for the exposed API.

Parameters:
  • name (str) – the license name used for the API

  • url (Union[UnsetType, str]) – a URL to the license used for the API

Bases: object

Parameters:
  • name (str) – Canonical name of the link.

  • description (Union[UnsetType, str]) – A description of the link.

  • summary (Union[UnsetType, str]) – Short description for the link.

  • method (Union[UnsetType, str]) – The name of an existing, resolvable OpenRPC method, as defined with a unique method.

  • params (Union[UnsetType, dict[str, Any]]) – A map representing parameters to pass to a method as specified with method. The key is the parameter name to be used, whereas the value can be a constant or a runtime expression to be evaluated and passed to the linked method.

  • server (Union[UnsetType, Server]) – A server object to be used by the target method.

pjrpc.server.specs.openrpc.metadata(params_schema=UnsetType.UNSET, result_schema=UnsetType.UNSET, errors=UnsetType.UNSET, examples=UnsetType.UNSET, summary=UnsetType.UNSET, description=UnsetType.UNSET, tags=UnsetType.UNSET, deprecated=UnsetType.UNSET, external_docs=UnsetType.UNSET, servers=UnsetType.UNSET)[source]#

Adds JSON-RPC method to the API specification.

Parameters:
Return type:

MethodMetadata

class pjrpc.server.specs.openrpc.MethodExample(name, params, result, summary=UnsetType.UNSET, description=UnsetType.UNSET)[source]#

Bases: object

The example Pairing object consists of a set of example params and result.

Parameters:
class pjrpc.server.specs.openrpc.MethodInfo(name, params, result, errors=UnsetType.UNSET, links=UnsetType.UNSET, paramStructure=UnsetType.UNSET, examples=UnsetType.UNSET, summary=UnsetType.UNSET, description=UnsetType.UNSET, tags=UnsetType.UNSET, deprecated=UnsetType.UNSET, externalDocs=UnsetType.UNSET, servers=UnsetType.UNSET)[source]#

Bases: object

Describes the interface for the given method name.

Parameters:
class pjrpc.server.specs.openrpc.MethodMetadata(params_schema: Union[pjrpc.common.common.UnsetType, list[pjrpc.server.specs.openrpc.spec.ContentDescriptor]] = UNSET, result_schema: Union[pjrpc.common.common.UnsetType, pjrpc.server.specs.openrpc.spec.ContentDescriptor] = UNSET, errors: Union[pjrpc.common.common.UnsetType, list[pjrpc.server.specs.openrpc.spec.Error]] = UNSET, examples: Union[pjrpc.common.common.UnsetType, list[Union[pjrpc.server.specs.openrpc.spec.MethodExample, pjrpc.server.specs.openrpc.spec.Reference]]] = UNSET, tags: Union[pjrpc.common.common.UnsetType, list[Union[pjrpc.server.specs.openrpc.spec.Tag, pjrpc.server.specs.openrpc.spec.Reference]]] = UNSET, summary: Union[pjrpc.common.common.UnsetType, str] = UNSET, description: Union[pjrpc.common.common.UnsetType, str] = UNSET, deprecated: Union[pjrpc.common.common.UnsetType, bool] = UNSET, external_docs: Union[pjrpc.common.common.UnsetType, pjrpc.server.specs.openrpc.spec.ExternalDocumentation] = UNSET, servers: Union[pjrpc.common.common.UnsetType, list[pjrpc.server.specs.openrpc.spec.Server]] = UNSET)[source]#

Bases: object

Parameters:
class pjrpc.server.specs.openrpc.OpenRPC(info, servers=UnsetType.UNSET, external_docs=UnsetType.UNSET, openrpc='1.3.2')[source]#

Bases: Specification

OpenRPC Specification.

Parameters:
generate(root_endpoint, methods)[source]#

Returns specification schema.

Parameters:
  • root_endpoint (str) – root endpoint all the methods are served on

  • methods (Mapping[str, Iterable[Method]]) – methods map the specification is generated for. Each item is a mapping from a endpoint to methods on which the methods will be served

Return type:

dict[str, Any]

class pjrpc.server.specs.openrpc.ParamStructure(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: str, Enum

The expected format of the parameters.

class pjrpc.server.specs.openrpc.Reference(ref)[source]#

Bases: object

A simple object to allow referencing other components in the specification, internally and externally. :param ref: the reference identifier.

Parameters:

ref (str) –

class pjrpc.server.specs.openrpc.Server(name, url, summary=UnsetType.UNSET, description=UnsetType.UNSET, variables=UnsetType.UNSET)[source]#

Bases: object

Connectivity information of a target server.

Parameters:
class pjrpc.server.specs.openrpc.ServerVariable(default, enum=UnsetType.UNSET, description=UnsetType.UNSET)[source]#

Bases: object

An object representing a Server Variable for server URL template substitution.

Parameters:
  • default (str) – The default value to use for substitution.

  • enum (Union[UnsetType, list[str]]) – An enumeration of string values to be used if the substitution options are from a limited set.

  • description (Union[UnsetType, str]) – An optional description for the server variable.

class pjrpc.server.specs.openrpc.SpecRoot(info, components, methods=<factory>, servers=UnsetType.UNSET, externalDocs=UnsetType.UNSET, openrpc='1.3.2')[source]#

Bases: object

The root object of the OpenRPC document.

Parameters:
class pjrpc.server.specs.openrpc.Tag(name, description=UnsetType.UNSET, externalDocs=UnsetType.UNSET)[source]#

Bases: object

A list of tags for API documentation control. Tags can be used for logical grouping of methods by resources or any other qualifier.

Parameters: