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:
A basis for class models |
|
|
Configuration class for a backend module class. |
|
A class in the API suitable for RPC via DASF |
- class demessaging.backend.class_.BackendClass[source]
Bases:
BaseModelA basis for class models
Do not directly instantiate from this class, rather use the
create_model()method.Attributes:
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
The return model of the member function.
Methods:
create_model(Class[, config, methods, ...])Generate a pydantic model from a class.
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 Classmethods (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 Classclass_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:
’any_of’: Use the [anyOf](https://json-schema.org/understanding-json-schema/reference/combining#anyOf)
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.
- 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:
ClassConfigConfiguration 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.Templatethat 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.PlainSerializerorpydantic.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:
Get a list of the method configs.
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Methods:
Update the config from the corresponding function.
- property method_configs: List[BackendFunctionConfig]
Get a list of the method configs.
- 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]]
- registry: ApiRegistry
- signature: inspect.Signature | None
- class demessaging.backend.class_.ClassAPIModel(*, name: str, rpc_schema: dict[str, Any], methods: List[FunctionAPIModel])[source]
Bases:
BaseModelA class in the API suitable for RPC via DASF
Attributes:
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- methods: List[FunctionAPIModel]
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- rpc_schema: JsonSchemaValue