Skip to main content

FastAPI integration for didactic Models.

Project description

didactic-fastapi

FastAPI integration for dx.Model types.

PyPI Python License CI Docs

Contributes didactic.fastapi to the namespace package.

Install

pip install didactic-fastapi

The package depends on didactic, didactic-pydantic, and fastapi>=0.115.

Quickstart

import didactic.api as dx
from fastapi import FastAPI
from didactic.fastapi import as_response, register_validation_handler


class User(dx.Model):
    id: str
    email: str


app = FastAPI()
register_validation_handler(app)


@app.get("/users/{uid}", response_model=as_response(User))
def get_user(uid: str) -> User:
    return User(id=uid, email="ada@example.org")

as_response(model) returns a pydantic.BaseModel subclass mirroring the input dx.Model. FastAPI uses the result for response validation and OpenAPI generation. The conversion is cached per input class.

as_request(model) is a synonym; use whichever name reads naturally in your route signatures.

register_validation_handler(app) installs an exception handler so that dx.ValidationError raised inside a route surfaces as a 422 response shaped like FastAPI's own validation errors.

Documentation

See Guides > FastAPI for the full integration guide and caveats.

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_fastapi-0.3.0.tar.gz (3.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_fastapi-0.3.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file didactic_fastapi-0.3.0.tar.gz.

File metadata

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

File hashes

Hashes for didactic_fastapi-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d53afe6fc96936913c25f2f4673b3142b85e318a3d3f002a2acc27228b5a201c
MD5 3474337eb44c93a08fa0e5ee2485f6c7
BLAKE2b-256 4629bd9fbe1cac1c6b52a528e59bf7f57f1e7fd3221adbd4b7a1be3d47283e49

See more details on using hashes here.

Provenance

The following attestation bundles were made for didactic_fastapi-0.3.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_fastapi-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for didactic_fastapi-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e57ed9c18af5d3123587e597ff08bea205d1d7d9692afd9f7c7e240abdf0cefb
MD5 d87e5bff7d519ea44e332719fd4f1557
BLAKE2b-256 7a1f9562510700845868c2d180979c3765135c2d8f05c997f1b30841527c6424

See more details on using hashes here.

Provenance

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

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