Registry / serialization / dydantic

dydantic

JSON →
library0.0.8pypypi✓ verified 24d ago

Dydantic is a Python library designed for dynamically generating Pydantic models directly from JSON Schema definitions. It offers a streamlined approach to creating Pydantic models on-the-fly, based on user-defined schemas, and is currently at version 0.0.8. The project appears to be actively maintained, with a recent PyPI release and GitHub activity.

pip install -U dydantic
INSTALL
IMPORT
SIG · DYDANTIC
D
dydantic
serializationpythonv0.0.8
Install
3.3s avg
Import
382ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.8 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.404s · 27.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.3s · import 0.360s · 27MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

create_model_from_schema
from dydantic import create_model_from_schema
This is the primary function for generating Pydantic models from a JSON schema.

This quickstart demonstrates how to define a simple JSON schema and use `dydantic` to create a corresponding Pydantic model. It then shows how to instantiate and serialize the dynamically generated model.

from dydantic import create_model_from_schema json_schema = { "title": "Person", "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"} }, "required": ["name"] } Person = create_model_from_schema(json_schema) person_instance = Person(name="Jane Doe", age=30) print(person_instance.model_dump_json(indent=2)) # Expected output: # { # "name": "Jane Doe", # "age": 30 # }
Debug
Known issues
breakingDydantic requires Pydantic v2.x. Users migrating from Pydantic v1.x projects will encounter breaking changes in Pydantic's API (e.g., method renames like `dict()` to `model_dump()`, `json()` to `model_dump_json()`, and changes to configuration handling).
fix
Consult the Pydantic v1 to v2 migration guide (`https://pydantic.dev/latest/migration/`) for necessary adjustments to code interacting with generated models.
affects: <=0.0.8 (due to Pydantic v2 requirement)
gotchaPydantic v2, which Dydantic leverages, has stricter type coercion rules. Data that might have been implicitly coerced in Pydantic v1 (e.g., a number string to an integer) may now raise validation errors if the JSON schema type doesn't perfectly match the input data.
fix
Ensure that your input data strictly adheres to the types defined in your JSON schema. Explicitly cast or transform data before passing it to the generated Pydantic models if strictness causes issues.
affects: <=0.0.8 (due to Pydantic v2 requirement)
gotchaIn Pydantic v2 (and thus Dydantic-generated models), a field annotated as `typing.Optional[T]` is considered required by default and merely *allows* a value of `None`. It does not automatically provide a default value of `None`. If your JSON schema implies optionality via `nullable: true` but doesn't provide a `default` value, the field will still be required unless an explicit Python `default=None` is passed during model creation or the field is marked as not required.
fix
For truly optional fields that should default to `None` if not provided, ensure your JSON schema specifies a `default: null` or handle the `None` case explicitly when instantiating the generated model.
affects: <=0.0.8 (due to Pydantic v2 behavior)
Upgrade
Version history
0.0.8latest on PyPI · released Jan 29, 2025
Audit
Dependencies
pydanticrequiredCore dependency for model generation and validation, requires Pydantic v2.x.
typing_extensionsrequiredProvides backports of new `typing` features for broader Python version compatibility.
Agent activity
13 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
dydantic — pip install dydantic · libregistry