Skip to main content

Pydantic interop for didactic — adapters for incremental migration.

Project description

didactic-pydantic

Bidirectional adapter between pydantic.BaseModel and dx.Model.

PyPI Python License CI Docs

Contributes didactic.pydantic to the namespace package.

Install

pip install didactic-pydantic

The package depends on didactic and pydantic>=2.10.

Quickstart

from_pydantic converts 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 is 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

Released under the MIT License.

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.7.8.tar.gz (8.3 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.7.8-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: didactic_pydantic-0.7.8.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for didactic_pydantic-0.7.8.tar.gz
Algorithm Hash digest
SHA256 6cb346dd8b0603c3c7d40aa92bab051c6fe84530a7e2912f95b1fdf6cbf5a4ba
MD5 063114f4973dfbf28d1ec8f07a6e3181
BLAKE2b-256 ddabc65ae4141cb114a9a541713422c6ba997a7d599e49f72051eabf5ec7da72

See more details on using hashes here.

Provenance

The following attestation bundles were made for didactic_pydantic-0.7.8.tar.gz:

Publisher: release.yml on panproto/didactic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for didactic_pydantic-0.7.8-py3-none-any.whl
Algorithm Hash digest
SHA256 6c564233056f5f7c994c1b358a8f3c0b7c321ae01d002a4f2337d0a995e9d3f1
MD5 4ebb9c34ae2a8d5c058e620a34a902c4
BLAKE2b-256 234a0f5a37523974e9d8adfb6e01010afc453be11e0c1a2b9ebd08309dc1d8a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for didactic_pydantic-0.7.8-py3-none-any.whl:

Publisher: release.yml on panproto/didactic

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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