Models
plateforme.core.schema.models
This module provides utilities for managing models, validation and serialization within the Plateforme framework using Pydantic features.
The BaseModel
class is the foundational base for all models within the
Plateforme framework. It extends Pydantic's BaseModel
with additional
functionality and integrates with the framework resource and service classes.
The ModelConfig
class is a configuration object used to define various
settings and behaviors for Plateforme models, such as validation rules and
serialization options.
Examples:
>>> from plateforme import BaseModel, Field
...
>>> class FooModel(BaseModel):
... name: str = Field(
... ...,
... unique=True,
... title='Foo Model',
... description='Name of the foo instance')
...
>>> class BarModel(BaseModel):
... name: str = Field(
... ...,
... unique=True,
... title='Bar Model',
... description='Name of the bar instance',
... )
... foo: FooModel | None = Field(title='Foo Reference')
Note
See also the Field
function for more information on modeling features.
Model
module-attribute
Model = TypeVar('Model', bound='BaseModel')
A type variable for a model class.
ModelFieldInfo
module-attribute
ModelFieldInfo = FieldInfo['BaseModel']
A type alias for a model field information.
RootModelType
module-attribute
RootModelType = Type['RootModel[Any]']
A type alias for a root model class.
DiscriminatedModelType
module-attribute
DiscriminatedModelType = Type[
"DiscriminatedModel[BaseModel]"
]
A type alias for a discriminated model class.
BaseModelConfigDict
Bases: TypedDict
A model class configuration dictionary.
alias
instance-attribute
alias: str
The alias name of the model. It must adhere to a specific ALIAS
pattern as defined in the framework's regular expressions repository. It is
inferred from the snake case version of the resolved model identifier.
slug
instance-attribute
slug: str
The slug name of the model. It must adhere to a specific SLUG
pattern as defined in the framework's regular expressions repository. It is
inferred from the pluralized kebab case version of the model identifier.
title
instance-attribute
title: str
The human-readable name of the model. It must adhere to a specific
TITLE
pattern as defined in the framework's regular expressions
repository. It is inferred from the titleized version of the model
identifier.
str_to_lower
instance-attribute
str_to_lower: bool
Whether to convert strings to lowercase. Defaults to False
.
str_to_upper
instance-attribute
str_to_upper: bool
Whether to convert strings to uppercase. Defaults to False
.
str_strip_whitespace
instance-attribute
str_strip_whitespace: bool
Whether to strip whitespace from strings. Defaults to False
.
str_min_length
instance-attribute
str_min_length: int
The minimum length for strings. Defaults to None
.
str_max_length
instance-attribute
str_max_length: int | None
The maximum length for strings. Defaults to None
.
populate_by_name
instance-attribute
populate_by_name: bool
Whether to populate fields by name. Defaults to False
.
use_enum_values
instance-attribute
use_enum_values: bool
Whether to use enum values. Defaults to False
.
validate_assignment
instance-attribute
validate_assignment: bool
Whether to validate assignments. Defaults to False
.
arbitrary_types_allowed
instance-attribute
arbitrary_types_allowed: bool
Whether to allow arbitrary types. Defaults to False
.
from_attributes
instance-attribute
from_attributes: bool
Whether to set attributes from the configuration.
Defaults to False
.
loc_by_alias
instance-attribute
loc_by_alias: bool
Whether to use the alias for error loc
s. Defaults to True
.
alias_generator
instance-attribute
alias_generator: (
Callable[[str], str] | AliasGenerator | None
)
A callable or alias generator to create aliases for the model.
Defaults to None
.
ignored_types
instance-attribute
A tuple of types to ignore. Defaults to an empty tuple.
allow_inf_nan
instance-attribute
allow_inf_nan: bool
Whether to allow infinity and NaN. Defaults to True
.
json_schema_extra
instance-attribute
json_schema_extra: JsonSchemaExtraCallable | None
Dictionary of extra JSON schema properties. Defaults to None
.
json_encoders
instance-attribute
json_encoders: dict[type[object], JsonEncoder] | None
A dictionary of custom JSON encoders for specific types.
Defaults to None
.
revalidate_instances
instance-attribute
revalidate_instances: Literal[
"always", "never", "subclass-instances"
]
When and how to revalidate models and dataclasses during validation.
Defaults to never
.
ser_json_timedelta
instance-attribute
ser_json_timedelta: Literal['iso8601', 'float']
The format of JSON serialized timedeltas. Defaults to iso8601
.
ser_json_bytes
instance-attribute
ser_json_bytes: Literal['utf8', 'base64']
The encoding of JSON serialized bytes. Defaults to utf8
.
ser_json_inf_nan
instance-attribute
ser_json_inf_nan: Literal['null', 'constants']
The encoding of JSON serialized infinity and NaN float values. Accepts
the string values of 'null'
and 'constants'
.
Defaults to 'null'
.
validate_default
instance-attribute
validate_default: bool
Whether to validate default values during validation.
Defaults to False
.
validate_return
instance-attribute
validate_return: bool
Whether to validate return values during validation.
Defaults to False
.
protected_namespaces
instance-attribute
A tuple of strings that prevent models to have field which conflict with
them. The provided namespaces are added to the internally forbidden and
protected ones, model_
, resource_
, and service_
.
Defaults to an empty tuple.
hide_input_in_errors
instance-attribute
hide_input_in_errors: bool
Whether to hide inputs when printing errors. Defaults to False
.
plugin_settings
instance-attribute
A dictionary of settings for plugins. Defaults to None
.
schema_generator
instance-attribute
A custom core schema generator class to use when generating JSON
schemas. Defaults to None
.
json_schema_serialization_defaults_required
instance-attribute
json_schema_serialization_defaults_required: bool
Whether fields with default values should be marked as required in the
serialization schema. Defaults to False
.
json_schema_mode_override
instance-attribute
json_schema_mode_override: (
Literal["validation", "serialization"] | None
)
If not None
, the specified mode will be used to generate the JSON
schema regardless of what mode
was passed to the function call.
Defaults to None
.
coerce_numbers_to_str
instance-attribute
coerce_numbers_to_str: bool
If True
, enables automatic coercion of any Number
type to str
in
lax
(non-strict) mode. Defaults to False
.
regex_engine
instance-attribute
regex_engine: Literal['rust-regex', 'python-re']
The regex engine to use for pattern validation.
Defaults to rust-regex
.
validation_error_cause
instance-attribute
validation_error_cause: bool
If True
, Python exceptions that were part of a validation failure
will be shown as an exception group as a cause. Can be useful for
debugging. Defaults to False
.
use_attribute_docstrings
instance-attribute
use_attribute_docstrings: bool
Whether docstrings of attributes should be used for field descriptions.
Defaults to False
.
cache_strings
instance-attribute
Whether to cache strings to avoid constructing new Python objects.
Enabling this setting should significantly improve validation performance
while increasing memory usage slightly.
- True
or 'all'
(default): Cache all strings
- 'keys'
: Cache only dictionary keys
- False
or 'none'
: No caching
Defaults to True
.
ModelConfigDict
Bases: BaseModelConfigDict
A model class configuration dictionary.
alias
instance-attribute
alias: str
The alias name of the model. It must adhere to a specific ALIAS
pattern as defined in the framework's regular expressions repository. It is
inferred from the snake case version of the resolved model identifier.
slug
instance-attribute
slug: str
The slug name of the model. It must adhere to a specific SLUG
pattern as defined in the framework's regular expressions repository. It is
inferred from the pluralized kebab case version of the model identifier.
title
instance-attribute
title: str
The human-readable name of the model. It must adhere to a specific
TITLE
pattern as defined in the framework's regular expressions
repository. It is inferred from the titleized version of the model
identifier.
str_to_lower
instance-attribute
str_to_lower: bool
Whether to convert strings to lowercase. Defaults to False
.
str_to_upper
instance-attribute
str_to_upper: bool
Whether to convert strings to uppercase. Defaults to False
.
str_strip_whitespace
instance-attribute
str_strip_whitespace: bool
Whether to strip whitespace from strings. Defaults to False
.
str_min_length
instance-attribute
str_min_length: int
The minimum length for strings. Defaults to None
.
str_max_length
instance-attribute
str_max_length: int | None
The maximum length for strings. Defaults to None
.
populate_by_name
instance-attribute
populate_by_name: bool
Whether to populate fields by name. Defaults to False
.
use_enum_values
instance-attribute
use_enum_values: bool
Whether to use enum values. Defaults to False
.
validate_assignment
instance-attribute
validate_assignment: bool
Whether to validate assignments. Defaults to False
.
arbitrary_types_allowed
instance-attribute
arbitrary_types_allowed: bool
Whether to allow arbitrary types. Defaults to False
.
from_attributes
instance-attribute
from_attributes: bool
Whether to set attributes from the configuration.
Defaults to False
.
loc_by_alias
instance-attribute
loc_by_alias: bool
Whether to use the alias for error loc
s. Defaults to True
.
alias_generator
instance-attribute
alias_generator: (
Callable[[str], str] | AliasGenerator | None
)
A callable or alias generator to create aliases for the model.
Defaults to None
.
ignored_types
instance-attribute
A tuple of types to ignore. Defaults to an empty tuple.
allow_inf_nan
instance-attribute
allow_inf_nan: bool
Whether to allow infinity and NaN. Defaults to True
.
json_schema_extra
instance-attribute
json_schema_extra: JsonSchemaExtraCallable | None
Dictionary of extra JSON schema properties. Defaults to None
.
json_encoders
instance-attribute
json_encoders: dict[type[object], JsonEncoder] | None
A dictionary of custom JSON encoders for specific types.
Defaults to None
.
revalidate_instances
instance-attribute
revalidate_instances: Literal[
"always", "never", "subclass-instances"
]
When and how to revalidate models and dataclasses during validation.
Defaults to never
.
ser_json_timedelta
instance-attribute
ser_json_timedelta: Literal['iso8601', 'float']
The format of JSON serialized timedeltas. Defaults to iso8601
.
ser_json_bytes
instance-attribute
ser_json_bytes: Literal['utf8', 'base64']
The encoding of JSON serialized bytes. Defaults to utf8
.
ser_json_inf_nan
instance-attribute
ser_json_inf_nan: Literal['null', 'constants']
The encoding of JSON serialized infinity and NaN float values. Accepts
the string values of 'null'
and 'constants'
.
Defaults to 'null'
.
validate_default
instance-attribute
validate_default: bool
Whether to validate default values during validation.
Defaults to False
.
validate_return
instance-attribute
validate_return: bool
Whether to validate return values during validation.
Defaults to False
.
protected_namespaces
instance-attribute
A tuple of strings that prevent models to have field which conflict with
them. The provided namespaces are added to the internally forbidden and
protected ones, model_
, resource_
, and service_
.
Defaults to an empty tuple.
hide_input_in_errors
instance-attribute
hide_input_in_errors: bool
Whether to hide inputs when printing errors. Defaults to False
.
plugin_settings
instance-attribute
A dictionary of settings for plugins. Defaults to None
.
schema_generator
instance-attribute
A custom core schema generator class to use when generating JSON
schemas. Defaults to None
.
json_schema_serialization_defaults_required
instance-attribute
json_schema_serialization_defaults_required: bool
Whether fields with default values should be marked as required in the
serialization schema. Defaults to False
.
json_schema_mode_override
instance-attribute
json_schema_mode_override: (
Literal["validation", "serialization"] | None
)
If not None
, the specified mode will be used to generate the JSON
schema regardless of what mode
was passed to the function call.
Defaults to None
.
coerce_numbers_to_str
instance-attribute
coerce_numbers_to_str: bool
If True
, enables automatic coercion of any Number
type to str
in
lax
(non-strict) mode. Defaults to False
.
regex_engine
instance-attribute
regex_engine: Literal['rust-regex', 'python-re']
The regex engine to use for pattern validation.
Defaults to rust-regex
.
validation_error_cause
instance-attribute
validation_error_cause: bool
If True
, Python exceptions that were part of a validation failure
will be shown as an exception group as a cause. Can be useful for
debugging. Defaults to False
.
use_attribute_docstrings
instance-attribute
use_attribute_docstrings: bool
Whether docstrings of attributes should be used for field descriptions.
Defaults to False
.
cache_strings
instance-attribute
Whether to cache strings to avoid constructing new Python objects.
Enabling this setting should significantly improve validation performance
while increasing memory usage slightly.
- True
or 'all'
(default): Cache all strings
- 'keys'
: Cache only dictionary keys
- False
or 'none'
: No caching
Defaults to True
.
defer_build
instance-attribute
defer_build: bool
Whether to defer model validator and serializer construction until the
first model validation. Defaults to False
.
extra
instance-attribute
extra: Literal['allow', 'ignore', 'forbid']
Extra values to include in this configuration.
Defaults to forbid
.
ModelConfig
ModelConfig(
__owner: Any | None = None,
__defaults: dict[str, Any] | None = None,
__partial_init: bool = False,
/,
**data: Any,
)
Bases: ConfigWrapper
A model class configuration.
Initialize the configuration class with the given data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__owner
|
Any | None
|
The owner of the configuration instance. It can be any
object or type that uses the configuration instance.
Defaults to |
None
|
__defaults
|
dict[str, Any] | None
|
The default values to initialize the configuration
instance with. Defaults to |
None
|
__partial_init
|
bool
|
Flag indicating whether to partially initialize
the configuration instance. Defaults to |
False
|
**data
|
Any
|
The data as keyword arguments to initialize the configuration instance with. |
{}
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
type_
class-attribute
instance-attribute
type_: str = ConfigField(
default="model", frozen=True, init=False
)
The configuration owner type set to model
. It is a protected field
that is typically used with check_config
to validate an object type
without using isinstance
in order to avoid circular imports.
stub
class-attribute
instance-attribute
stub: bool = ConfigField(
default=False, frozen=True, init=False
)
Whether the model is a stub model. This is set to True
when a
collected bare model has a final stub no-operation statement.
Defaults to False
.
alias
class-attribute
instance-attribute
alias: str = Deferred
The alias name of the model. It must adhere to a specific ALIAS
pattern as defined in the framework's regular expressions repository. It is
inferred from the snake case version of the resolved model identifier.
slug
class-attribute
instance-attribute
slug: str = Deferred
The slug name of the model. It must adhere to a specific SLUG
pattern as defined in the framework's regular expressions repository. It is
inferred from the pluralized kebab case version of the model identifier.
title
class-attribute
instance-attribute
The human-readable name of the model. It must adhere to a specific
TITLE
pattern as defined in the framework's regular expressions
repository. It is inferred from the titleized version of the model
identifier.
str_to_lower
class-attribute
instance-attribute
Whether to convert strings to lowercase. Defaults to False
.
str_to_upper
class-attribute
instance-attribute
Whether to convert strings to uppercase. Defaults to False
.
str_strip_whitespace
class-attribute
instance-attribute
Whether to strip whitespace from strings. Defaults to False
.
str_min_length
class-attribute
instance-attribute
The minimum length for strings. Defaults to None
.
str_max_length
class-attribute
instance-attribute
The maximum length for strings. Defaults to None
.
extra
class-attribute
instance-attribute
Extra values to include in this configuration.
Defaults to forbid
.
frozen
class-attribute
instance-attribute
Whether to freeze the configuration. Defaults to False
.
populate_by_name
class-attribute
instance-attribute
Whether to populate fields by name. Defaults to False
.
use_enum_values
class-attribute
instance-attribute
Whether to use enum values. Defaults to False
.
validate_assignment
class-attribute
instance-attribute
Whether to validate assignments. Defaults to False
.
arbitrary_types_allowed
class-attribute
instance-attribute
Whether to allow arbitrary types. Defaults to False
.
from_attributes
class-attribute
instance-attribute
Whether to set attributes from the configuration.
Defaults to False
.
loc_by_alias
class-attribute
instance-attribute
Whether to use the alias for error loc
s. Defaults to True
.
alias_generator
class-attribute
instance-attribute
alias_generator: Annotated[
Callable[[str], str] | AliasGenerator | None, pydantic
] = to_name_case
A callable or alias generator to create aliases for the model.
Defaults to None
.
ignored_types
class-attribute
instance-attribute
A tuple of types to ignore. Defaults to an empty tuple.
allow_inf_nan
class-attribute
instance-attribute
Whether to allow infinity and NaN. Defaults to True
.
json_schema_extra
class-attribute
instance-attribute
json_schema_extra: Annotated[
JsonSchemaExtraCallable | None, pydantic
] = None
Dictionary of extra JSON schema properties. Defaults to None
.
json_encoders
class-attribute
instance-attribute
json_encoders: Annotated[
dict[type[object], JsonEncoder] | None, pydantic
] = None
A dictionary of custom JSON encoders for specific types.
Defaults to None
.
strict
class-attribute
instance-attribute
Whether to make the configuration strict. Defaults to False
.
revalidate_instances
class-attribute
instance-attribute
revalidate_instances: Annotated[
Literal["always", "never", "subclass-instances"],
pydantic,
] = "never"
When and how to revalidate models and dataclasses during validation.
Defaults to never
.
ser_json_timedelta
class-attribute
instance-attribute
The format of JSON serialized timedeltas. Defaults to iso8601
.
ser_json_bytes
class-attribute
instance-attribute
The encoding of JSON serialized bytes. Defaults to utf8
.
ser_json_inf_nan
class-attribute
instance-attribute
The encoding of JSON serialized infinity and NaN float values. Accepts
the string values of 'null'
and 'constants'
.
Defaults to 'null'
.
validate_default
class-attribute
instance-attribute
Whether to validate default values during validation.
Defaults to False
.
validate_return
class-attribute
instance-attribute
Whether to validate return values during validation.
Defaults to False
.
protected_namespaces
class-attribute
instance-attribute
A tuple of strings that prevent models to have field which conflict with
them. The provided namespaces are added to the internally forbidden and
protected ones, model_
, resource_
, and service_
.
Defaults to an empty tuple.
hide_input_in_errors
class-attribute
instance-attribute
Whether to hide inputs when printing errors. Defaults to False
.
defer_build
class-attribute
instance-attribute
Whether to defer model validator and serializer construction until the
first model validation. Defaults to False
.
plugin_settings
class-attribute
instance-attribute
A dictionary of settings for plugins. Defaults to None
.
schema_generator
class-attribute
instance-attribute
A custom core schema generator class to use when generating JSON
schemas. Defaults to None
.
json_schema_serialization_defaults_required
class-attribute
instance-attribute
Whether fields with default values should be marked as required in the
serialization schema. Defaults to False
.
json_schema_mode_override
class-attribute
instance-attribute
json_schema_mode_override: Annotated[
Literal["validation", "serialization"] | None, pydantic
] = None
If not None
, the specified mode will be used to generate the JSON
schema regardless of what mode
was passed to the function call.
Defaults to None
.
coerce_numbers_to_str
class-attribute
instance-attribute
If True
, enables automatic coercion of any Number
type to str
in
lax
(non-strict) mode. Defaults to False
.
regex_engine
class-attribute
instance-attribute
The regex engine to use for pattern validation.
Defaults to rust-regex
.
validation_error_cause
class-attribute
instance-attribute
If True
, Python exceptions that were part of a validation failure
will be shown as an exception group as a cause. Can be useful for
debugging. Defaults to False
.
use_attribute_docstrings
class-attribute
instance-attribute
Whether docstrings of attributes should be used for field descriptions.
Defaults to False
.
cache_strings
class-attribute
instance-attribute
Whether to cache strings to avoid constructing new Python objects.
Enabling this setting should significantly improve validation performance
while increasing memory usage slightly.
- True
or 'all'
(default): Cache all strings
- 'keys'
: Cache only dictionary keys
- False
or 'none'
: No caching
Defaults to True
.
create
classmethod
create(
owner: Any | None = None,
defaults: dict[str, Any] | None = None,
partial_init: bool = False,
*,
data: dict[str, Any] | None = None,
) -> Self
Create a new configuration instance.
This method is typically used internally to create a new configuration
class with a specific owner and partial initialization flag. It is an
alternative to the __init__
method for creating a new configuration
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owner
|
Any | None
|
The owner of the configuration instance. |
None
|
defaults
|
dict[str, Any] | None
|
The default values to initialize the configuration
instance with. Defaults to |
None
|
partial_init
|
bool
|
Flag indicating whether to partially initialize the
configuration instance. Defaults to |
False
|
data
|
dict[str, Any] | None
|
The data to initialize the configuration instance with.
Defaults to |
None
|
Returns:
Type | Description |
---|---|
Self
|
The new configuration instance created. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
from_meta
classmethod
from_meta(
owner: type[Any],
bases: tuple[type, ...],
namespace: dict[str, Any],
/,
config_attr: str = "__config__",
partial_init: bool = False,
data: dict[str, Any] | None = None,
) -> Self
Create a new configuration instance from a class constructor.
This method is typically used internally to create a new configuration class from the meta configuration of a model, package, resource, or service. It merges the configuration of the given bases, the namespace, and the keyword arguments to create a new configuration class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owner
|
type[Any]
|
The owner of the configuration instance. It should be the class that is being created from the meta configuration. |
required |
bases
|
tuple[type, ...]
|
The configurable base classes to merge. |
required |
namespace
|
dict[str, Any]
|
The configurable namespace to merge. |
required |
config_attr
|
str
|
The configurable attribute name used to extract the
configuration dictionary from the bases and the namespace of
the configurable class. Defaults to |
'__config__'
|
partial_init
|
bool
|
Flag indicating whether to partially initialize the
configuration instance. Defaults to |
False
|
data
|
dict[str, Any] | None
|
The data to initialize the configuration instance with.
Defaults to |
None
|
Returns:
Type | Description |
---|---|
Self
|
The new configuration instance created from the given meta |
Self
|
configuration. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
validate
Validate the configuration instance.
It post-initializes the configuration instance, checks for any missing required fields and validates the assignments of the configuration values based on the configuration fields information and the current validation context. This is performed automatically upon initialization of the configuration instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strict
|
bool | None
|
Whether to enforce strict validation. Defaults to |
None
|
context
|
dict[str, Any] | None
|
The context to use for validation. Defaults to |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If the configuration instance has undefined values for required fields. |
ValidationError
|
If the assignment of a value is invalid based on the configuration fields information and the current validation context. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
context
staticmethod
Context manager for the configuration instance.
If the frozen mutation flag is not specified, the current frozen
mutation flag is used if available, otherwise it defaults to False
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
allow_mutation
|
bool | None
|
Flag indicating whether to allow frozen mutation
of the configuration instance. When set to |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
clear
copy
copy() -> Self
Return a shallow copy of the configuration dictionary.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
merge
Merge the configuration with other configurations.
It merges the configuration with the provided configuration instances
or dictionaries. The precedence of the rightmost configuration is
higher than the leftmost configuration. This can be changed by setting
the setdefault
argument to True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*configs
|
Self | dict[str, Any]
|
The configuration instances or dictionaries to merge with the target configuration dictionary. |
()
|
setdefault
|
bool
|
Flag indicating whether to set the default values for
the configuration keys if they are not already set.
This modifies the behavior of the merge operation, making the
precedence of the leftmost configuration higher than the
rightmost configuration.
Defaults to |
False
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
check
check(
key: str,
*,
scope: Literal["all", "default", "set"] = "all",
raise_errors: bool = True,
) -> bool
Check if the configuration key exists in the given scope.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The configuration key to check for. |
required |
scope
|
Literal['all', 'default', 'set']
|
The scope to check for the configuration key. It can be
either |
'all'
|
raise_errors
|
bool
|
Flag indicating whether to raise an error if the
configuration key is not defined for the configuration wrapper.
Defaults to |
True
|
Returns:
Type | Description |
---|---|
bool
|
A boolean indicating whether the configuration key exists in the |
bool
|
specified scope. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
entries
entries(
*,
scope: Literal["all", "default", "set"] = "all",
default_mode: Literal[
"preserve", "unwrap", "wrap"
] = "unwrap",
include_keys: Iterable[str] | None = None,
exclude_keys: Iterable[str] | None = None,
include_metadata: Iterable[Any] | None = None,
exclude_metadata: Iterable[Any] | None = None,
) -> dict[str, Any]
Return the configuration dictionary.
It returns the configuration dictionary based on the specified scope, and keys and extra information to filter the configuration dictionary entries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scope
|
Literal['all', 'default', 'set']
|
The scope of the configuration dictionary to return. It can
be either |
'all'
|
default_mode
|
Literal['preserve', 'unwrap', 'wrap']
|
The default mode to use when returning a default
entry from the configuration dictionary. It can be either
|
'unwrap'
|
include_keys
|
Iterable[str] | None
|
The keys to include from the configuration dictionary
entries. Defaults to |
None
|
exclude_keys
|
Iterable[str] | None
|
The keys to exclude from the configuration dictionary
entries. Defaults to |
None
|
include_metadata
|
Iterable[Any] | None
|
The metadata information to include from the
configuration dictionary entries. Defaults to |
None
|
exclude_metadata
|
Iterable[Any] | None
|
The metadata information to exclude from the
configuration dictionary entries. Defaults to |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
A dictionary containing the configuration entries based on the |
dict[str, Any]
|
specified scope and extra information. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 |
|
keys
values
values() -> ValuesView[Any]
items
get
get(
key: str,
default: Any = Undefined,
*,
default_mode: Literal[
"preserve", "unwrap", "wrap"
] = "unwrap",
) -> Any
Get the value for the specified key if set otherwise the default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The configuration key to get the value for. |
required |
default
|
Any
|
The default value to return if the key is not set. |
Undefined
|
default_mode
|
Literal['preserve', 'unwrap', 'wrap']
|
The default mode to use when returning a default
value from the configuration dictionary. It can be either
|
'unwrap'
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
pop
pop(
key: str,
default: Any = Undefined,
*,
default_mode: Literal[
"preserve", "unwrap", "wrap"
] = "unwrap",
) -> Any
Pop the specified key if set and return its corresponding value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The configuration key to pop the value for. |
required |
default
|
Any
|
The default value to return if the key is not set. |
Undefined
|
default_mode
|
Literal['preserve', 'unwrap', 'wrap']
|
The default mode to use when returning a default
value from the configuration dictionary. It can be either
|
'unwrap'
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
getdefault
Get the default value for the specified key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The configuration key to get the default value for. |
required |
mode
|
Literal['preserve', 'unwrap', 'wrap']
|
The mode to use when returning the default value. It can be
either |
'unwrap'
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
setdefault
Set the default value for the specified key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The configuration key to set the default value for. |
required |
default
|
Any
|
The default value to set for the key. |
required |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
update
Update the config dictionary with new data.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
post_init
Post-initialization steps for the model configuration.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
ModelMeta
ModelMeta(
name: str,
bases: tuple[type, ...],
namespace: dict[str, Any],
/,
*args: Any,
**kwargs: Any,
)
Bases: ConfigurableMeta
, ModelMetaclass
Meta class for the base model class.
Initialize a new model meta class.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
collect_config_wrappers
Collect configuration wrappers from the given bases and namespace.
It collects the configuration wrappers from the given bases and namespace by extracting the configuration wrapper type from the original bases annotation if it is a generic subclass of the configurable class or metaclass, and from the configuration attribute if present in the class and bases namespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bases
|
tuple[type, ...]
|
The class bases. |
required |
namespace
|
dict[str, Any]
|
The class namespace. |
required |
Returns:
Type | Description |
---|---|
list[ConfigType]
|
A list of configuration wrapper classes found in the given bases |
list[ConfigType]
|
and namespace. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 |
|
BaseModel
BaseModel(**data: Any)
Bases: BaseModel
, Configurable[ModelConfig]
Base class for all Plateforme models.
It exposes the base class for all models within the Plateforme framework.
Attributes:
Name | Type | Description |
---|---|---|
__config__ |
ModelConfig | ConfigDict[ModelConfigDict]
|
The configuration class for the model. |
__pydantic_owner__ |
Literal['model', 'resource']
|
The owner of the model fields, either the model
itself or the resource it belongs to. Defaults to |
__pydantic_resource__ |
ResourceType | None
|
The resource that the model belongs to. |
__class_vars__ |
set[str]
|
The names of classvars defined on the model. |
__private_attributes__ |
dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__signature__ |
Signature
|
The signature for instantiating the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_validated__ |
bool
|
Whether the model has been validated or directly constructed. |
__pydantic_core_schema__ |
CoreSchema
|
The pydantic-core schema used to build the
|
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_generic_metadata__ |
PydanticGenericMetadata
|
Metadata for generic models, it contains
data used for a similar purpose to |
__pydantic_parent_namespace__ |
dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_discriminated_model__ |
bool
|
Whether the model is an
implementation of the |
__pydantic_root_model__ |
Whether the model is an implementation
of the |
|
__pydantic_adapter__ |
TypeAdapterList[BaseModel]
|
The pydantic |
__pydantic_serializer__ |
SchemaSerializer
|
The pydantic-core |
__pydantic_validator__ |
SchemaValidator
|
The pydantic-core |
__pydantic_extra__ |
dict[str, Any] | None
|
An instance attribute with the values of extra
fields from validation when |
__pydantic_fields_set__ |
set[str]
|
An instance attribute with the names of fields explicitly set. |
__pydantic_private__ |
dict[str, Any] | None
|
Instance attribute with the values of private attributes set on the model instance. |
Initialize a model instance.
It initializes a model instance by parsing and validating input data
from the data
keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**data
|
Any
|
The input data to initialize the model instance. |
{}
|
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
Note
The argument self
is explicitly positional-only to allow
self
as a field name and data keyword argument.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_extra
property
model_fields_set
property
model_dump_json
model_dump_json(
*,
indent: int | None = None,
include: IncEx = None,
exclude: IncEx = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
round_trip: bool = False,
warnings: bool = True,
) -> str
Usage docs: https://docs.pydantic.dev/2.6/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic's to_json
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
include
|
IncEx
|
Field(s) to include in the JSON output. |
None
|
exclude
|
IncEx
|
Field(s) to exclude from the JSON output. |
None
|
by_alias
|
bool
|
Whether to serialize using field aliases. |
False
|
exclude_unset
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
exclude_defaults
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
exclude_none
|
bool
|
Whether to exclude fields that have a value of |
False
|
round_trip
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
warnings
|
bool
|
Whether to log warnings when invalid fields are encountered. |
True
|
Returns:
Type | Description |
---|---|
str
|
A JSON string representation of the model. |
Source code in .venv/lib/python3.12/site-packages/pydantic/main.py
model_parametrized_name
classmethod
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
Type | Description |
---|---|
str
|
String representing the new class where |
Raises:
Type | Description |
---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in .venv/lib/python3.12/site-packages/pydantic/main.py
copy
copy(
*,
include: AbstractSetIntStr
| MappingIntStrAny
| None = None,
exclude: AbstractSetIntStr
| MappingIntStrAny
| None = None,
update: Dict[str, Any] | None = None,
deep: bool = False,
) -> Model
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy
instead.
If you need include
or exclude
, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
exclude
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
update
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
deep
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
Type | Description |
---|---|
Model
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in .venv/lib/python3.12/site-packages/pydantic/main.py
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 |
|
model_adapter
model_adapter() -> TypeAdapterList[BaseModel]
Get the model type adapter.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_construct
classmethod
Creates a new instance of the model class with validated data.
Creates a new model setting __dict__
and __pydantic_fields_set__
from trusted or pre-validated data. Default values are respected, but
no other validation is performed. It behaves as if
model_config.extra = 'allow'
was set since it adds all passed values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_fields_set
|
set[str] | None
|
The set of field names accepted by the model instance. |
None
|
**data
|
Any
|
Trusted or pre-validated input data to initialize the
model. It is used to set the |
{}
|
Returns:
Type | Description |
---|---|
Model
|
A new instance of the model class with validated data. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_copy
Returns a copy of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
update
|
dict[str, Any] | None
|
Values to add/modify within the new model. Note that if
assignment validation is not set to |
None
|
deep
|
bool
|
Set to |
False
|
Returns:
Type | Description |
---|---|
Model
|
A new copy of the model instance with the updated values. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_dump
model_dump(
*,
mode: Literal["json", "python", "raw"] | str = "python",
include: IncEx | None = None,
exclude: IncEx | None = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
round_trip: bool = False,
warnings: bool = True,
) -> dict[str, Any]
Generate a dictionary representation of the model.
It is used to dump the model instance to a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode
|
Literal['json', 'python', 'raw'] | str
|
The mode in which |
'python'
|
include
|
IncEx | None
|
A list of fields to include in the output.
Defaults to |
None
|
exclude
|
IncEx | None
|
A list of fields to exclude from the output.
Defaults to |
None
|
by_alias
|
bool
|
Whether to use the field's alias in the dictionary key if
defined. Defaults to |
False
|
exclude_unset
|
bool
|
Whether to exclude fields that have not been
explicitly set. Defaults to |
False
|
exclude_defaults
|
bool
|
Whether to exclude fields that are set to their
default value. Defaults to |
False
|
exclude_none
|
bool
|
Whether to exclude fields that have a value of
|
False
|
round_trip
|
bool
|
If |
False
|
warnings
|
bool
|
Whether to log warnings when invalid fields are
encountered. Defaults to |
True
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 |
|
model_json_schema
classmethod
model_json_schema(
by_alias: bool = True,
ref_template: str = DEFAULT_REF_TEMPLATE,
schema_generator: type[
GenerateJsonSchema
] = GenerateJsonSchema,
mode: JsonSchemaMode = "validation",
source: JsonSchemaSource = "model",
) -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
by_alias
|
bool
|
Whether to use field aliases when generating the schema,
i.e. if |
True
|
ref_template
|
str
|
The template format string used when generating
reference names. Defaults to |
DEFAULT_REF_TEMPLATE
|
schema_generator
|
type[GenerateJsonSchema]
|
The class to use for generating the JSON Schema. |
GenerateJsonSchema
|
mode
|
JsonSchemaMode
|
The mode to use for generating the JSON Schema. It can be
either |
'validation'
|
source
|
JsonSchemaSource
|
The source type to use for generating the resources JSON
schema. It can be either |
'model'
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
The generated JSON schema of the model class. |
Note
The schema generator class can be overridden to customize the
logic used to generate the JSON schema. This can be done by
subclassing the GenerateJsonSchema
class and passing the subclass
as the schema_generator
argument.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_post_init
model_post_init(__context: Any) -> None
Post-initialization method for the model class.
Override this method to perform additional initialization after the
__init__
and model_construct
methods have been called. This is
useful in scenarios where it is necessary to perform additional
initialization steps after the model has been fully initialized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__context
|
Any
|
The context object passed to the model instance. |
required |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_rebuild
classmethod
model_rebuild(
*,
force: bool = False,
raise_errors: bool = True,
_parent_namespace_depth: int = 2,
_types_namespace: dict[str, Any] | None = None,
) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef
which could not be resolved during the initial attempt to build the
schema, and automatic rebuilding fails.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
Whether to force the rebuilding of the model schema.
Defaults to |
False
|
raise_errors
|
bool
|
Whether to raise errors or fail silently.
Defaults to |
True
|
_parent_namespace_depth
|
int
|
The depth level of the parent namespace. Defaults to 2. |
2
|
_types_namespace
|
dict[str, Any] | None
|
The types namespace. Defaults to |
None
|
Raises:
Type | Description |
---|---|
PlateformeError
|
If an error occurred while rebuilding the model
adapter and |
PydanticUndefinedAnnotation
|
If |
Returns:
Type | Description |
---|---|
bool | None
|
Returns |
bool | None
|
was not required. If rebuilding was required, returns |
bool | None
|
rebuilding was successful, otherwise |
bool | None
|
occurred and |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 |
|
model_revalidate
model_revalidate(
*,
force: bool = False,
raise_errors: bool = True,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> bool | None
Revalidate the model instance.
It revalidates the model instance in place, enforcing the types
strictly if specified. If the model instance has already been
validated, it will not be revalidated unless the force
argument is
set to True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
Whether to force the revalidation of the model instance.
Defaults to |
False
|
raise_errors
|
bool
|
Whether to raise errors or fail silently.
Defaults to |
True
|
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Raises:
Type | Description |
---|---|
ValidationError
|
If the model instance could not be validated and
|
Returns:
Type | Description |
---|---|
bool | None
|
Returns |
bool | None
|
revalidation was not required. If validation was required, returns |
bool | None
|
|
bool | None
|
error occurred and |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_update
model_update(
obj: Any,
*,
update: dict[str, Any] | None = None,
from_attributes: bool | None = None,
) -> None
Update the model with the given object and update dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to update the model with. It can be a dictionary
or an object with attributes (if |
required |
update
|
dict[str, Any] | None
|
Values to add/modify within the model. Note that if
assignment validation is not set to |
None
|
from_attributes
|
bool | None
|
Whether to extract data from object attributes.
Defaults to |
None
|
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate
classmethod
model_validate(
obj: Any,
*,
strict: bool | None = None,
from_attributes: bool | None = None,
context: dict[str, Any] | None = None,
) -> Model
Validate the given object against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
from_attributes
|
bool | None
|
Whether to extract data from the object attributes. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Model
|
A validated model instance. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_many
classmethod
model_validate_many(
obj: Any,
*,
strict: bool | None = None,
from_attributes: bool | None = None,
context: dict[str, Any] | None = None,
) -> Sequence[Model]
Validate the given object collection against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object collection to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
from_attributes
|
bool | None
|
Whether to extract data from the object collection items attributes. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Sequence[Model]
|
A validated collection of model instances. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object collection could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_json
classmethod
model_validate_json(
json_data: str | bytes | bytearray,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Model
Validate the given JSON data against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_data
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Model
|
A validated model instance. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValidationError
|
If the object could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_json_many
classmethod
model_validate_json_many(
json_data: str | bytes | bytearray,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Sequence[Model]
Validate the given JSON data collection against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_data
|
str | bytes | bytearray
|
The JSON data collection to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Sequence[Model]
|
A validated collection of model instances. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValidationError
|
If the object collection could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_strings
classmethod
model_validate_strings(
obj: Any,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Model
Validate the given string object against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The string object to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Model
|
A validated model instance. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_strings_many
classmethod
model_validate_strings_many(
obj: Any,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Sequence[Model]
Validate the given string object collection against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The string object collection to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Sequence[Model]
|
A validated collection of model instances. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object collection could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
RootModelMeta
RootModelMeta(
name: str,
bases: tuple[type, ...],
namespace: dict[str, Any],
/,
*args: Any,
**kwargs: Any,
)
Bases: ModelMeta
A metaclass for root model classes.
Initialize a new model meta class.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
collect_config_wrappers
Collect configuration wrappers from the given bases and namespace.
It collects the configuration wrappers from the given bases and namespace by extracting the configuration wrapper type from the original bases annotation if it is a generic subclass of the configurable class or metaclass, and from the configuration attribute if present in the class and bases namespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bases
|
tuple[type, ...]
|
The class bases. |
required |
namespace
|
dict[str, Any]
|
The class namespace. |
required |
Returns:
Type | Description |
---|---|
list[ConfigType]
|
A list of configuration wrapper classes found in the given bases |
list[ConfigType]
|
and namespace. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 |
|
RootModel
RootModel(root: _TRoot = Undefined, **data: Any)
Bases: BaseModel
, Generic[_TRoot]
A root model class.
A model used to store a single root object.
a specialized model class used to define and validate a single root object. It's particularly useful for scenarios involving a top-level data structure that doesn't fit neatly into a typical dictionary or list format. The roo model ensures type safety and data validation for this singular, primary object, and allows dynamic type updates without losing references within other models.
Attributes:
Name | Type | Description |
---|---|---|
root |
_TRoot
|
The root object of the model. |
Initialize a root model instance.
It initializes a model instance by parsing and validating input data
from the root
argument or data
keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
_TRoot
|
The root object of the model. |
Undefined
|
**data
|
Any
|
The input data to initialize the model instance. |
{}
|
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
Note
The argument self
is explicitly positional-only to allow
self
as a field name and data keyword argument.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_extra
property
model_fields_set
property
model_copy
Returns a copy of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
update
|
dict[str, Any] | None
|
Values to add/modify within the new model. Note that if
assignment validation is not set to |
None
|
deep
|
bool
|
Set to |
False
|
Returns:
Type | Description |
---|---|
Model
|
A new copy of the model instance with the updated values. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_dump_json
model_dump_json(
*,
indent: int | None = None,
include: IncEx = None,
exclude: IncEx = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
round_trip: bool = False,
warnings: bool = True,
) -> str
Usage docs: https://docs.pydantic.dev/2.6/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic's to_json
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
include
|
IncEx
|
Field(s) to include in the JSON output. |
None
|
exclude
|
IncEx
|
Field(s) to exclude from the JSON output. |
None
|
by_alias
|
bool
|
Whether to serialize using field aliases. |
False
|
exclude_unset
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
exclude_defaults
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
exclude_none
|
bool
|
Whether to exclude fields that have a value of |
False
|
round_trip
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
warnings
|
bool
|
Whether to log warnings when invalid fields are encountered. |
True
|
Returns:
Type | Description |
---|---|
str
|
A JSON string representation of the model. |
Source code in .venv/lib/python3.12/site-packages/pydantic/main.py
model_json_schema
classmethod
model_json_schema(
by_alias: bool = True,
ref_template: str = DEFAULT_REF_TEMPLATE,
schema_generator: type[
GenerateJsonSchema
] = GenerateJsonSchema,
mode: JsonSchemaMode = "validation",
source: JsonSchemaSource = "model",
) -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
by_alias
|
bool
|
Whether to use field aliases when generating the schema,
i.e. if |
True
|
ref_template
|
str
|
The template format string used when generating
reference names. Defaults to |
DEFAULT_REF_TEMPLATE
|
schema_generator
|
type[GenerateJsonSchema]
|
The class to use for generating the JSON Schema. |
GenerateJsonSchema
|
mode
|
JsonSchemaMode
|
The mode to use for generating the JSON Schema. It can be
either |
'validation'
|
source
|
JsonSchemaSource
|
The source type to use for generating the resources JSON
schema. It can be either |
'model'
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
The generated JSON schema of the model class. |
Note
The schema generator class can be overridden to customize the
logic used to generate the JSON schema. This can be done by
subclassing the GenerateJsonSchema
class and passing the subclass
as the schema_generator
argument.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_parametrized_name
classmethod
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
Type | Description |
---|---|
str
|
String representing the new class where |
Raises:
Type | Description |
---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in .venv/lib/python3.12/site-packages/pydantic/main.py
model_post_init
model_post_init(__context: Any) -> None
Post-initialization method for the model class.
Override this method to perform additional initialization after the
__init__
and model_construct
methods have been called. This is
useful in scenarios where it is necessary to perform additional
initialization steps after the model has been fully initialized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__context
|
Any
|
The context object passed to the model instance. |
required |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_rebuild
classmethod
model_rebuild(
*,
force: bool = False,
raise_errors: bool = True,
_parent_namespace_depth: int = 2,
_types_namespace: dict[str, Any] | None = None,
) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef
which could not be resolved during the initial attempt to build the
schema, and automatic rebuilding fails.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
Whether to force the rebuilding of the model schema.
Defaults to |
False
|
raise_errors
|
bool
|
Whether to raise errors or fail silently.
Defaults to |
True
|
_parent_namespace_depth
|
int
|
The depth level of the parent namespace. Defaults to 2. |
2
|
_types_namespace
|
dict[str, Any] | None
|
The types namespace. Defaults to |
None
|
Raises:
Type | Description |
---|---|
PlateformeError
|
If an error occurred while rebuilding the model
adapter and |
PydanticUndefinedAnnotation
|
If |
Returns:
Type | Description |
---|---|
bool | None
|
Returns |
bool | None
|
was not required. If rebuilding was required, returns |
bool | None
|
rebuilding was successful, otherwise |
bool | None
|
occurred and |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 |
|
model_validate
classmethod
model_validate(
obj: Any,
*,
strict: bool | None = None,
from_attributes: bool | None = None,
context: dict[str, Any] | None = None,
) -> Model
Validate the given object against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
from_attributes
|
bool | None
|
Whether to extract data from the object attributes. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Model
|
A validated model instance. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_json
classmethod
model_validate_json(
json_data: str | bytes | bytearray,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Model
Validate the given JSON data against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_data
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Model
|
A validated model instance. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValidationError
|
If the object could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_strings
classmethod
model_validate_strings(
obj: Any,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Model
Validate the given string object against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The string object to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Model
|
A validated model instance. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
copy
copy(
*,
include: AbstractSetIntStr
| MappingIntStrAny
| None = None,
exclude: AbstractSetIntStr
| MappingIntStrAny
| None = None,
update: Dict[str, Any] | None = None,
deep: bool = False,
) -> Model
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy
instead.
If you need include
or exclude
, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
exclude
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
update
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
deep
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
Type | Description |
---|---|
Model
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in .venv/lib/python3.12/site-packages/pydantic/main.py
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 |
|
model_adapter
model_adapter() -> TypeAdapterList[BaseModel]
Get the model type adapter.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_revalidate
model_revalidate(
*,
force: bool = False,
raise_errors: bool = True,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> bool | None
Revalidate the model instance.
It revalidates the model instance in place, enforcing the types
strictly if specified. If the model instance has already been
validated, it will not be revalidated unless the force
argument is
set to True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
Whether to force the revalidation of the model instance.
Defaults to |
False
|
raise_errors
|
bool
|
Whether to raise errors or fail silently.
Defaults to |
True
|
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Raises:
Type | Description |
---|---|
ValidationError
|
If the model instance could not be validated and
|
Returns:
Type | Description |
---|---|
bool | None
|
Returns |
bool | None
|
revalidation was not required. If validation was required, returns |
bool | None
|
|
bool | None
|
error occurred and |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_update
model_update(
obj: Any,
*,
update: dict[str, Any] | None = None,
from_attributes: bool | None = None,
) -> None
Update the model with the given object and update dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to update the model with. It can be a dictionary
or an object with attributes (if |
required |
update
|
dict[str, Any] | None
|
Values to add/modify within the model. Note that if
assignment validation is not set to |
None
|
from_attributes
|
bool | None
|
Whether to extract data from object attributes.
Defaults to |
None
|
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_many
classmethod
model_validate_many(
obj: Any,
*,
strict: bool | None = None,
from_attributes: bool | None = None,
context: dict[str, Any] | None = None,
) -> Sequence[Model]
Validate the given object collection against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object collection to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
from_attributes
|
bool | None
|
Whether to extract data from the object collection items attributes. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Sequence[Model]
|
A validated collection of model instances. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object collection could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_json_many
classmethod
model_validate_json_many(
json_data: str | bytes | bytearray,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Sequence[Model]
Validate the given JSON data collection against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_data
|
str | bytes | bytearray
|
The JSON data collection to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Sequence[Model]
|
A validated collection of model instances. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValidationError
|
If the object collection could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_strings_many
classmethod
model_validate_strings_many(
obj: Any,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Sequence[Model]
Validate the given string object collection against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The string object collection to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Sequence[Model]
|
A validated collection of model instances. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object collection could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_construct
classmethod
Create a new model using the provided root object and update fields set with the given set of fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
_TRoot
|
The root object of the model. |
required |
_fields_set
|
set[str] | None
|
The set of fields to be updated. |
None
|
Returns:
Type | Description |
---|---|
Self
|
The new model. |
Raises:
Type | Description |
---|---|
NotImplemented
|
If the model is not a subclass of |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_dump
model_dump(
*,
mode: Literal["json", "python", "raw"] | str = "python",
include: Any | None = None,
exclude: Any | None = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
round_trip: bool = False,
warnings: bool = True,
) -> Any
This method is included just to get a more accurate return type
for type checkers. It is included in this if TYPE_CHECKING:
block
since no override is actually necessary.
See the documentation of base model model_dump
for more details
about the arguments.
Generally, this method will have a return type of _TRoot
,
assuming that _TRoot
is not a BaseModel
subclass. If _TRoot
is a BaseModel
subclass, then the return type will likely be
dict[str, Any]
, as model_dump
calls are recursive. The return
type could even be something different, in the case of a custom
serializer. Thus, Any
is used here to catch all of these cases.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
DiscriminatedModelMeta
DiscriminatedModelMeta(
name: str,
bases: tuple[type, ...],
namespace: dict[str, Any],
/,
*args: Any,
**kwargs: Any,
)
Bases: RootModelMeta
A metaclass for discriminated model classes.
Initialize a new discriminated model meta class.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
collect_config_wrappers
Collect configuration wrappers from the given bases and namespace.
It collects the configuration wrappers from the given bases and namespace by extracting the configuration wrapper type from the original bases annotation if it is a generic subclass of the configurable class or metaclass, and from the configuration attribute if present in the class and bases namespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bases
|
tuple[type, ...]
|
The class bases. |
required |
namespace
|
dict[str, Any]
|
The class namespace. |
required |
Returns:
Type | Description |
---|---|
list[ConfigType]
|
A list of configuration wrapper classes found in the given bases |
list[ConfigType]
|
and namespace. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/config.py
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 |
|
collect_typevar_values
collect_typevar_values(
bases: tuple[type, ...], namespace: dict[str, Any]
) -> tuple[type[Any], ...] | None
Collect the root typevar values.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
get_root_members
Get the base and variant classes of the discriminated model.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
get_root_base
get_root_base() -> ModelType
Get the base class of the discriminated model.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
get_root_variants
Get the variant classes of the discriminated model.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
update_root_members
update_root_members(
*,
base: type[Any] | None = None,
variants: Sequence[type[Any]] | None = None,
) -> tuple[ModelType, ...]
Update the discriminator with the given models.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
update_root_metadata
Update root type metadata.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
validate_root
Validate the root type annotation of the discriminated model.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
DiscriminatedModel
DiscriminatedModel(root: _TRoot = Undefined, **data: Any)
Bases: RootModel[_TBase]
, Generic[_TBase, *_TSubs]
A discriminated model class.
Initialize a root model instance.
It initializes a model instance by parsing and validating input data
from the root
argument or data
keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
_TRoot
|
The root object of the model. |
Undefined
|
**data
|
Any
|
The input data to initialize the model instance. |
{}
|
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
Note
The argument self
is explicitly positional-only to allow
self
as a field name and data keyword argument.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_extra
property
model_fields_set
property
model_construct
classmethod
Create a new model using the provided root object and update fields set with the given set of fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
_TRoot
|
The root object of the model. |
required |
_fields_set
|
set[str] | None
|
The set of fields to be updated. |
None
|
Returns:
Type | Description |
---|---|
Self
|
The new model. |
Raises:
Type | Description |
---|---|
NotImplemented
|
If the model is not a subclass of |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_copy
Returns a copy of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
update
|
dict[str, Any] | None
|
Values to add/modify within the new model. Note that if
assignment validation is not set to |
None
|
deep
|
bool
|
Set to |
False
|
Returns:
Type | Description |
---|---|
Model
|
A new copy of the model instance with the updated values. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_dump
model_dump(
*,
mode: Literal["json", "python", "raw"] | str = "python",
include: Any | None = None,
exclude: Any | None = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
round_trip: bool = False,
warnings: bool = True,
) -> Any
This method is included just to get a more accurate return type
for type checkers. It is included in this if TYPE_CHECKING:
block
since no override is actually necessary.
See the documentation of base model model_dump
for more details
about the arguments.
Generally, this method will have a return type of _TRoot
,
assuming that _TRoot
is not a BaseModel
subclass. If _TRoot
is a BaseModel
subclass, then the return type will likely be
dict[str, Any]
, as model_dump
calls are recursive. The return
type could even be something different, in the case of a custom
serializer. Thus, Any
is used here to catch all of these cases.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_dump_json
model_dump_json(
*,
indent: int | None = None,
include: IncEx = None,
exclude: IncEx = None,
by_alias: bool = False,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
round_trip: bool = False,
warnings: bool = True,
) -> str
Usage docs: https://docs.pydantic.dev/2.6/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic's to_json
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
include
|
IncEx
|
Field(s) to include in the JSON output. |
None
|
exclude
|
IncEx
|
Field(s) to exclude from the JSON output. |
None
|
by_alias
|
bool
|
Whether to serialize using field aliases. |
False
|
exclude_unset
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
exclude_defaults
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
exclude_none
|
bool
|
Whether to exclude fields that have a value of |
False
|
round_trip
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
warnings
|
bool
|
Whether to log warnings when invalid fields are encountered. |
True
|
Returns:
Type | Description |
---|---|
str
|
A JSON string representation of the model. |
Source code in .venv/lib/python3.12/site-packages/pydantic/main.py
model_json_schema
classmethod
model_json_schema(
by_alias: bool = True,
ref_template: str = DEFAULT_REF_TEMPLATE,
schema_generator: type[
GenerateJsonSchema
] = GenerateJsonSchema,
mode: JsonSchemaMode = "validation",
source: JsonSchemaSource = "model",
) -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
by_alias
|
bool
|
Whether to use field aliases when generating the schema,
i.e. if |
True
|
ref_template
|
str
|
The template format string used when generating
reference names. Defaults to |
DEFAULT_REF_TEMPLATE
|
schema_generator
|
type[GenerateJsonSchema]
|
The class to use for generating the JSON Schema. |
GenerateJsonSchema
|
mode
|
JsonSchemaMode
|
The mode to use for generating the JSON Schema. It can be
either |
'validation'
|
source
|
JsonSchemaSource
|
The source type to use for generating the resources JSON
schema. It can be either |
'model'
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
The generated JSON schema of the model class. |
Note
The schema generator class can be overridden to customize the
logic used to generate the JSON schema. This can be done by
subclassing the GenerateJsonSchema
class and passing the subclass
as the schema_generator
argument.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_parametrized_name
classmethod
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
Type | Description |
---|---|
str
|
String representing the new class where |
Raises:
Type | Description |
---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in .venv/lib/python3.12/site-packages/pydantic/main.py
model_post_init
model_post_init(__context: Any) -> None
Post-initialization method for the model class.
Override this method to perform additional initialization after the
__init__
and model_construct
methods have been called. This is
useful in scenarios where it is necessary to perform additional
initialization steps after the model has been fully initialized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__context
|
Any
|
The context object passed to the model instance. |
required |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_rebuild
classmethod
model_rebuild(
*,
force: bool = False,
raise_errors: bool = True,
_parent_namespace_depth: int = 2,
_types_namespace: dict[str, Any] | None = None,
) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef
which could not be resolved during the initial attempt to build the
schema, and automatic rebuilding fails.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
Whether to force the rebuilding of the model schema.
Defaults to |
False
|
raise_errors
|
bool
|
Whether to raise errors or fail silently.
Defaults to |
True
|
_parent_namespace_depth
|
int
|
The depth level of the parent namespace. Defaults to 2. |
2
|
_types_namespace
|
dict[str, Any] | None
|
The types namespace. Defaults to |
None
|
Raises:
Type | Description |
---|---|
PlateformeError
|
If an error occurred while rebuilding the model
adapter and |
PydanticUndefinedAnnotation
|
If |
Returns:
Type | Description |
---|---|
bool | None
|
Returns |
bool | None
|
was not required. If rebuilding was required, returns |
bool | None
|
rebuilding was successful, otherwise |
bool | None
|
occurred and |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 |
|
model_validate
classmethod
model_validate(
obj: Any,
*,
strict: bool | None = None,
from_attributes: bool | None = None,
context: dict[str, Any] | None = None,
) -> Model
Validate the given object against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
from_attributes
|
bool | None
|
Whether to extract data from the object attributes. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Model
|
A validated model instance. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_json
classmethod
model_validate_json(
json_data: str | bytes | bytearray,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Model
Validate the given JSON data against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_data
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Model
|
A validated model instance. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValidationError
|
If the object could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_strings
classmethod
model_validate_strings(
obj: Any,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Model
Validate the given string object against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The string object to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Model
|
A validated model instance. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
copy
copy(
*,
include: AbstractSetIntStr
| MappingIntStrAny
| None = None,
exclude: AbstractSetIntStr
| MappingIntStrAny
| None = None,
update: Dict[str, Any] | None = None,
deep: bool = False,
) -> Model
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy
instead.
If you need include
or exclude
, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
exclude
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
update
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
deep
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
Type | Description |
---|---|
Model
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in .venv/lib/python3.12/site-packages/pydantic/main.py
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 |
|
model_adapter
model_adapter() -> TypeAdapterList[BaseModel]
Get the model type adapter.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_revalidate
model_revalidate(
*,
force: bool = False,
raise_errors: bool = True,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> bool | None
Revalidate the model instance.
It revalidates the model instance in place, enforcing the types
strictly if specified. If the model instance has already been
validated, it will not be revalidated unless the force
argument is
set to True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
Whether to force the revalidation of the model instance.
Defaults to |
False
|
raise_errors
|
bool
|
Whether to raise errors or fail silently.
Defaults to |
True
|
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Raises:
Type | Description |
---|---|
ValidationError
|
If the model instance could not be validated and
|
Returns:
Type | Description |
---|---|
bool | None
|
Returns |
bool | None
|
revalidation was not required. If validation was required, returns |
bool | None
|
|
bool | None
|
error occurred and |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_update
model_update(
obj: Any,
*,
update: dict[str, Any] | None = None,
from_attributes: bool | None = None,
) -> None
Update the model with the given object and update dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object to update the model with. It can be a dictionary
or an object with attributes (if |
required |
update
|
dict[str, Any] | None
|
Values to add/modify within the model. Note that if
assignment validation is not set to |
None
|
from_attributes
|
bool | None
|
Whether to extract data from object attributes.
Defaults to |
None
|
Raises:
Type | Description |
---|---|
ValidationError
|
If the object could not be validated. |
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_many
classmethod
model_validate_many(
obj: Any,
*,
strict: bool | None = None,
from_attributes: bool | None = None,
context: dict[str, Any] | None = None,
) -> Sequence[Model]
Validate the given object collection against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object collection to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
from_attributes
|
bool | None
|
Whether to extract data from the object collection items attributes. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Sequence[Model]
|
A validated collection of model instances. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object collection could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_json_many
classmethod
model_validate_json_many(
json_data: str | bytes | bytearray,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Sequence[Model]
Validate the given JSON data collection against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_data
|
str | bytes | bytearray
|
The JSON data collection to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Sequence[Model]
|
A validated collection of model instances. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValidationError
|
If the object collection could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
model_validate_strings_many
classmethod
model_validate_strings_many(
obj: Any,
*,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> Sequence[Model]
Validate the given string object collection against the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The string object collection to validate. |
required |
strict
|
bool | None
|
Whether to enforce types strictly. |
None
|
context
|
dict[str, Any] | None
|
Extra variables to pass to the validator. |
None
|
Returns:
Type | Description |
---|---|
Sequence[Model]
|
A validated collection of model instances. |
Raises:
Type | Description |
---|---|
ValidationError
|
If the object collection could not be validated. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
ModelFieldLookup
Bases: TypedDict
A model field lookup configuration.
include
instance-attribute
include: dict[str, IncExPredicate] | None
The filters for including specific fields as a dictionary with the field
attribute names as keys and the values to match. Specified keys can use
the .
notation to access nested attributes. Additionally, the lookup
attributes can be callables without arguments. Defaults to None
.
exclude
instance-attribute
exclude: dict[str, IncExPredicate] | None
The filters for excluding specific fields as a dictionary with the field
attribute names as keys and the values to not match. Specified keys can use
the .
notation to access nested attributes. Additionally, the lookup
attributes can be callable without arguments. Defaults to None
.
partial
instance-attribute
partial: bool | None
Whether to mark the field annotations as optional.
Defaults to None
.
default
instance-attribute
The default to apply and set within the field information.
Defaults to None
.
update
instance-attribute
The update to apply and set within the field information.
Defaults to None
.
override
instance-attribute
override: ModelFieldLookup | None
The field lookup configuration to override the current configuration.
This can be used to narrow down the field lookup configuration to specific
fields. Multiple levels of nested configurations can be provided and will
be resolved recursively. Defaults to None
.
NoInitField
Only for typing purposes. Used as default value of the attribute
__pydantic_fields_set__
, __pydantic_extra__
, __pydantic_private__
, so
they could be ignored when synthesizing the __init__
signature.
See Pydantic base model metaclass signature for more information.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
create_model
create_model(
__model_name: str,
*,
__config__: ModelConfig | None = None,
__doc__: str | None = None,
__base__: None = None,
__module__: str = __name__,
__validators__: dict[str, ClassMethodType]
| None = None,
__cls_kwargs__: dict[str, Any] | None = None,
**field_definitions: tuple[
type[Any], Any | ModelFieldInfo
],
) -> ModelType
create_model(
__model_name: str,
*,
__config__: ModelConfig | None = None,
__doc__: str | None = None,
__base__: type[Model] | tuple[type[Model], ...],
__module__: str = __name__,
__validators__: dict[str, ClassMethodType]
| None = None,
__cls_kwargs__: dict[str, Any] | None = None,
**field_definitions: tuple[
type[Any], Any | ModelFieldInfo
],
) -> type[Model]
create_model(
__model_name: str,
*,
__config__: ModelConfig | None = None,
__doc__: str | None = None,
__base__: type[Model]
| tuple[type[Model], ...]
| None = None,
__module__: str | None = None,
__validators__: dict[str, ClassMethodType]
| None = None,
__cls_kwargs__: dict[str, Any] | None = None,
**field_definitions: tuple[
type[Any], Any | ModelFieldInfo
],
) -> type[Model]
Dynamically creates and returns a new model class.
It is used to dynamically create a subclass of the BaseModel
class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__model_name
|
str
|
The name of the newly created model. |
required |
__config__
|
ModelConfig | None
|
The configuration of the new model. |
None
|
__doc__
|
str | None
|
The docstring of the new model. |
None
|
__base__
|
type[Model] | tuple[type[Model], ...] | None
|
The base class or classes for the new model. |
None
|
__module__
|
str | None
|
The name of the module that the model belongs to.
If |
None
|
__validators__
|
dict[str, ClassMethodType] | None
|
A dictionary of class methods that validate fields. |
None
|
__cls_kwargs__
|
dict[str, Any] | None
|
A dictionary of keyword arguments for class creation,
such as |
None
|
**field_definitions
|
tuple[type[Any], Any | ModelFieldInfo]
|
Attributes of the new model. They should be passed
in the format: |
{}
|
Returns:
Type | Description |
---|---|
type[Model]
|
The new |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 |
|
create_root_model
create_root_model(
__model_name: str,
*,
__config__: ModelConfig | None = None,
__doc__: str | None = None,
__module__: str | None = None,
__validators__: dict[str, ClassMethodType]
| None = None,
__cls_kwargs__: dict[str, Any] | None = None,
root: tuple[type[_TRoot], Any | ModelFieldInfo],
) -> type[RootModel[_TRoot]]
Dynamically creates and returns a new model class.
It is used to dynamically create a subclass of the BaseModel
class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__model_name
|
str
|
The name of the newly created model. |
required |
__config__
|
ModelConfig | None
|
The configuration of the new model. |
None
|
__doc__
|
str | None
|
The docstring of the new model. |
None
|
__module__
|
str | None
|
The name of the module that the model belongs to.
If |
None
|
__validators__
|
dict[str, ClassMethodType] | None
|
A dictionary of class methods that validate fields. |
None
|
__cls_kwargs__
|
dict[str, Any] | None
|
A dictionary of keyword arguments for class creation,
such as |
None
|
root
|
tuple[type[_TRoot], Any | ModelFieldInfo]
|
Root attributes of the new model. It should be passed in
the format: |
required |
Returns:
Type | Description |
---|---|
type[RootModel[_TRoot]]
|
The new |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
create_discriminated_model
create_discriminated_model(
__model_name: str,
*,
__owner__: object | int | None = None,
__config__: ModelConfig | None = None,
__doc__: str | None = None,
__module__: str | None = None,
__validators__: dict[str, ClassMethodType]
| None = None,
__cls_kwargs__: dict[str, Any] | None = None,
discriminator: str | Discriminator | None = None,
root: tuple[type[_TBase], Any | ModelFieldInfo],
) -> type[DiscriminatedModel[_TBase]]
create_discriminated_model(
__model_name: str,
*,
__owner__: object | int | None = None,
__config__: ModelConfig | None = None,
__doc__: str | None = None,
__module__: str | None = None,
__validators__: dict[str, ClassMethodType]
| None = None,
__cls_kwargs__: dict[str, Any] | None = None,
discriminator: str | Discriminator | None = None,
root: tuple[
tuple[type[_TBase], ...], Any | ModelFieldInfo
],
) -> type[DiscriminatedModel[*tuple[_TBase, ...],]]
create_discriminated_model(
__model_name: str,
*,
__owner__: object | int | None = None,
__config__: ModelConfig | None = None,
__doc__: str | None = None,
__module__: str | None = None,
__validators__: dict[str, ClassMethodType]
| None = None,
__cls_kwargs__: dict[str, Any] | None = None,
discriminator: str | Discriminator | None = None,
root: tuple[
type[_TBase] | tuple[type[_TBase], ...],
Any | ModelFieldInfo,
],
) -> type[DiscriminatedModel[*tuple[_TBase, ...],]]
Dynamically creates and returns a new model class.
It is used to dynamically create a subclass of the BaseModel
class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__model_name
|
str
|
The name of the newly created model. |
required |
__owner__
|
object | int | None
|
The owner object or identifier to use as the registrant of
the new model. If an object is provided, the object's identifier
is used. If an integer is provided, the integer is used.
Defaults to |
None
|
__config__
|
ModelConfig | None
|
The configuration of the new model. |
None
|
__doc__
|
str | None
|
The docstring of the new model. |
None
|
__module__
|
str | None
|
The name of the module that the model belongs to.
If |
None
|
__validators__
|
dict[str, ClassMethodType] | None
|
A dictionary of class methods that validate fields. |
None
|
__cls_kwargs__
|
dict[str, Any] | None
|
A dictionary of keyword arguments for class creation,
such as |
None
|
discriminator
|
str | Discriminator | None
|
The discriminator either as a string or an object use for the validation of the discriminated root type. |
None
|
root
|
tuple[type[_TBase] | tuple[type[_TBase], ...], Any | ModelFieldInfo]
|
Root attributes of the new model. It should be passed in
the format: |
required |
Returns:
Type | Description |
---|---|
type[DiscriminatedModel[*tuple[_TBase, ...],]]
|
The new |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 |
|
collect_fields
collect_fields(
__model: ModelType, **kwargs: Unpack[ModelFieldLookup]
) -> dict[str, tuple[type, ModelFieldInfo]]
Collect the model field definitions from the provided model.
It collects the model fields based on the provided model and keyword
arguments lookup configuration to include or exclude specific fields. The
collected fields annotations are updated with the provided partial
flag,
and the field information is updated with the provided default
and
update
values. The field lookup configuration can be overridden to narrow
down the field lookup configuration to specific fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__model
|
ModelType
|
The model class to collect the fields from. |
required |
**kwargs
|
Unpack[ModelFieldLookup]
|
The field lookup configuration to collect the fields.
- |
{}
|
Returns:
Type | Description |
---|---|
dict[str, tuple[type, ModelFieldInfo]]
|
A dictionary of field names with the corresponding field annotations |
dict[str, tuple[type, ModelFieldInfo]]
|
and field information. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 |
|
collect_models
collect_models(
__obj: Any,
*,
__config__: ModelConfig | None = None,
__base__: ModelType
| tuple[ModelType, ...]
| None = None,
__module__: str | None = None,
__validators__: dict[str, ClassMethodType]
| None = None,
__cls_kwargs__: dict[str, Any] | None = None,
__namespace__: str | None = None,
) -> list[ModelType]
Collect and build recursively all nested models in a given object.
It recursively collect all nested classes in a given object and build the
associated models. The __namespace__
argument is used recursively to
determine the root namespace under which the models are collected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__obj
|
Any
|
The object to inspect for nested classes. |
required |
__config__
|
ModelConfig | None
|
The configuration of the new models. |
None
|
__base__
|
ModelType | tuple[ModelType, ...] | None
|
The base class or classes for the new models. |
None
|
__module__
|
str | None
|
The name of the module that the models belongs to.
If |
None
|
__validators__
|
dict[str, ClassMethodType] | None
|
A dictionary of class methods that validate fields. |
None
|
__cls_kwargs__
|
dict[str, Any] | None
|
A dictionary of keyword arguments for class creation,
such as |
None
|
__namespace__
|
str | None
|
The namespace of the object to collect models from. |
None
|
Returns:
Type | Description |
---|---|
list[ModelType]
|
A dictionary with the generated |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/schema/models.py
2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 |
|