dyff.schema¶
Dyff uses pydantic models to formalize all of its data schemas. Pydantic models can be converted easily to and from JSON objects, and they perform validation when loading JSON data. We also use the models to generate schemas in the JSON Schema format, which, in turn, form part of the OpenAPI specification of Dyff API.
Warning
Dyff currently only supports Pydantic V1. A migration to V2 is planned.
To convert a model to a JSON object, use model.dict()
; to create a model
from a JSON object, use ModelType.parse_obj()
. 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 Platform schemas
derive from DyffSchemaBaseModel
,
which overrides dict()
and json()
so that they default to using the
aliases as the keys when building JSON objects. You generally should not
override this behavior.