Skip to content

pydantic

CythonFunctionDetector

Cython function detector for solution to pydantic/cython issue: https://github.com/pydantic/pydantic/issues/6670#issuecomment-1644799636

HashableBaseModelIO

Bases: BaseModel

Input/output utilities for the models with support for the following features:

  • Hashing of the model
  • Conversion to and from dictionaries, json, toml, and yaml files
  • Compatibility with pydantic v1 and v2

exclude property

exclude: set[int] | set[str] | dict[int, Any] | dict[str, Any] | None

Fields to exclude from the model, typically used to exclude arbitrary types when it is allowed in the pydantic model to avoid hashing issues.

toDict class-attribute instance-attribute

toDict = model_dump

__hash__

__hash__() -> int

Return the hash of the model.

create classmethod

create(**kwargs) -> Self

dataFromAny classmethod

dataFromAny(
    *,
    data: dict | None = None,
    text: str | bytes | None = None,
    path: str | PathLike | None = None,
    key: str = ""
) -> dict

Load the data from a dictionary, json, toml, yaml, or binary string, or file if a path is provided.

dataFromBytes classmethod

dataFromBytes(
    binary_or_path: bytes | str | PathLike | None = None,
    path: str | PathLike | None = None,
    *,
    key: str = ""
) -> dict

Load the data from a binary string or file if a path is provided.

dataFromDict classmethod

dataFromDict(data: dict, key: str = '') -> dict

Load the data from a dictionary.

dataFromJson classmethod

dataFromJson(
    string_or_path: str | PathLike | None = None,
    path: str | PathLike | None = None,
    *,
    key: str = ""
) -> dict

Load the data from a json string or file if a path is provided.

dataFromToml classmethod

dataFromToml(
    string_or_path: str | PathLike | None = None,
    path: str | PathLike | None = None,
    *,
    key: str = ""
) -> dict

Load the data from a toml string or file if a path is provided.

dataFromYaml classmethod

dataFromYaml(
    string_or_path: str | PathLike | None = None,
    path: str | PathLike | None = None,
    *,
    key: str = ""
) -> dict

Load the data from a yaml string or file if a path is provided.

format

format(*, copy: bool = True, rebuild: bool = False, **specs)

Format the model with the given specifications.

PARAMETER DESCRIPTION
copy

Whether to copy the current model.

TYPE: bool DEFAULT: True

rebuild

Whether to rebuild the model. If true, the model will be rebuilt with the formatted data which is a copy of the model.

TYPE: bool DEFAULT: False

specs

The specifications for the formatting.

TYPE: dict DEFAULT: {}

fromAny classmethod

fromAny(
    *,
    data: dict | None = None,
    text: str | bytes | None = None,
    path: str | PathLike | None = None,
    key: str = "",
    **kwargs
) -> Self

Load the model from a dictionary, json, toml, yaml, or binary string, or file if a path is provided.

fromBytes classmethod

fromBytes(
    binary_or_path: bytes | str | PathLike | None = None,
    path: str | PathLike | None = None,
    *,
    key: str = "",
    **kwargs
) -> Self

Load the model from a binary string or file if a path is provided.

fromDict classmethod

fromDict(data: dict, *, key: str = '', **kwargs) -> Self

Load the model from a dictionary.

fromJson classmethod

fromJson(
    string_or_path: str | PathLike | None = None,
    path: str | PathLike | None = None,
    *,
    key: str = "",
    **kwargs
)

Load the model from a json string or file if a path is provided.

fromToml classmethod

fromToml(
    string_or_path: str | PathLike | None = None,
    path: str | PathLike | None = None,
    *,
    key: str = "",
    **kwargs
)

Load the model from a toml string or file if a path is provided.

fromYaml classmethod

fromYaml(
    string_or_path: str | PathLike | None = None,
    path: str | PathLike | None = None,
    *,
    key: str = "",
    **kwargs
)

Load the model from a yaml string or file if a path is provided.

get_

get_(key: str, default: Any = None) -> Any

Get the value of a property by name.

merge

merge(
    *others: Self,
    deep: bool = True,
    copy: bool = True,
    rebuild: bool = False,
    exclude_unset: bool = False,
    **specs
)

Merge the model with other models.

PARAMETER DESCRIPTION
others

The other models to merge.

TYPE: Self DEFAULT: ()

deep

Whether to deep merge the dictionaries.

TYPE: bool DEFAULT: True

copy

Whether to copy the current model.

TYPE: bool DEFAULT: True

rebuild

Whether to rebuild the model. If true, the model will be rebuilt with the formatted data which is a copy of the model.

TYPE: bool DEFAULT: False

exclude_unset

Whether to exclude unset values from the dictionaries.

TYPE: bool DEFAULT: False

specs

The specifications for the formatting.

DEFAULT: {}

setParameters

setParameters(
    params: Dict[str, Any] | None = None, *, force: bool = False, **kwargs
)

Set the material parameters.

toAny

toAny(path: str | PathLike, **kwargs) -> None

Convert the model to a dictionary, json, toml, yaml, or binary string.

toBytes

toBytes(path: str | PathLike | None = None, **kwargs) -> bytes | None

Convert the model to a binary string or save it to a file if a path is provided.

toJson

toJson(path: str | PathLike | None = None, **kwargs) -> str | None

Convert the model to a json string or save it to a file if a path is provided.

toToml

toToml(path: str | PathLike | None = None, **kwargs) -> str | None

Convert the model to a toml string or save it to a file if a path is provided.

toYaml

toYaml(path: str | PathLike | None = None, **kwargs) -> str | None

Convert the model to a yaml string or save it to a file if a path is provided.

update

update(data: dict = None, **kwargs) -> Self

Update the options of the optimizer

_CyFunctionDetectorMeta

Bases: type

__instancecheck__

__instancecheck__(instance)

_make_field_title

_make_field_title(field_name: str, field_info: FieldInfo) -> str

_make_model_title

_make_model_title(model: Type) -> str