demessaging.backend.class_ module

Transform a python class into a corresponding pydantic model.

The BackendClass model in this module generates subclasses based upon a python class (similarly as the BackendFunction does it for functions).

Classes:

BackendClass()

A basis for class models

BackendClassConfig(*, doc, registry, template)

Configuration class for a backend module class.

ClassAPIModel(*, name, rpc_schema, methods)

A class in the API suitable for RPC via DASF

class demessaging.backend.class_.BackendClass[source]

Bases: BaseModel

A basis for class models

Do not directly instantiate from this class, rather use the create_model() method.

Attributes:

backend_config

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

return_model

The return model of the member function.

Methods:

create_model(Class[, config, methods, ...])

Generate a pydantic model from a class.

get_api_info()

Get the API info on the function.

get_constructor_fields(Class, config, class_name)

model_json_schema(*args, **kwargs)

Generates a JSON schema for a model class.

backend_config: ClassVar[BackendClassConfig]
classmethod create_model(Class, config: ClassConfig | None = None, methods: List[Type[BackendFunction] | Callable | str] | None = None, class_name: str | None = None, **kwargs: Any) Type[BackendClass][source]

Generate a pydantic model from a class.

Parameters:
  • func (type) – A class

  • config (ClassConfig, optional) – The configuration to use. If given, this overrides the __pulsar_config__ of the given Class

  • methods (list of methods, optional) – A list of methods or model classes generated with FunctionModel(). This overrides the methods in config or the __pulsar_config__ attribute of Class

  • class_name (str, optional) – The name for the generated subclass of pydantic.BaseModel. If not given, the name of Class is used

  • **kwargs – Any other parameter for the pydantic.create_model() function

Returns:

The newly generated model that represents this class.

Return type:

Subclass of BackendClass

function: BackendFunction
classmethod get_api_info() ClassAPIModel[source]

Get the API info on the function.

classmethod get_constructor_fields(Class, config: ClassConfig, class_name: str | None) Tuple[Dict[str, Any], BackendClassConfig][source]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

classmethod model_json_schema(*args, **kwargs) Dict[str, Any][source]

Generates a JSON schema for a model class.

Parameters:
  • by_alias – Whether to use attribute aliases or not.

  • ref_template – The reference template.

  • union_format

    The format to use when combining schemas from unions together. Can be one of:

    keyword to combine schemas (the default). - ‘primitive_type_array’: Use the [type](https://json-schema.org/understanding-json-schema/reference/type) keyword as an array of strings, containing each type of the combination. If any of the schemas is not a primitive type (string, boolean, null, integer or number) or contains constraints/metadata, falls back to any_of.

  • schema_generator – To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications

  • mode – The mode in which to generate the schema.

Returns:

The JSON schema for the given model class.

property return_model: Type[BaseModel]

The return model of the member function.

class demessaging.backend.class_.BackendClassConfig(*, doc: str = '', registry: ~demessaging.config.registry.ApiRegistry = <factory>, template: ~demessaging.template.Template = Template(name='class_.py', folder=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/dasf/checkouts/latest/demessaging/templates'), suffix='.jinja2', context={}), name: str = '', init_doc: str = '', signature: ~inspect.Signature | None = None, methods: ~typing.List[str] = <factory>, validators: ~typing.Dict[str, ~typing.Any] = <factory>, serializers: ~typing.Dict[str, ~typing.Any] = <factory>, field_params: ~typing.Dict[str, ~typing.Dict[str, ~typing.Any]] = <factory>, annotations: ~typing.Dict[str, ~typing.Any] = <factory>, reporter_args: ~typing.Dict[str, ~deprogressapi.base.BaseReport] = <factory>, json_schema_extra: ~typing.Dict[str, ~typing.Any] = <factory>, models: ~typing.Dict[str, ~typing.Type[~demessaging.backend.function.BackendFunction]] = <factory>, Class: ~typing.Type[object], class_name: str)[source]

Bases: ClassConfig

Configuration class for a backend module class.

Parameters:
  • doc (str) – The documentation of the object. If empty, this will be taken from the corresponding __doc__ attribute.

  • registry (demessaging.config.registry.ApiRegistry) – Utilities for imports and encoders.

  • template (demessaging.template.Template) – The demessaging.template.Template that is used to render the class for the generated API.

  • name (str) – The name of the function. If empty, this will be taken from the classes __name__ attribute.

  • init_doc (str) – The documentation of the function. If empty, this will be taken from the classes __init__ method.

  • signature (Optional[inspect.Signature]) – The calling signature for the function. If empty, this will be taken from the function itself.

  • methods (List[str]) – methods to use within the backend modules

  • validators (Dict[str, Any]) – custom validators for the constructor parameters

  • serializers (Dict[str, Any]) – A mapping from function argument to serializer that is of instance pydantic.functional_serializers.PlainSerializer or pydantic.functional_serializers.WrapSerializer.

  • field_params (Dict[str, Dict[str, Any]]) – custom Field overrides for the constructor parameters. See pydantic.Fields.Field()

  • annotations (Dict[str, Any]) – custom annotations for constructor parameters

  • reporter_args (Dict[str, deprogressapi.base.BaseReport]) – Arguments that use the dasf-progress-api

  • json_schema_extra (Dict[str, Any]) – Any extra parameter for the JSON schema export for the function

  • models (Dict[str, Type[demessaging.backend.function.BackendFunction]]) – Mapping of method name to the function model for the methods of this class

  • Class (Type[object]) – The class that corresponds to this config.

  • class_name (str) – Name of the model class

Attributes:

Class

class_name

method_configs

Get a list of the method configs.

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

models

Methods:

update_from_cls()

Update the config from the corresponding function.

Class: Type[object]
annotations: Dict[str, Any]
class_name: str
doc: str
field_params: Dict[str, Dict[str, Any]]
init_doc: str
json_schema_extra: Dict[str, Any]
property method_configs: List[BackendFunctionConfig]

Get a list of the method configs.

methods: List[str]
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

models: Dict[str, Type[BackendFunction]]
name: str
registry: ApiRegistry
reporter_args: Dict[str, BaseReport]
serializers: Dict[str, Any]
signature: inspect.Signature | None
template: Template
update_from_cls() None[source]

Update the config from the corresponding function.

validators: Dict[str, Any]
class demessaging.backend.class_.ClassAPIModel(*, name: str, rpc_schema: dict[str, Any], methods: List[FunctionAPIModel])[source]

Bases: BaseModel

A class in the API suitable for RPC via DASF

Attributes:

methods

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name

rpc_schema

methods: List[FunctionAPIModel]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
rpc_schema: JsonSchemaValue