{"id":4524,"library":"dydantic","title":"Dydantic","description":"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.","status":"active","version":"0.0.8","language":"en","source_language":"en","source_url":"https://github.com/hinthornw/dydantic","tags":["pydantic","json-schema","model-generation","dynamic-models","validation","schema-to-code"],"install":[{"cmd":"pip install -U dydantic","lang":"bash","label":"Install Dydantic"}],"dependencies":[{"reason":"Core dependency for model generation and validation, requires Pydantic v2.x.","package":"pydantic","optional":false},{"reason":"Provides backports of new `typing` features for broader Python version compatibility.","package":"typing_extensions","optional":false}],"imports":[{"note":"This is the primary function for generating Pydantic models from a JSON schema.","symbol":"create_model_from_schema","correct":"from dydantic import create_model_from_schema"}],"quickstart":{"code":"from dydantic import create_model_from_schema\n\njson_schema = {\n    \"title\": \"Person\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"name\": {\"type\": \"string\"},\n        \"age\": {\"type\": \"integer\"}\n    },\n    \"required\": [\"name\"]\n}\n\nPerson = create_model_from_schema(json_schema)\nperson_instance = Person(name=\"Jane Doe\", age=30)\n\nprint(person_instance.model_dump_json(indent=2))\n# Expected output:\n# {\n#   \"name\": \"Jane Doe\",\n#   \"age\": 30\n# }","lang":"python","description":"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."},"warnings":[{"fix":"Consult the Pydantic v1 to v2 migration guide (`https://pydantic.dev/latest/migration/`) for necessary adjustments to code interacting with generated models.","message":"Dydantic 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).","severity":"breaking","affected_versions":"<=0.0.8 (due to Pydantic v2 requirement)"},{"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.","message":"Pydantic 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.","severity":"gotcha","affected_versions":"<=0.0.8 (due to Pydantic v2 requirement)"},{"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.","message":"In 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.","severity":"gotcha","affected_versions":"<=0.0.8 (due to Pydantic v2 behavior)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}