Skip to content

pydantic

sgp.pydantic.CythonFunctionDetector

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

sgp.pydantic.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

sgp.pydantic.HashableBaseModelIO.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.

sgp.pydantic.HashableBaseModelIO.__hash__

__hash__() -> int

Return the hash of the model.

sgp.pydantic.HashableBaseModelIO.fromBytes classmethod

fromBytes(*, binary: bytes | None = None, path: str | None = None, **kwargs) -> Self

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

sgp.pydantic.HashableBaseModelIO.fromCryptography classmethod

fromCryptography(*, binary: bytes | None = None, path: str | None = None, **kwargs) -> Self

Decrypt the model using the key.

sgp.pydantic.HashableBaseModelIO.fromDict classmethod

fromDict(*, data: dict, **kwargs) -> Self

Load the model from a dictionary.

sgp.pydantic.HashableBaseModelIO.fromJson classmethod

fromJson(*, string: str | None = None, path: str | None = None, **kwargs)

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

sgp.pydantic.HashableBaseModelIO.fromToml classmethod

fromToml(*, string: str | None = None, path: str | None = None, **kwargs)

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

sgp.pydantic.HashableBaseModelIO.fromYaml classmethod

fromYaml(*, string: str | None = None, path: str | None = None, **kwargs)

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

sgp.pydantic.HashableBaseModelIO.toBytes

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

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

sgp.pydantic.HashableBaseModelIO.toCryptography

toCryptography(path: Path | str | None = None, **kwargs) -> bytes | None

Encrypt the model using the key.

sgp.pydantic.HashableBaseModelIO.toDict

toDict(**kwargs) -> dict

Convert the model to a dictionary.

sgp.pydantic.HashableBaseModelIO.toJson

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

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

sgp.pydantic.HashableBaseModelIO.toToml

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

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

sgp.pydantic.HashableBaseModelIO.toYaml

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

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

sgp.pydantic.HashableBaseModelIO.update

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

Update the options of the optimizer

sgp.pydantic._CyFunctionDetectorMeta

Bases: type