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, ...])

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_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config

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

model_fields

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

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_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

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

model_fields: ClassVar[dict[str, FieldInfo]] = {}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

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.

  • 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: ApiRegistry = None, 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: Signature | None = None, methods: List[str] = None, validators: Dict[str, Any] = None, serializers: Dict[str, Any] = None, field_params: Dict[str, Dict[str, Any]] = None, annotations: Dict[str, Any] = None, reporter_args: Dict[str, BaseReport] = None, json_schema_extra: Dict[str, Any] = None, models: Dict[str, Type[BackendFunction]] = None, Class: 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_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config

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

model_fields

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

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_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

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

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

model_fields: ClassVar[dict[str, FieldInfo]] = {'Class': FieldInfo(annotation=Type[object], required=True, description='The class that corresponds to this config.'), 'annotations': FieldInfo(annotation=Dict[str, Any], required=False, default_factory=dict, description='custom annotations for constructor parameters'), 'class_name': FieldInfo(annotation=str, required=True, description='Name of the model class'), 'doc': FieldInfo(annotation=str, required=False, default='', description='The documentation of the object. If empty, this will be taken from the corresponding ``__doc__`` attribute.'), 'field_params': FieldInfo(annotation=Dict[str, Dict[str, Any]], required=False, default_factory=dict, description='custom Field overrides for the constructor parameters. See :func:`pydantic.Fields.Field`'), 'init_doc': FieldInfo(annotation=str, required=False, default='', description='The documentation of the function. If empty, this will be taken from the classes ``__init__`` method.'), 'json_schema_extra': FieldInfo(annotation=Dict[str, Any], required=False, default_factory=dict, description='Any extra parameter for the JSON schema export for the function'), 'methods': FieldInfo(annotation=List[str], required=False, default_factory=list, description='methods to use within the backend modules'), 'models': FieldInfo(annotation=Dict[str, Type[BackendFunction]], required=False, default_factory=dict, description='Mapping of method name to the function model for the methods of this class'), 'name': FieldInfo(annotation=str, required=False, default='', description='The name of the function. If empty, this will be taken from the classes ``__name__`` attribute.'), 'registry': FieldInfo(annotation=ApiRegistry, required=False, default_factory=_get_registry, description='Utilities for imports and encoders.'), 'reporter_args': FieldInfo(annotation=Dict[str, BaseReport], required=False, default_factory=dict, description='Arguments that use the dasf-progress-api'), 'serializers': FieldInfo(annotation=Dict[str, Any], required=False, default_factory=dict, description='A mapping from function argument to serializer that is of instance :class:`pydantic.functional_serializers.PlainSerializer` or :class:`pydantic.functional_serializers.WrapSerializer`.'), 'signature': FieldInfo(annotation=Union[Signature, NoneType], required=False, default=None, description='The calling signature for the function. If empty, this will be taken from the function itself.'), 'template': FieldInfo(annotation=Template, required=False, default=Template(name='class_.py', folder=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/dasf/checkouts/latest/demessaging/templates'), suffix='.jinja2', context={}), description='The :class:`demessaging.template.Template` that is used to render the class for the generated API.'), 'validators': FieldInfo(annotation=Dict[str, Any], required=False, default_factory=dict, description='custom validators for the constructor parameters')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

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_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config

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

model_fields

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

name

rpc_schema

methods: List[FunctionAPIModel]
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

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

model_fields: ClassVar[dict[str, FieldInfo]] = {'methods': FieldInfo(annotation=List[FunctionAPIModel], required=True, description='The list of methods that this class provides.'), 'name': FieldInfo(annotation=str, required=True, description='The name of the class that is used as identifier in the RPC.'), 'rpc_schema': FieldInfo(annotation=Dict[str, Any], required=True, description='The JSON Schema for the constructor of the class.')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

name: str
rpc_schema: JsonSchemaValue