dyff.schema¶
The dyff.schema package contains schema definitions for Dyff resources.
Installation¶
Install the dyff-schema package from PyPI:
python3 -m pip install dyff-schema
Pydantic models¶
Dyff uses pydantic models to formalize all of its data schemas. We also use the models to generate schemas in the JSON Schema format, which, in turn, form part of the OpenAPI specification of the Dyff API.
Pydantic models are easy to convert to and from JSON, and they perform
validation when loading data. To create a model instance from a Python dict,
use ModelType.model_validate(data). To create a model instance from a JSON
string, use ModelType.model_validate_json(json_str). To convert a model
instance to a Python dict, use model.model_dump(). To convert to a
JSON string, use model.model_dump_json(). When you need a dict
containing only JSON-native types (e.g. datetime serialized to a string),
use model.model_dump(mode="json").
Note that in some cases, the
“canonical name” of a field is not valid as a pydantic model field name, either
because it conflicts with fields inherited from pydantic.BaseModel, or
because it is a Python reserved word like bytes. In these cases, the field
will have an alias set to its canonical name. All Dyff schema models
derive from DyffBaseModel,
which overrides model_dump() and model_dump_json() so that they default
to using the aliases as the keys when building JSON objects. You generally
should not override this behavior.