Server#
Misc#
JSON-RPC server package.
- class pjrpc.server.AsyncDispatcher(*, request_class=<class 'pjrpc.common.v20.Request'>, response_class=<class 'pjrpc.common.v20.Response'>, batch_request=<class 'pjrpc.common.v20.BatchRequest'>, batch_response=<class 'pjrpc.common.v20.BatchResponse'>, json_loader=<function loads>, json_dumper=<function dumps>, json_encoder=<class 'pjrpc.server.dispatcher.JSONEncoder'>, json_decoder=None, middlewares=(), error_handlers={}, max_batch_size=None, concurrent_batch=True)[source]#
Bases:
BaseDispatcherAsynchronous method dispatcher.
- Parameters:
batch_request (Type[BatchRequest]) –
batch_response (Type[BatchResponse]) –
json_encoder (Type[JSONEncoder]) –
middlewares (Iterable[AsyncMiddlewareType]) –
error_handlers (Dict[Union[None, int, Exception], List[AsyncErrorHandlerType]]) –
concurrent_batch (bool) –
- class pjrpc.server.BaseDispatcher(*, request_class=<class 'pjrpc.common.v20.Request'>, response_class=<class 'pjrpc.common.v20.Response'>, batch_request=<class 'pjrpc.common.v20.BatchRequest'>, batch_response=<class 'pjrpc.common.v20.BatchResponse'>, json_loader=<function loads>, json_dumper=<function dumps>, json_encoder=<class 'pjrpc.server.dispatcher.JSONEncoder'>, json_decoder=None, middlewares=(), error_handlers={})[source]#
Bases:
objectMethod dispatcher.
- Parameters:
batch_request (Type[BatchRequest]) – JSON-RPC batch request class
batch_response (Type[BatchResponse]) – JSON-RPC batch response class
json_encoder (Type[JSONEncoder]) – response json encoder
json_decoder (Optional[Type[JSONDecoder]]) – request json decoder
middlewares (Iterable[Callable[[...], Any]]) – request middlewares
error_handlers (Dict[Union[None, int, Exception], List[Callable[[...], Any]]]) – request error handlers
- add_methods(*methods)[source]#
Adds methods to the registry.
- Parameters:
methods (Union[MethodRegistry, Method, Callable[[...], Any]]) – method list. Each method may be an instance of
pjrpc.server.MethodRegistry,pjrpc.server.Methodor plain function- Return type:
None
- class pjrpc.server.Dispatcher(*, request_class=<class 'pjrpc.common.v20.Request'>, response_class=<class 'pjrpc.common.v20.Response'>, batch_request=<class 'pjrpc.common.v20.BatchRequest'>, batch_response=<class 'pjrpc.common.v20.BatchResponse'>, json_loader=<function loads>, json_dumper=<function dumps>, json_encoder=<class 'pjrpc.server.dispatcher.JSONEncoder'>, json_decoder=None, middlewares=(), error_handlers={}, max_batch_size=None)[source]#
Bases:
BaseDispatcherSynchronous method dispatcher.
- Parameters:
batch_request (Type[BatchRequest]) –
batch_response (Type[BatchResponse]) –
json_encoder (Type[JSONEncoder]) –
middlewares (Iterable[MiddlewareType]) –
error_handlers (Dict[Union[None, int, Exception], List[ErrorHandlerType]]) –
- 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:
JSONEncoderServer 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 aTypeError).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 JSONEncoder.default(self, o)
- class pjrpc.server.Method(method, name=None, context=None, positional=False)[source]#
Bases:
objectJSON-RPC method wrapper. Stores method itself and some metainformation.
- class pjrpc.server.MethodRegistry(prefix=None)[source]#
Bases:
objectMethod registry.
- add(maybe_method=None, name=None, context=None, positional=False)[source]#
Decorator adding decorated method to the registry.
- Parameters:
- Returns:
decorated method or decorator
- Return type:
- add_methods(*methods)[source]#
Adds methods to the registry.
- Parameters:
methods (Union[Callable[[...], Any], Method]) – methods to be added. Each one can be an instance of
pjrpc.server.Methodor plain method- Return type:
None
- merge(other)[source]#
Merges two registries.
- Parameters:
other (MethodRegistry) – registry to be merged in the current one
- Return type:
None
Types#
- pjrpc.server.typedefs.AsyncErrorHandlerType#
Asynchronous server error handler
alias of
Callable[[Request,Optional[Any],JsonRpcError],Awaitable[JsonRpcError]]
- pjrpc.server.typedefs.AsyncMiddlewareType#
Asynchronous middleware type
alias of
Callable[[Request,Optional[Any],Callable[[Request,Optional[Any]],Awaitable[Union[UnsetType,Response]]]],Awaitable[Union[UnsetType,Response]]]
- pjrpc.server.typedefs.AsyncHandlerType#
Async RPC handler method, passed to middlewares
alias of
Callable[[Request,Optional[Any]],Awaitable[Union[UnsetType,Response]]]
- pjrpc.server.typedefs.MiddlewareResponse#
middlewares and handlers return Response or UnsetType
- pjrpc.server.typedefs.MiddlewareType#
Synchronous middleware type
alias of
Callable[[Request,Optional[Any],Callable[[Request,Optional[Any]],Union[UnsetType,Response]]],Union[UnsetType,Response]]
- pjrpc.server.typedefs.ErrorHandlerType#
Synchronous server error handler
alias of
Callable[[Request,Optional[Any],JsonRpcError],JsonRpcError]
- pjrpc.server.typedefs.ExcludeFunc#
Parameter exclude function
alias of
Callable[[str,Optional[Type[Any]],Optional[Any]],bool]
- pjrpc.server.typedefs.ResponseOrUnset#
Return value of RPC handlers and middlewares
Integrations#
aiohttp#
aiohttp JSON-RPC server integration.
- class pjrpc.server.integration.aiohttp.Application(path='', spec=None, specs=(), app=None, status_by_error=<function Application.<lambda>>, **kwargs)[source]#
Bases:
objectaiohttp based JSON-RPC server.
- Parameters:
path (str) – JSON-RPC handler base path
spec (Optional[Specification]) – api specification instance
app (Optional[Application]) – aiohttp application instance
status_by_error (Callable[[Tuple[int, ...]], int]) – a function returns http status code by json-rpc error codes, 200 for all errors by default
kwargs (Any) – arguments to be passed to the dispatcher
pjrpc.server.AsyncDispatcherspecs (Iterable[Specification]) –
- property app: Application#
aiohttp application.
- property dispatcher: AsyncDispatcher#
JSON-RPC method dispatcher.
- property endpoints: Mapping[str, AsyncDispatcher]#
JSON-RPC application registered endpoints.
- add_subapp(prefix, subapp)[source]#
Adds sub-application.
- Parameters:
prefix (str) – sub-application prefix
subapp (Application) – sub-application to be added
- Return type:
None
- add_endpoint(prefix, subapp=None, **kwargs)[source]#
Adds additional endpoint.
- Parameters:
prefix (str) – endpoint prefix
subapp (Optional[Application]) – aiohttp subapp the endpoint will be served on
kwargs (Any) – arguments to be passed to the dispatcher
pjrpc.server.Dispatcher
- Returns:
dispatcher
- Return type:
flask#
Flask JSON-RPC extension.
- class pjrpc.server.integration.flask.JsonRPC(path, spec=None, specs=(), status_by_error=<function JsonRPC.<lambda>>, **kwargs)[source]#
Bases:
objectFlask framework JSON-RPC extension class.
- Parameters:
path (str) – JSON-RPC handler base path
spec (Optional[Specification]) – JSON-RPC specification
kwargs (Any) – arguments to be passed to the dispatcher
pjrpc.server.Dispatcherspecs (Iterable[Specification]) –
- property dispatcher: Dispatcher#
JSON-RPC method dispatcher.
- property endpoints: Dict[str, Dispatcher]#
JSON-RPC application registered endpoints.
- add_endpoint(prefix, blueprint=None, **kwargs)[source]#
Adds additional endpoint.
- Parameters:
prefix (str) – endpoint prefix
blueprint (Optional[Blueprint]) – flask blueprint the endpoint will be served on
kwargs (Any) – arguments to be passed to the dispatcher
pjrpc.server.Dispatcher
- Returns:
dispatcher
- Return type:
kombu#
kombu JSON-RPC server integration.
- class pjrpc.server.integration.kombu.Executor(broker_url, queue_name, conn_args=None, queue_args=None, publish_args=None, prefetch_count=0, **kwargs)[source]#
Bases:
ConsumerProducerMixinkombu based JSON-RPC server.
- Parameters:
broker_url (str) – broker connection url
queue_name (str) – requests queue name
conn_args (Optional[Dict[str, Any]]) – additional connection arguments
publish_args (Optional[Dict[str, Any]]) – message publish additional arguments
prefetch_count (int) – worker prefetch count
kwargs (Any) – dispatcher additional arguments
- property dispatcher: Dispatcher#
JSON-RPC method dispatcher.
aio_pika#
- class pjrpc.server.integration.aio_pika.Executor(broker_url, rx_queue_name, tx_exchange_name=None, tx_routing_key=None, prefetch_count=0, **kwargs)[source]#
Bases:
objectaio_pika based JSON-RPC server.
- Parameters:
- property dispatcher: AsyncDispatcher#
JSON-RPC method dispatcher.
werkzeug#
- class pjrpc.server.integration.werkzeug.JsonRPC(path='', **kwargs)[source]#
Bases:
objectwerkzeug server JSON-RPC integration.
- Parameters:
path (str) – JSON-RPC handler base path
kwargs (Any) – arguments to be passed to the dispatcher
pjrpc.server.Dispatcher
- property dispatcher: Dispatcher#
JSON-RPC method dispatcher.
Validators#
JSON-RPC method parameters validators.
- class pjrpc.server.validators.BaseValidator(exclude_param=None)[source]#
Bases:
objectBase method parameters validator. Uses
inspect.signature()for validation.- Parameters:
exclude_param (Optional[Callable[[str, Optional[Type[Any]], Optional[Any]], bool]]) – a function that decides if the parameters must be excluded from validation (useful for dependency injection)
- validate(maybe_method=None, **kwargs)[source]#
Decorator marks a method the parameters of which to be validated when calling it using JSON-RPC protocol.
- validate_method(method, params, exclude=(), **kwargs)[source]#
Validates params against method signature.
- Parameters:
- Raises:
- Returns:
bound method parameters
- Return type:
- exception pjrpc.server.validators.ValidationError[source]#
Bases:
ExceptionMethod parameters validation error. Raised when parameters validation failed.
jsonschema#
- class pjrpc.server.validators.jsonschema.JsonSchemaValidator(exclude_param=None, **kwargs)[source]#
Bases:
BaseValidatorParameters validator based on jsonschema library.
- Parameters:
pydantic#
- class pjrpc.server.validators.pydantic.PydanticValidator(coerce=True, exclude_param=None, **config_args)[source]#
Bases:
BaseValidatorParameters validator based on pydantic library. Uses python type annotations for parameters validation.
- Parameters:
coerce (bool) – if
Truereturns converted (coerced) parameters according to parameter type annotation otherwise returns parameters as isexclude_param (Optional[Callable[[str, Optional[Type[Any]], Optional[Any]], bool]]) – a function that decides if the parameters must be excluded from validation (useful for dependency injection)
config_args (Any) –
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:
JSONEncoderSchema 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 aTypeError).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 JSONEncoder.default(self, o)
- class pjrpc.server.specs.Specification(path='/spec.json', ui=None, ui_path=None)[source]#
Bases:
ABCJSON-RPC specification.
- Parameters:
extractors#
- class pjrpc.server.specs.extractors.BaseSchemaExtractor[source]#
Bases:
objectBase method schema extractor.
- extract_params_schema(method_name, method, ref_template, exclude=())[source]#
Extracts params schema.
- extract_request_schema(method_name, method, ref_template, exclude=())[source]#
Extracts request schema.
- extract_response_schema(method_name, method, ref_template, errors=None)[source]#
Extracts response schema.
- extract_error_response_schema(method_name, method, ref_template, errors=None)[source]#
Extracts error response schema.
- class pjrpc.server.specs.extractors.pydantic.JsonRpcRequest(*, jsonrpc, id=None, method, params)[source]#
Bases:
BaseModel,Generic[MethodT,ParamsT]- Parameters:
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'strict': True, 'title': 'Request'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pjrpc.server.specs.extractors.pydantic.JsonRpcRequestWrapper(root=PydanticUndefined)[source]#
Bases:
RootModel[~RequestT],Generic[RequestT]- Parameters:
root (RootModelRootType) –
- model_config: ClassVar[ConfigDict] = {'title': 'Request'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pjrpc.server.specs.extractors.pydantic.JsonRpcResponseSuccess(*, jsonrpc, id, result)[source]#
Bases:
BaseModel,Generic[ResultT]- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'strict': True, 'title': 'Success'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pjrpc.server.specs.extractors.pydantic.JsonRpcError(*, code, message, data)[source]#
Bases:
BaseModel,Generic[ErrorCodeT,ErrorDataT]- Parameters:
code (ErrorCodeT) –
message (str) –
data (ErrorDataT) –
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'strict': True, 'title': 'Error'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pjrpc.server.specs.extractors.pydantic.JsonRpcResponseError(*, jsonrpc, id, error)[source]#
Bases:
BaseModel,Generic[JsonRpcErrorT]- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'strict': True, 'title': 'ResponseError'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pjrpc.server.specs.extractors.pydantic.JsonRpcResponseWrapper(root=PydanticUndefined)[source]#
Bases:
RootModel[~ResponseT],Generic[ResponseT]- Parameters:
root (RootModelRootType) –
- model_config: ClassVar[ConfigDict] = {'title': 'Response'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class pjrpc.server.specs.extractors.pydantic.PydanticSchemaExtractor(exclude_param=None, **config_args)[source]#
Bases:
BaseSchemaExtractorPydantic method specification extractor.
- Parameters:
- extract_params_schema(method_name, method, ref_template, exclude=())[source]#
Extracts params schema.
- extract_request_schema(method_name, method, ref_template, exclude=())[source]#
Extracts request schema.
- extract_response_schema(method_name, method, ref_template, errors=None)[source]#
Extracts response schema.
schemas#
OpenAPI Specification generator. See https://swagger.io/specification/.
- class pjrpc.server.specs.openapi.Reference(ref, summary=UNSET, description=UNSET)[source]#
Bases:
objectA simple object to allow referencing other components in the OpenAPI document, internally and externally.
- class pjrpc.server.specs.openapi.Contact(name=UNSET, url=UNSET, email=UNSET)[source]#
Bases:
objectContact information for the exposed API.
- class pjrpc.server.specs.openapi.License(name, identifier=UNSET, url=UNSET)[source]#
Bases:
objectLicense information for the exposed API.
- class pjrpc.server.specs.openapi.Info(title, version, summary=UNSET, description=UNSET, contact=UNSET, license=UNSET, termsOfService=UNSET)[source]#
Bases:
objectMetadata about the API.
- Parameters:
title (str) – the title of the application
version (str) – the version of the OpenAPI document
summary (Union[UnsetType, str]) – a short summary of the API.
description (Union[UnsetType, str]) – a 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.openapi.ServerVariable(default, enum=UNSET, description=UNSET)[source]#
Bases:
objectAn 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.Server(url, description=UNSET, variables=UNSET)[source]#
Bases:
objectConnectivity information of a target server.
- Parameters:
url (str) – a URL to the target host
description (Union[UnsetType, str]) – an optional string describing the host designated by the URL
variables (Union[UnsetType, Dict[str, ServerVariable]]) – a map between a variable name and its value. The value is used for substitution in the server’s URL template.
- class pjrpc.server.specs.openapi.Link(operationRef=UNSET, operationId=UNSET, parameters=UNSET, requestBody=UNSET, description=UNSET, server=UNSET)[source]#
Bases:
objectThe 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.ExternalDocumentation(url, description=UNSET)[source]#
Bases:
objectAllows referencing an external resource for extended documentation.
- class pjrpc.server.specs.openapi.Tag(name, description=UNSET, externalDocs=UNSET)[source]#
Bases:
objectA list of tags for API documentation control. Tags can be used for logical grouping of methods by resources or any other qualifier.
- class pjrpc.server.specs.openapi.SecuritySchemeType(value)[source]#
-
The type of the security scheme.
- class pjrpc.server.specs.openapi.OAuthFlow(authorizationUrl, tokenUrl, scopes, refreshUrl=UNSET)[source]#
Bases:
objectConfiguration details for a supported OAuth Flow.
- Parameters:
- class pjrpc.server.specs.openapi.OAuthFlows(implicit=UNSET, password=UNSET, clientCredentials=UNSET, authorizationCode=UNSET)[source]#
Bases:
objectConfiguration of the supported OAuth Flows.
- Parameters:
implicit (Union[UnsetType, OAuthFlow]) – configuration for the OAuth Implicit flow
password (Union[UnsetType, OAuthFlow]) – configuration for the OAuth Resource Owner Password flow
clientCredentials (Union[UnsetType, OAuthFlow]) – configuration for the OAuth Client Credentials flow
authorizationCode (Union[UnsetType, OAuthFlow]) – configuration for the OAuth Authorization Code flow
- class pjrpc.server.specs.openapi.SecurityScheme(type, scheme=UNSET, name=UNSET, location=UNSET, bearerFormat=UNSET, flows=UNSET, openIdConnectUrl=UNSET, description=UNSET)[source]#
Bases:
objectDefines a security scheme that can be used by the operations.
- Parameters:
type (SecuritySchemeType) – the type of the security scheme
name (Union[UnsetType, str]) – the name of the header, query or cookie parameter to be used
location (Union[UnsetType, ApiKeyLocation]) – the location of the API key
scheme (Union[UnsetType, str]) – the name of the HTTP Authorization scheme to be used in the Authorization header
bearerFormat (Union[UnsetType, str]) – a hint to the client to identify how the bearer token is formatted
flows (Union[UnsetType, OAuthFlows]) – an object containing configuration information for the flow types supported
description (Union[UnsetType, str]) – a short description for security scheme
- class pjrpc.server.specs.openapi.MethodExample(params, result, version='2.0', summary=UNSET, description=UNSET)[source]#
Bases:
objectMethod usage example.
- class pjrpc.server.specs.openapi.ExampleObject(value=UNSET, summary=UNSET, description=UNSET, externalValue=UNSET)[source]#
Bases:
objectMethod usage example.
- class pjrpc.server.specs.openapi.Encoding(contentType=UNSET, headers=UNSET, style=UNSET, explode=UNSET, allowReserved=UNSET)[source]#
Bases:
objectA single encoding definition applied to a single schema property.
- Parameters:
contentType (Union[UnsetType, str]) – the Content-Type for encoding a specific property
headers (Union[UnsetType, Dict[str, Union[Parameter, Reference]]]) – a map allowing additional information to be provided as headers
style (Union[UnsetType, str]) – describes how a specific property value will be serialized depending on its type
explode (Union[UnsetType, bool]) – when this is true, property values of type array or object generate separate parameters for each value of the array, or key-value-pair of the map
allowReserved (Union[UnsetType, bool]) – determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986 to be included without percent-encoding
- class pjrpc.server.specs.openapi.StyleType(value)[source]#
-
Describes how the parameter value will be serialized depending on the type of the parameter value.
- class pjrpc.server.specs.openapi.MediaType(schema=UNSET, example=UNSET, examples=UNSET, encoding=UNSET)[source]#
Bases:
objectEach Media Type Object provides schema and examples for the media type identified by its key.
- class pjrpc.server.specs.openapi.RequestBody(content, required=UNSET, description=UNSET)[source]#
Bases:
objectDescribes a single request body.
- class pjrpc.server.specs.openapi.Parameter(name, location, description=UNSET, required=UNSET, deprecated=UNSET, allowEmptyValue=UNSET, style=UNSET, explode=UNSET, allowReserved=UNSET, schema=UNSET, example=UNSET, examples=UNSET, content=UNSET)[source]#
Bases:
objectDescribes a single operation parameter.
- Parameters:
name (str) – the name of the parameter
location (ParameterLocation) – the location of the parameter
description (Union[UnsetType, str]) – a brief description of the parameter
required (Union[UnsetType, bool]) – determines whether this parameter is mandatory
deprecated (Union[UnsetType, bool]) – a parameter is deprecated and SHOULD be transitioned out of usage
allowEmptyValue (Union[UnsetType, bool]) – the ability to pass empty-valued parameters
style (Union[UnsetType, StyleType]) – describes how the parameter value will be serialized depending on the type of the parameter value
explode (Union[UnsetType, bool]) – when this is true, parameter values of type array or object generate separate parameters for each value of the array or key-value pair of the map
allowReserved (Union[UnsetType, bool]) – determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986 :/?#[]@!$&’()*+,;= to be included without percent-encoding
schema (Union[UnsetType, Dict[str, Any]]) – the schema defining the type used for the parameter.
examples (Union[UnsetType, Dict[str, ExampleObject]]) – examples of the parameter’s potential value
content (Union[UnsetType, Dict[str, MediaType]]) – a map containing the representations for the parameter
- class pjrpc.server.specs.openapi.Response(description, headers=UNSET, content=UNSET, links=UNSET)[source]#
Bases:
objectA container for the expected responses of an operation.
- Parameters:
- class pjrpc.server.specs.openapi.Operation(responses=UNSET, requestBody=UNSET, tags=UNSET, summary=UNSET, description=UNSET, externalDocs=UNSET, operationId=UNSET, deprecated=UNSET, servers=UNSET, security=UNSET, parameters=UNSET)[source]#
Bases:
objectDescribes a single API operation on a path.
- Parameters:
tags (Union[UnsetType, List[str]]) – a list of tags for API documentation control
summary (Union[UnsetType, str]) – a short summary of what the operation does
description (Union[UnsetType, str]) – a verbose explanation of the operation behavior
externalDocs (Union[UnsetType, ExternalDocumentation]) – additional external documentation for this operation
requestBody (Union[UnsetType, RequestBody, Reference]) – the request body applicable for this operation
responses (Union[UnsetType, Dict[str, Union[Response, Reference]]]) – the list of possible responses as they are returned from executing this operation
deprecated (Union[UnsetType, bool]) – declares this operation to be deprecated
servers (Union[UnsetType, List[Server]]) – an alternative server array to service this operation
security (Union[UnsetType, List[Dict[str, List[str]]]]) – a declaration of which security mechanisms can be used for this operation
parameters (Union[UnsetType, List[Union[Parameter, Reference]]]) –
- class pjrpc.server.specs.openapi.Path(get=UNSET, put=UNSET, post=UNSET, delete=UNSET, options=UNSET, head=UNSET, patch=UNSET, trace=UNSET, summary=UNSET, description=UNSET, servers=UNSET, parameters=UNSET)[source]#
Bases:
objectDescribes the interface for the given method name.
- Parameters:
summary (Union[UnsetType, str]) – an optional, string summary, intended to apply to all operations in this path
description (Union[UnsetType, str]) – an optional, string description, intended to apply to all operations in this path
servers (Union[UnsetType, List[Server]]) – an alternative server array to service all operations in this path
parameters (Union[UnsetType, Parameter, Reference]) – a list of parameters that are applicable for all the operations described under this path
- class pjrpc.server.specs.openapi.Components(schemas=UNSET, responses=UNSET, parameters=UNSET, examples=UNSET, requestBodies=UNSET, headers=UNSET, securitySchemes=UNSET, links=UNSET, pathItems=UNSET)[source]#
Bases:
objectHolds a set of reusable objects for different aspects of the OAS.
- Parameters:
securitySchemes (Union[UnsetType, Dict[str, Union[SecurityScheme, Reference]]]) – an object to hold reusable Security Scheme Objects
schemas (Union[UnsetType, Dict[str, Dict[str, Any]]]) – the definition of input and output data types
responses (Union[UnsetType, Dict[str, Union[Response, Reference]]]) –
parameters (Union[UnsetType, Dict[str, Union[Parameter, Reference]]]) –
examples (Union[UnsetType, Dict[str, Union[ExampleObject, Reference]]]) –
requestBodies (Union[UnsetType, Dict[str, Union[RequestBody, Reference]]]) –
headers (Union[UnsetType, Dict[str, Union[Parameter, Reference]]]) –
links (Union[UnsetType, Dict[str, Dict[str, Union[Link, Reference]]]]) –
pathItems (Union[UnsetType, Dict[str, Union[Path, Reference]]]) –
- class pjrpc.server.specs.openapi.SpecRoot(info, paths, components, servers=UNSET, externalDocs=UNSET, tags=UNSET, security=UNSET, openapi='3.1.0', jsonSchemaDialect=UNSET)[source]#
Bases:
objectThe root object of the OpenAPI description.
- Parameters:
info (Info) – provides metadata about the API
servers (Union[UnsetType, List[Server]]) – an array of Server Objects, which provide connectivity information to a target server
externalDocs (Union[UnsetType, ExternalDocumentation]) – additional external documentation
openapi (str) – the semantic version number of the OpenAPI Specification version that the OpenAPI document uses
jsonSchemaDialect (Union[UnsetType, str]) – the default value for the $schema keyword within Schema Objects
tags (Union[UnsetType, List[Tag]]) – a list of tags used by the specification with additional metadata
security (Union[UnsetType, List[Dict[str, List[str]]]]) – a declaration of which security mechanisms can be used across the API
components (Components) –
- pjrpc.server.specs.openapi.annotate(params_schema=UNSET, result_schema=UNSET, errors=UNSET, examples=UNSET, tags=UNSET, summary=UNSET, description=UNSET, external_docs=UNSET, deprecated=UNSET, security=UNSET, parameters=UNSET, servers=UNSET, component_name_prefix=None)[source]#
Adds Open Api specification annotation to the method.
- Parameters:
params_schema (Union[UnsetType, Dict[str, Dict[str, Any]]]) – method parameters JSON schema
result_schema (Union[UnsetType, Dict[str, Any]]) – method result JSON schema
errors (Union[UnsetType, List[Type[JsonRpcError]]]) – method errors
examples (Union[UnsetType, List[MethodExample]]) – method usage examples
tags (Union[UnsetType, List[Union[str, Tag]]]) – a list of tags for method documentation control
summary (Union[UnsetType, str]) – a short summary of what the method does
description (Union[UnsetType, str]) – a verbose explanation of the method behavior
external_docs (Union[UnsetType, ExternalDocumentation]) – an external resource for extended documentation
deprecated (Union[UnsetType, bool]) – declares this method to be deprecated
security (Union[UnsetType, List[Dict[str, List[str]]]]) – a declaration of which security mechanisms can be used for the method
parameters (Union[UnsetType, List[Parameter]]) – a list of parameters that are applicable for the method
servers (Union[UnsetType, List[Server]]) – a list of connectivity information of a target server.
component_name_prefix (Optional[str]) – components name prefix.
- Return type:
Callable[[Func], Func]
- class pjrpc.server.specs.openapi.OpenAPI(info, path='/openapi.json', servers=UNSET, external_docs=UNSET, tags=UNSET, security=UNSET, security_schemes=UNSET, openapi='3.1.0', json_schema_dialect=UNSET, schema_extractor=None, schema_extractors=(), ui=None, ui_path='/ui/', error_http_status_map={})[source]#
Bases:
SpecificationOpenAPI Specification.
- Parameters:
info (Info) – provides metadata about the API
servers (Union[UnsetType, List[Server]]) – an array of Server Objects, which provide connectivity information to a target server
external_docs (Union[UnsetType, ExternalDocumentation]) – additional external documentation
openapi (str) – the semantic version number of the OpenAPI Specification version that the OpenAPI document uses
json_schema_dialect (Union[UnsetType, str]) – the default value for the $schema keyword within Schema Objects
tags (Union[UnsetType, List[Tag]]) – a list of tags used by the specification with additional metadata
security (Union[UnsetType, List[Dict[str, List[str]]]]) – a declaration of which security mechanisms can be used across the API
schema_extractor (Optional[BaseSchemaExtractor]) – method specification extractor
schema_extractors (Iterable[BaseSchemaExtractor]) – method specification extractors. Extractors results will be merged in reverse order (former extractor rewrites the result of the later one)
path (str) – specification url path
security_schemes (Union[UnsetType, Dict[str, Union[SecurityScheme, Reference]]]) – an object to hold reusable Security Scheme Objects
ui_path (str) – wet ui path
- class pjrpc.server.specs.openapi.SwaggerUI(**configs)[source]#
Bases:
BaseUISwagger UI.
- Parameters:
config – documentation configurations (see https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md).
configs (Any) –
- class pjrpc.server.specs.openapi.RapiDoc(**configs)[source]#
Bases:
BaseUIRapiDoc UI.
- Parameters:
config – documentation configurations (see https://mrin9.github.io/RapiDoc/api.html). Be aware that configuration parameters should be in snake case, for example: parameter heading-text should be passed as heading_text)
configs (Any) –
- class pjrpc.server.specs.openapi.ReDoc(**configs)[source]#
Bases:
BaseUIReDoc UI.
- Parameters:
config – documentation configurations (see https://github.com/Redocly/redoc#configuration). Be aware that configuration parameters should be in snake case, for example: parameter heading-text should be passed as heading_text)
configs (Any) –
OpenRPC specification generator. See https://spec.open-rpc.org/.
- class pjrpc.server.specs.openrpc.Reference(ref)[source]#
Bases:
objectA 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.Contact(name=UNSET, url=UNSET, email=UNSET)[source]#
Bases:
objectContact information for the exposed API.
- class pjrpc.server.specs.openrpc.License(name, url=UNSET)[source]#
Bases:
objectLicense information for the exposed API.
- class pjrpc.server.specs.openrpc.Info(title, version, description=UNSET, contact=UNSET, license=UNSET, termsOfService=UNSET)[source]#
Bases:
objectMetadata 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.ServerVariable(default, enum=UNSET, description=UNSET)[source]#
Bases:
objectAn object representing a Server Variable for server URL template substitution.
- class pjrpc.server.specs.openrpc.Server(name, url, summary=UNSET, description=UNSET, variables=UNSET)[source]#
Bases:
objectConnectivity information of a target server.
- Parameters:
name (str) – a name to be used as the canonical name for the server.
url (str) – a URL to the target host. This URL supports Server Variables.
summary (Union[UnsetType, str]) – a short summary of what the server is
description (Union[UnsetType, str]) – an optional string describing the host designated by the URL
variables (Union[UnsetType, Dict[str, ServerVariable]]) – A map between a variable name and its value. The value is passed into the Runtime Expression to produce a server URL.
- class pjrpc.server.specs.openrpc.ExternalDocumentation(url, description=UNSET)[source]#
Bases:
objectAllows referencing an external resource for extended documentation.
- class pjrpc.server.specs.openrpc.Tag(name, description=UNSET, externalDocs=UNSET)[source]#
Bases:
objectA list of tags for API documentation control. Tags can be used for logical grouping of methods by resources or any other qualifier.
- class pjrpc.server.specs.openrpc.ExampleObject(value, name, summary=UNSET, description=UNSET, externalValue=UNSET)[source]#
Bases:
objectThe 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.MethodExample(name, params, result, summary=UNSET, description=UNSET)[source]#
Bases:
objectThe example Pairing object consists of a set of example params and result.
- Parameters:
params (List[Union[ExampleObject, Reference]]) – example parameters
result (Union[ExampleObject, Reference]) – example result
name (str) – name for the example pairing
summary (Union[UnsetType, str]) – short description for the example pairing
description (Union[UnsetType, str]) – a verbose explanation of the example pairing
- class pjrpc.server.specs.openrpc.ContentDescriptor(name, schema, summary=UNSET, description=UNSET, required=UNSET, deprecated=UNSET)[source]#
Bases:
objectContent Descriptors are objects that describe content. They are reusable ways of describing either parameters or result.
- Parameters:
name (str) – name of the content that is being described
schema (Dict[str, Any]) – schema that describes the content. The Schema Objects MUST follow the specifications outline in the JSON Schema Specification 7 (https://json-schema.org/draft-07/json-schema-release-notes.html)
summary (Union[UnsetType, str]) – a short summary of the content that is being described
description (Union[UnsetType, str]) – a verbose explanation of the content descriptor behavior
required (Union[UnsetType, bool]) – determines if the content is a required field
deprecated (Union[UnsetType, bool]) – specifies that the content is deprecated and SHOULD be transitioned out of usage
- class pjrpc.server.specs.openrpc.Error(code, message, data=UNSET)[source]#
Bases:
objectDefines an application level error.
- class pjrpc.server.specs.openrpc.ParamStructure(value)[source]#
-
The expected format of the parameters.
- class pjrpc.server.specs.openrpc.Link(name, description=UNSET, summary=UNSET, method=UNSET, params=UNSET, server=UNSET)[source]#
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, 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.
- class pjrpc.server.specs.openrpc.MethodInfo(name, params, result, errors=UNSET, links=UNSET, paramStructure=UNSET, examples=UNSET, summary=UNSET, description=UNSET, tags=UNSET, deprecated=UNSET, externalDocs=UNSET, servers=UNSET)[source]#
Bases:
objectDescribes the interface for the given method name.
- Parameters:
name (str) – the canonical name for the method
params (List[Union[ContentDescriptor, Reference]]) – a list of parameters that are applicable for this method
result (Union[ContentDescriptor, Reference]) – the description of the result returned by the method
errors (Union[UnsetType, List[Union[Error, Reference]]]) – a list of custom application defined errors that MAY be returned
examples (Union[UnsetType, List[Union[MethodExample, Reference]]]) – method usage examples
summary (Union[UnsetType, str]) – a short summary of what the method does
description (Union[UnsetType, str]) – a verbose explanation of the method behavior
tags (Union[UnsetType, List[Union[Tag, Reference]]]) – a list of tags for API documentation control
deprecated (Union[UnsetType, bool]) – declares this method to be deprecated
paramStructure (Union[UnsetType, ParamStructure]) – the expected format of the parameters
externalDocs (Union[UnsetType, ExternalDocumentation]) – additional external documentation for this method
servers (Union[UnsetType, List[Server]]) – an alternative servers array to service this method
- class pjrpc.server.specs.openrpc.Components(contentDescriptors=UNSET, schemas=UNSET, examples=UNSET, links=UNSET, errors=UNSET, examplePairingObjects=UNSET, tags=UNSET)[source]#
Bases:
objectSet of reusable objects for different aspects of the OpenRPC.
- Parameters:
contentDescriptors (Union[UnsetType, Dict[str, ContentDescriptor]]) – reusable Schema Objects
schemas (Union[UnsetType, Dict[str, Dict[str, Any]]]) – reusable Schema Objects
examples (Union[UnsetType, Dict[str, ExampleObject]]) – reusable Schema Objects
links (Union[UnsetType, Dict[str, Link]]) – reusable Schema Objects
errors (Union[UnsetType, Dict[str, Error]]) – reusable Schema Objects
examplePairingObjects (Union[UnsetType, Dict[str, MethodExample]]) – reusable Schema Objects
tags (Union[UnsetType, Dict[str, Tag]]) – reusable Schema Objects
- class pjrpc.server.specs.openrpc.SpecRoot(info, components, methods=<factory>, servers=UNSET, externalDocs=UNSET, openrpc='1.3.2')[source]#
Bases:
objectThe root object of the OpenRPC document.
- Parameters:
info (Info) – provides metadata about the API
components (Components) – an element to hold various schemas for the specification.
methods (List[Union[MethodInfo, Reference]]) – the available methods for the API
servers (Union[UnsetType, List[Server]]) – connectivity information
externalDocs (Union[UnsetType, ExternalDocumentation]) – additional external documentation
openrpc (str) – the semantic version number of the OpenRPC Specification version that the OpenRPC document uses
- pjrpc.server.specs.openrpc.annotate(params_schema=UNSET, result_schema=UNSET, errors=UNSET, examples=UNSET, summary=UNSET, description=UNSET, tags=UNSET, deprecated=UNSET, external_docs=UNSET, servers=UNSET)[source]#
Adds JSON-RPC method to the API specification.
- Parameters:
params_schema (Union[UnsetType, List[ContentDescriptor]]) – a list of parameters that are applicable for this method
result_schema (Union[UnsetType, ContentDescriptor]) – the description of the result returned by the method
errors (Union[UnsetType, List[Union[Error, Type[JsonRpcError]]]]) – a list of custom application defined errors that MAY be returned
examples (Union[UnsetType, List[Union[MethodExample, Reference]]]) – method usage example
summary (Union[UnsetType, str]) – a short summary of what the method does
description (Union[UnsetType, str]) – a verbose explanation of the method behavior
tags (Union[UnsetType, List[Union[Tag, str]]]) – a list of tags for API documentation control
deprecated (Union[UnsetType, bool]) – declares this method to be deprecated
external_docs (Union[UnsetType, ExternalDocumentation]) – additional external documentation for the method
servers (Union[UnsetType, List[Server]]) – an alternative servers array to service this method
- Return type:
Callable[[Func], Func]
- class pjrpc.server.specs.openrpc.OpenRPC(info, path='/openrpc.json', servers=UNSET, external_docs=UNSET, openrpc='1.3.2', schema_extractor=None)[source]#
Bases:
SpecificationOpenRPC Specification.
- Parameters:
info (Info) – provides metadata about the API
path (str) – specification url path
servers (Union[UnsetType, List[Server]]) – connectivity information
external_docs (Union[UnsetType, ExternalDocumentation]) – additional external documentation
openrpc (str) – the semantic version number of the OpenRPC Specification version that the OpenRPC document uses
schema_extractor (Optional[BaseSchemaExtractor]) – method specification extractor