Skip to main content

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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: didactic_pydantic-0.10.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for didactic_pydantic-0.10.0.tar.gz
Algorithm Hash digest
SHA256 4204802e29e57b5090606aaaaaadd47ff0e9d9fd18be2057c587b7fcf72cc8e7
MD5 95fd6161eb3c7e5943cbe1cf7bdac537
BLAKE2b-256 2529c6bb4d458f6743872f98eab9671aba0c457574cf53e9a2ee17b4566b1d1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for didactic_pydantic-0.10.0.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.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for didactic_pydantic-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 297e7e88aba4dade35d9c364f895209a9f9b5295e536accd317b74f749a3e49e
MD5 89d417393a646f705991cda46b8a68c3
BLAKE2b-256 5d3ee4f748b039047187a5468854dfbf0c1f9a46eb85519bcca339937985bd7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for didactic_pydantic-0.10.0-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.

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.8

2 files

0.7.7

2 files

0.7.6

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

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