Skip to main content

Pydantic interop for didactic — adapters for incremental migration.

Project description

didactic-pydantic

Bidirectional adapter between pydantic.BaseModel and dx.Model. Contributes didactic.pydantic to the namespace package.

Install

pip install didactic-pydantic

The package depends on didactic and pydantic>=2.10.

from_pydantic

Convert a pydantic.BaseModel subclass into a dx.Model subclass:

from pydantic import BaseModel, Field
from didactic.pydantic import from_pydantic


class PydUser(BaseModel):
    id: str
    email: str = Field(description="primary contact")


User = from_pydantic(PydUser)

Field annotations, defaults, factories, aliases, descriptions, examples, and the deprecated flag carry across. Annotated[T, ...] constraint metadata flows through unchanged, so annotated-types primitives (Ge, Le, ...) continue to produce axioms on the didactic side.

Custom Pydantic validators (@field_validator, @model_validator), @computed_field, and discriminated unions are not translated; the Pydantic interop guide lists the didactic-side replacements.

to_pydantic

The inverse direction:

import didactic.api as dx
from didactic.pydantic import to_pydantic


class User(dx.Model):
    id: str
    email: str = dx.field(description="primary contact")


PydUser = to_pydantic(User)

Use to_pydantic to expose a dx.Model to FastAPI, OpenAPI generators, or any other Pydantic-shaped tool. The conversion is cached, so repeated calls with the same input return the same Pydantic class.

Documentation

See Guides > Pydantic interop for the full feature matrix and round-trip behaviour.

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

didactic_pydantic-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

didactic_pydantic-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file didactic_pydantic-0.1.0.tar.gz.

File metadata

  • Download URL: didactic_pydantic-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for didactic_pydantic-0.1.0.tar.gz
Algorithm Hash digest
SHA256 efe36a7baefa215a4793d8681322ee71e108ec5e2c30f69253db9e9bb150b7d1
MD5 d73892905bba843bad361ff78c722de0
BLAKE2b-256 ef5cdeb6a20055bdfa12a062ca559cf278c4b2fbb9aa71561a5db63c5b2e7857

See more details on using hashes here.

File details

Details for the file didactic_pydantic-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: didactic_pydantic-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for didactic_pydantic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fad3fa709350293f837f1c02d094916f687f458458ae84c2486c7df27a520945
MD5 a80a82b46836d8f719f8c231d0456317
BLAKE2b-256 ff0cc4ac11faa142d5800449e0ddee2300c2b1cbad12d4876730b96376db91c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page