Server¶
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={})¶
Bases:
BaseDispatcher
Asynchronous method dispatcher.
- Parameters
batch_request (Type[BatchRequest]) –
batch_response (Type[BatchResponse]) –
json_loader (Callable) –
json_dumper (Callable) –
json_encoder (Type[JSONEncoder]) –
middlewares (Iterable[AsyncMiddlewareType]) –
error_handlers (Dict[Union[None, int, Exception], List[AsyncErrorHandlerType]]) –
- async dispatch(request_text, context=None)¶
Deserializes request, dispatches it to the required method and serializes the result.
- 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={})¶
Bases:
object
Method dispatcher.
- Parameters
batch_request (Type[BatchRequest]) – JSON-RPC batch request class
batch_response (Type[BatchResponse]) – JSON-RPC batch response class
json_loader (Callable) – request json loader
json_dumper (Callable) – response json dumper
json_encoder (Type[JSONEncoder]) – response json encoder
json_decoder (Optional[Type[JSONDecoder]]) – request json decoder
error_handlers (Dict[Union[None, int, Exception], List[Callable]]) – request error handlers
- add(method, name=None, context=None)¶
Adds method to the registry.
- add_methods(*methods)¶
Adds methods to the registry.
- Parameters
methods (Union[MethodRegistry, Method, Callable]) – method list. Each method may be an instance of
pjrpc.server.MethodRegistry
,pjrpc.server.Method
or 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={})¶
Bases:
BaseDispatcher
Synchronous method dispatcher.
- Parameters
batch_request (Type[BatchRequest]) –
batch_response (Type[BatchResponse]) –
json_loader (Callable) –
json_dumper (Callable) –
json_encoder (Type[JSONEncoder]) –
middlewares (Iterable[MiddlewareType]) –
error_handlers (Dict[Union[None, int, Exception], List[ErrorHandlerType]]) –
- dispatch(request_text, context=None)¶
Deserializes request, dispatches it to the required method and serializes the result.
- class pjrpc.server.JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)¶
Bases:
JSONEncoder
Server JSON encoder. All custom server encoders should be inherited from it.
- default(o)¶
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)¶
Bases:
object
JSON-RPC method wrapper. Stores method itself and some metainformation.
- class pjrpc.server.MethodRegistry(prefix=None)¶
Bases:
object
Method registry.
- get(item)¶
Returns a method from the registry by name.
- add(maybe_method=None, name=None, context=None)¶
Decorator adding decorated method to the registry.
- add_methods(*methods)¶
Adds methods to the registry.
- Parameters
methods (Union[Callable, Method]) – methods to be added. Each one can be an instance of
pjrpc.server.Method
or plain method- Return type
None
- view(maybe_view=None, context=None, prefix=None)¶
Methods view decorator.
- merge(other)¶
Merges two registries.
- Parameters
other (MethodRegistry) – registry to be merged in the current one
- Return type
None
- class pjrpc.server.ViewMixin(context=None)¶
Bases:
object
Simple class based method handler mixin. Exposes all public methods.
Types¶
- pjrpc.server.typedefs.AsyncMiddlewareType¶
Asynchronous middleware type
alias of
Callable
[[Request
,Optional
[Any
],Callable
[[Request
,Optional
[Any
]],Union
[UnsetType
,Response
]]],Awaitable
[Union
[UnsetType
,Response
]]]
- pjrpc.server.typedefs.AsyncErrorHandlerType¶
Asynchronous server error handler
alias of
Callable
[[Request
,Optional
[Any
],JsonRpcError
],Awaitable
[JsonRpcError
]]
- 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
]
Integrations¶
aiohttp¶
aiohttp JSON-RPC server integration.
- class pjrpc.server.integration.aiohttp.Application(path='', spec=None, app=None, **kwargs)¶
Bases:
object
aiohttp based JSON-RPC server.
- Parameters
path (str) – JSON-RPC handler base path
app_args – arguments to be passed to
aiohttp.web.Application
kwargs (Any) – arguments to be passed to the dispatcher
pjrpc.server.AsyncDispatcher
spec (Optional[Specification]) –
app (Optional[Application]) –
- property app: aiohttp.web_app.Application¶
aiohttp application.
- property dispatcher: pjrpc.server.dispatcher.AsyncDispatcher¶
JSON-RPC method dispatcher.
- property endpoints: Mapping[str, pjrpc.server.dispatcher.AsyncDispatcher]¶
JSON-RPC application registered endpoints.
- add_endpoint(prefix, subapp=None, **kwargs)¶
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, **kwargs)¶
Bases:
object
Flask 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.Dispatcher
- property dispatcher: pjrpc.server.dispatcher.Dispatcher¶
JSON-RPC method dispatcher.
- property endpoints: Dict[str, pjrpc.server.dispatcher.Dispatcher]¶
JSON-RPC application registered endpoints.
- add_endpoint(prefix, blueprint=None, **kwargs)¶
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)¶
Bases:
ConsumerProducerMixin
kombu 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: pjrpc.server.dispatcher.Dispatcher¶
JSON-RPC method dispatcher.
aio_pika¶
- class pjrpc.server.integration.aio_pika.Executor(broker_url, queue_name, prefetch_count=0, **kwargs)¶
Bases:
object
aio_pika based JSON-RPC server.
- Parameters
- property dispatcher: pjrpc.server.dispatcher.AsyncDispatcher¶
JSON-RPC method dispatcher.
- async start(queue_args=None)¶
Starts executor.
- async shutdown()¶
Stops executor.
- Return type
None
werkzeug¶
- class pjrpc.server.integration.werkzeug.JsonRPC(path='', **kwargs)¶
Bases:
object
werkzeug 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: pjrpc.server.dispatcher.Dispatcher¶
JSON-RPC method dispatcher.
Validators¶
JSON-RPC method parameters validators.
- class pjrpc.server.validators.BaseValidator¶
Bases:
object
Base method parameters validator. Uses
inspect.signature()
for validation.- validate(maybe_method=None, **kwargs)¶
Decorator marks a method the parameters of which to be validated when calling it using JSON-RPC protocol.
- validate_method(method, params, exclude=(), **kwargs)¶
Validates params against method signature.
- Parameters
- Raises
- Returns
bound method parameters
- Return type
- bind(signature, params)¶
Binds parameters to method. :param signature: method to bind parameters to :param params: parameters to be bound
- Raises
ValidationError is parameters binding failed
- Returns
bound parameters
- Parameters
- Return type
- exception pjrpc.server.validators.ValidationError¶
Bases:
Exception
Method parameters validation error. Raised when parameters validation failed.
jsonschema¶
- class pjrpc.server.validators.jsonschema.JsonSchemaValidator(**kwargs)¶
Bases:
BaseValidator
Parameters validator based on jsonschema library.
- Parameters
kwargs (Any) – default jsonschema validator arguments
- validate_method(method, params, exclude=(), **kwargs)¶
Validates params against method using
pydantic
validator.- Parameters
- Raises
- Return type
pydantic¶
- class pjrpc.server.validators.pydantic.PydanticValidator(coerce=True, **config_args)¶
Bases:
BaseValidator
Parameters validator based on pydantic library. Uses python type annotations for parameters validation.
- Parameters
- validate_method(method, params, exclude=(), **kwargs)¶
Validates params against method using
pydantic
validator.- Parameters
- Returns
coerced parameters if coerce flag is
True
otherwise parameters as is- Raises
ValidationError
- Return type
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)¶
Bases:
JSONEncoder
Schema JSON encoder.
- default(o)¶
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)¶
Bases:
ABC
JSON-RPC specification.
- Parameters
- property ui: Optional[pjrpc.server.specs.BaseUI]¶
Returns ui instance.
- abstract schema(path, methods=(), methods_map={})¶
Returns specification schema.
- Parameters
- Return type
extractors¶
- class pjrpc.server.specs.extractors.Schema(schema, required=True, summary=UNSET, description=UNSET, deprecated=UNSET, definitions=UNSET)¶
Bases:
object
Method parameter/result schema.
- class pjrpc.server.specs.extractors.Example(params, result, version='2.0', summary=UNSET, description=UNSET)¶
Bases:
object
Method usage example.
- class pjrpc.server.specs.extractors.ErrorExample(code, message, data=UNSET, summary=UNSET, description=UNSET)¶
Bases:
object
Method error example.
- class pjrpc.server.specs.extractors.Tag(name, description=UNSET, externalDocs=UNSET)¶
Bases:
object
A list of method tags.
- class pjrpc.server.specs.extractors.Error(code, message, data=UNSET, data_required=UNSET, title=UNSET, description=UNSET, deprecated=UNSET, definitions=UNSET)¶
Bases:
object
Defines an application level error.
- class pjrpc.server.specs.extractors.BaseSchemaExtractor¶
Bases:
object
Base method schema extractor.
- extract_params_schema(method, exclude=())¶
Extracts method parameters schema.
- extract_result_schema(method)¶
Extracts method result schema.
- extract_description(method)¶
Extracts method description.
- extract_summary(method)¶
Extracts method summary.
- extract_errors_schema(method, errors=None)¶
Extracts method errors schema.
- extract_tags(method)¶
Extracts method tags.
- extract_examples(method)¶
Extracts method usage examples.
- extract_error_examples(method, errors=None)¶
Extracts method error examples.
- Parameters
- Return type
- class pjrpc.server.specs.extractors.pydantic.PydanticSchemaExtractor(ref_template='#/components/schemas/{model}')¶
Bases:
BaseSchemaExtractor
Pydantic method specification extractor.
- Parameters
ref_template (str) –
- extract_params_schema(method, exclude=())¶
Extracts method parameters schema.
- extract_result_schema(method)¶
Extracts method result schema.
schemas¶
OpenAPI Specification generator. See https://swagger.io/specification/.
- class pjrpc.server.specs.openapi.Contact(name=UNSET, url=UNSET, email=UNSET)¶
Bases:
object
Contact information for the exposed API.
- class pjrpc.server.specs.openapi.License(name, url=UNSET)¶
Bases:
object
License information for the exposed API.
- class pjrpc.server.specs.openapi.Info(title, version, description=UNSET, contact=UNSET, license=UNSET, termsOfService=UNSET)¶
Bases:
object
Metadata about the API.
- Parameters
title (str) – the title of the application
version (str) – the version of the OpenAPI document
description (Union[str, UnsetType]) – a short description of the application
contact (Union[Contact, UnsetType]) – the contact information for the exposed API
license (Union[License, UnsetType]) – the license information for the exposed API
termsOfService (Union[str, UnsetType]) – a URL to the Terms of Service for the API
- Return type
None
- class pjrpc.server.specs.openapi.ServerVariable(default, enum=UNSET, description=UNSET)¶
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[List[str], UnsetType]) – an enumeration of string values to be used if the substitution options are from a limited set
description (Union[str, UnsetType]) – an optional description for the server variable
- Return type
None
- class pjrpc.server.specs.openapi.Server(url, description=UNSET, variables=UNSET)¶
Bases:
object
Connectivity information of a target server.
- class pjrpc.server.specs.openapi.ExternalDocumentation(url, description=UNSET)¶
Bases:
object
Allows referencing an external resource for extended documentation.
- class pjrpc.server.specs.openapi.Tag(name, description=UNSET, externalDocs=UNSET)¶
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.
- class pjrpc.server.specs.openapi.SecuritySchemeType(value)¶
-
The type of the security scheme.
- APIKEY = 'apiKey'¶
- HTTP = 'http'¶
- OAUTH2 = 'oauth2'¶
- OPENID_CONNECT = 'openIdConnect'¶
- class pjrpc.server.specs.openapi.ApiKeyLocation(value)¶
-
The location of the API key.
- QUERY = 'query'¶
- HEADER = 'header'¶
- COOKIE = 'cookie'¶
- class pjrpc.server.specs.openapi.OAuthFlow(authorizationUrl, tokenUrl, scopes, refreshUrl=UNSET)¶
Bases:
object
Configuration details for a supported OAuth Flow.
- Parameters
- Return type
None
- class pjrpc.server.specs.openapi.OAuthFlows(implicit=UNSET, password=UNSET, clientCredentials=UNSET, authorizationCode=UNSET)¶
Bases:
object
Configuration of the supported OAuth Flows.
- Parameters
implicit (Union[OAuthFlow, UnsetType]) – configuration for the OAuth Implicit flow
password (Union[OAuthFlow, UnsetType]) – configuration for the OAuth Resource Owner Password flow
clientCredentials (Union[OAuthFlow, UnsetType]) – configuration for the OAuth Client Credentials flow
authorizationCode (Union[OAuthFlow, UnsetType]) – configuration for the OAuth Authorization Code flow
- Return type
None
- class pjrpc.server.specs.openapi.SecurityScheme(type, scheme, name=UNSET, location=UNSET, bearerFormat=UNSET, flows=UNSET, openIdConnectUrl=UNSET, description=UNSET)¶
Bases:
object
Defines a security scheme that can be used by the operations.
- Parameters
type (SecuritySchemeType) – the type of the security scheme
name (Union[str, UnsetType]) – the name of the header, query or cookie parameter to be used
location (Union[ApiKeyLocation, UnsetType]) – the location of the API key
scheme (str) – the name of the HTTP Authorization scheme to be used in the Authorization header
bearerFormat (Union[str, UnsetType]) – a hint to the client to identify how the bearer token is formatted
flows (Union[OAuthFlows, UnsetType]) – an object containing configuration information for the flow types supported
description (Union[str, UnsetType]) – a short description for security scheme
- Return type
None
- class pjrpc.server.specs.openapi.Components(securitySchemes=UNSET, schemas=<factory>)¶
Bases:
object
Holds a set of reusable objects for different aspects of the OAS.
- class pjrpc.server.specs.openapi.MethodExample(params, result, version='2.0', summary=UNSET, description=UNSET)¶
Bases:
object
Method usage example.
- Parameters
- Return type
None
- class pjrpc.server.specs.openapi.ExampleObject(value, summary=UNSET, description=UNSET, externalValue=UNSET)¶
Bases:
object
Method usage example.
- class pjrpc.server.specs.openapi.MediaType(schema, examples=UNSET)¶
Bases:
object
Each Media Type Object provides schema and examples for the media type identified by its key.
- class pjrpc.server.specs.openapi.Response(description, content=UNSET)¶
Bases:
object
A container for the expected responses of an operation.
- class pjrpc.server.specs.openapi.RequestBody(content, required=UNSET, description=UNSET)¶
Bases:
object
Describes a single request body.
- class pjrpc.server.specs.openapi.ParameterLocation(value)¶
-
The location of the parameter.
- QUERY = 'query'¶
- HEADER = 'header'¶
- PATH = 'path'¶
- COOKIE = 'cookie'¶
- class pjrpc.server.specs.openapi.StyleType(value)¶
-
Describes how the parameter value will be serialized depending on the type of the parameter value.
- MATRIX = 'matrix'¶
- LABEL = 'label'¶
- FORM = 'form'¶
- SIMPLE = 'simple'¶
- SPACE_DELIMITED = 'spaceDelimited'¶
- PIPE_DELIMITED = 'pipeDelimited'¶
- DEEP_OBJECT = 'deepObject'¶
- class pjrpc.server.specs.openapi.Parameter(name, location, description=UNSET, required=UNSET, deprecated=UNSET, allowEmptyValue=UNSET, style=UNSET, explode=UNSET, allowReserved=UNSET, schema=UNSET, examples=UNSET, content=UNSET)¶
Bases:
object
Describes a single operation parameter.
- Parameters
name (str) – the name of the parameter
location (ParameterLocation) – the location of the parameter
description (Union[str, UnsetType]) – a brief description of the parameter
required (Union[bool, UnsetType]) – determines whether this parameter is mandatory
deprecated (Union[bool, UnsetType]) – a parameter is deprecated and SHOULD be transitioned out of usage
allowEmptyValue (Union[bool, UnsetType]) – the ability to pass empty-valued parameters
style (Union[StyleType, UnsetType]) – describes how the parameter value will be serialized depending on the type of the parameter value
explode (Union[bool, UnsetType]) – 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[bool, UnsetType]) – determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986 :/?#[]@!$&’()*+,;= to be included without percent-encoding
schema (Union[Dict[str, Any], UnsetType]) – the schema defining the type used for the parameter.
examples (Union[Dict[str, ExampleObject], UnsetType]) – examples of the parameter’s potential value
content (Union[Dict[str, MediaType], UnsetType]) – a map containing the representations for the parameter
- Return type
None
- class pjrpc.server.specs.openapi.Operation(responses, requestBody=UNSET, tags=UNSET, summary=UNSET, description=UNSET, externalDocs=UNSET, deprecated=UNSET, servers=UNSET, security=UNSET, parameters=UNSET)¶
Bases:
object
Describes a single API operation on a path.
- Parameters
tags (Union[List[str], UnsetType]) – a list of tags for API documentation control
summary (Union[str, UnsetType]) – a short summary of what the operation does
description (Union[str, UnsetType]) – a verbose explanation of the operation behavior
externalDocs (Union[ExternalDocumentation, UnsetType]) – additional external documentation for this operation
requestBody (Union[RequestBody, UnsetType]) – the request body applicable for this operation
responses (Dict[str, Response]) – the list of possible responses as they are returned from executing this operation
deprecated (Union[bool, UnsetType]) – declares this operation to be deprecated
servers (Union[List[Server], UnsetType]) – an alternative server array to service this operation
security (Union[List[Dict[str, List[str]]], UnsetType]) – a declaration of which security mechanisms can be used for this operation
- Return type
None
- 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)¶
Bases:
object
Describes the interface for the given method name.
- Parameters
summary (Union[str, UnsetType]) – an optional, string summary, intended to apply to all operations in this path
description (Union[str, UnsetType]) – an optional, string description, intended to apply to all operations in this path
servers (Union[List[Server], UnsetType]) – an alternative server array to service all operations in this path
- Return type
None
- pjrpc.server.specs.openapi.annotate(params_schema=UNSET, result_schema=UNSET, errors_schema=UNSET, errors=UNSET, examples=UNSET, error_examples=UNSET, tags=UNSET, summary=UNSET, description=UNSET, external_docs=UNSET, deprecated=UNSET, security=UNSET, parameters=UNSET)¶
Adds Open Api specification annotation to the method.
- Parameters
params_schema (Union[Dict[str, Schema], UnsetType]) – method parameters JSON schema
result_schema (Union[Schema, UnsetType]) – method result JSON schema
errors_schema (Union[List[Error], UnsetType]) – method errors schema
errors (Union[List[Type[JsonRpcError]], UnsetType]) – method errors
examples (Union[List[MethodExample], UnsetType]) – method usage examples
error_examples (Union[List[ErrorExample], UnsetType]) – method error examples
tags (Union[List[str], UnsetType]) – a list of tags for method documentation control
summary (Union[str, UnsetType]) – a short summary of what the method does
description (Union[str, UnsetType]) – a verbose explanation of the method behavior
external_docs (Union[ExternalDocumentation, UnsetType]) – an external resource for extended documentation
deprecated (Union[bool, UnsetType]) – declares this method to be deprecated
security (Union[List[Dict[str, List[str]]], UnsetType]) – a declaration of which security mechanisms can be used for the method
parameters (Union[List[Parameter], UnsetType]) – a list of parameters that are applicable for the method
- 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.0.0', schema_extractor=None, schema_extractors=(), ui=None, ui_path='/ui/')¶
Bases:
Specification
OpenAPI Specification.
- Parameters
info (Info) – provides metadata about the API
servers (Union[List[Server], UnsetType]) – an array of Server Objects, which provide connectivity information to a target server
external_docs (Union[ExternalDocumentation, UnsetType]) – additional external documentation
openapi (str) – the semantic version number of the OpenAPI Specification version that the OpenAPI document uses
tags (Union[List[Tag], UnsetType]) – a list of tags used by the specification with additional metadata
security (Union[List[Dict[str, List[str]]], UnsetType]) – 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[Dict[str, SecurityScheme], UnsetType]) – an object to hold reusable Security Scheme Objects
ui_path (str) – wet ui path
- schema(path, methods=(), methods_map={})¶
Returns specification schema.
- Parameters
- Return type
- class pjrpc.server.specs.openapi.SwaggerUI(**configs)¶
Bases:
BaseUI
Swagger 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)¶
Bases:
BaseUI
RapiDoc 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)¶
Bases:
BaseUI
ReDoc 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.Contact(name=UNSET, url=UNSET, email=UNSET)¶
Bases:
object
Contact information for the exposed API.
- class pjrpc.server.specs.openrpc.License(name, url=UNSET)¶
Bases:
object
License information for the exposed API.
- class pjrpc.server.specs.openrpc.Info(title, version, description=UNSET, contact=UNSET, license=UNSET, termsOfService=UNSET)¶
Bases:
object
Metadata about the API.
- Parameters
title (str) – the title of the application
version (str) – the version of the OpenRPC document
description (Union[str, UnsetType]) – a verbose description of the application
contact (Union[Contact, UnsetType]) – the contact information for the exposed API
license (Union[License, UnsetType]) – the license information for the exposed API
termsOfService (Union[str, UnsetType]) – a URL to the Terms of Service for the API
- Return type
None
- class pjrpc.server.specs.openrpc.Server(name, url, summary=UNSET, description=UNSET)¶
Bases:
object
Connectivity information of a target server.
- Parameters
- Return type
None
- class pjrpc.server.specs.openrpc.ExternalDocumentation(url, description=UNSET)¶
Bases:
object
Allows referencing an external resource for extended documentation.
- class pjrpc.server.specs.openrpc.Tag(name, summary=UNSET, description=UNSET, externalDocs=UNSET)¶
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.
- class pjrpc.server.specs.openrpc.ExampleObject(value, name, summary=UNSET, description=UNSET)¶
Bases:
object
The ExampleObject object is an object the defines an example.
- Parameters
- Return type
None
- class pjrpc.server.specs.openrpc.MethodExample(name, params, result, summary=UNSET, description=UNSET)¶
Bases:
object
The example Pairing object consists of a set of example params and result.
- Parameters
params (List[ExampleObject]) – example parameters
result (ExampleObject) – example result
name (str) – name for the example pairing
summary (Union[str, UnsetType]) – short description for the example pairing
description (Union[str, UnsetType]) – a verbose explanation of the example pairing
- Return type
None
- class pjrpc.server.specs.openrpc.ContentDescriptor(name, schema, summary=UNSET, description=UNSET, required=UNSET, deprecated=UNSET)¶
Bases:
object
Content 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[str, UnsetType]) – a short summary of the content that is being described
description (Union[str, UnsetType]) – a verbose explanation of the content descriptor behavior
required (Union[bool, UnsetType]) – determines if the content is a required field
deprecated (Union[bool, UnsetType]) – specifies that the content is deprecated and SHOULD be transitioned out of usage
- Return type
None
- class pjrpc.server.specs.openrpc.Error(code, message, data=UNSET)¶
Bases:
object
Defines an application level error.
- class pjrpc.server.specs.openrpc.ParamStructure(value)¶
-
The expected format of the parameters.
- BY_NAME = 'by-name'¶
- BY_POSITION = 'by-position'¶
- EITHER = 'either'¶
- class pjrpc.server.specs.openrpc.MethodInfo(name, params, result, errors=UNSET, paramStructure=UNSET, examples=UNSET, summary=UNSET, description=UNSET, tags=UNSET, deprecated=UNSET, externalDocs=UNSET, servers=UNSET)¶
Bases:
object
Describes the interface for the given method name.
- Parameters
name (str) – the canonical name for the method
params (List[Union[ContentDescriptor, dict]]) – a list of parameters that are applicable for this method
result (Union[ContentDescriptor, dict]) – the description of the result returned by the method
errors (Union[List[Error], UnsetType]) – a list of custom application defined errors that MAY be returned
examples (Union[List[MethodExample], UnsetType]) – method usage examples
summary (Union[str, UnsetType]) – a short summary of what the method does
description (Union[str, UnsetType]) – a verbose explanation of the method behavior
tags (Union[List[Tag], UnsetType]) – a list of tags for API documentation control
deprecated (Union[bool, UnsetType]) – declares this method to be deprecated
paramStructure (Union[ParamStructure, UnsetType]) – the expected format of the parameters
externalDocs (Union[ExternalDocumentation, UnsetType]) – additional external documentation for this method
servers (Union[List[Server], UnsetType]) – an alternative servers array to service this method
- Return type
None
- class pjrpc.server.specs.openrpc.Components(schemas=<factory>)¶
Bases:
object
Set of reusable objects for different aspects of the OpenRPC.
- pjrpc.server.specs.openrpc.annotate(params_schema=UNSET, result_schema=UNSET, errors=UNSET, examples=UNSET, summary=UNSET, description=UNSET, tags=UNSET, deprecated=UNSET)¶
Adds JSON-RPC method to the API specification.
- Parameters
params_schema (Union[List[ContentDescriptor], UnsetType]) – a list of parameters that are applicable for this method
result_schema (Union[ContentDescriptor, UnsetType]) – the description of the result returned by the method
errors (Union[List[Union[Error, Type[JsonRpcError]]], UnsetType]) – a list of custom application defined errors that MAY be returned
examples (Union[List[MethodExample], UnsetType]) – method usage example
summary (Union[str, UnsetType]) – a short summary of what the method does
description (Union[str, UnsetType]) – a verbose explanation of the method behavior
tags (Union[List[Union[Tag, str]], UnsetType]) – a list of tags for API documentation control
deprecated (Union[bool, UnsetType]) – declares this method to be deprecated
- Return type
Callable[[Func], Func]
- class pjrpc.server.specs.openrpc.OpenRPC(info, path='/openrpc.json', servers=UNSET, external_docs=UNSET, openrpc='1.0.0', schema_extractor=None)¶
Bases:
Specification
OpenRPC Specification.
- Parameters
info (Info) – specification information
path (str) – specification url path
servers (Union[List[Server], UnsetType]) – connectivity information
external_docs (Union[ExternalDocumentation, UnsetType]) – 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
- schema(path, methods=(), methods_map={})¶
Returns specification schema.
- Parameters
- Return type