nat.data_models.common#
Attributes#
Classes#
Subclass of a Pydantic BaseModel that is hashable. Use in objects that need to be hashed for caching purposes. |
|
Subclass of Pydantic BaseModel that allows for specifying the object type. Use in Pydantic discriminated unions. |
Functions#
|
Compute a class' subclass depth. |
|
Get the origin of a type or the base class if it is not a generic. |
|
Extract the secret value from a SecretStr or return None. |
|
Set a SecretStr field in a Pydantic model from an environment variable, but only if the environment variable is set. |
Module Contents#
- _LT#
- class HashableBaseModel(/, **data: Any)#
Bases:
pydantic.BaseModelSubclass of a Pydantic BaseModel that is hashable. Use in objects that need to be hashed for caching purposes.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.
- _get_origin_or_base(cls: type) type#
Get the origin of a type or the base class if it is not a generic.
- class BaseModelRegistryTag#
- class TypedBaseModel(/, **data: Any)#
Bases:
pydantic.BaseModelSubclass of Pydantic BaseModel that allows for specifying the object type. Use in Pydantic discriminated unions.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- model_post_init(__context)#
Set the type field to the correct value after instance creation.
- classmethod model_json_schema(
- by_alias: bool = True,
- ref_template: str = '#/$defs/{model}',
- schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema,
- mode: pydantic.json_schema.JsonSchemaMode = 'validation',
Override to provide correct default for type field in schema.
- classmethod static_type()#
- classmethod static_full_type()#
- TypedBaseModelT#
- get_secret_value(v: pydantic.SecretStr | None) str | None#
Extract the secret value from a SecretStr or return None.
Parameters#
- v: SecretStr or None.
A field defined as OptionalSecretStr, which is either a SecretStr or None.
Returns#
- str | None
The secret value as a plain string, or None if v is None.
- set_secret_from_env( )#
Set a SecretStr field in a Pydantic model from an environment variable, but only if the environment variable is set.
Parameters#
- model: BaseModel
The Pydantic model instance containing the field to set.
- field_name: str
The name of the field in the model to set.
- env_var: str
The name of the environment variable to read the secret value from.
- SerializableSecretStr#
- OptionalSecretStr#