Skip to main content

fastapi-canon

Canon adds typed HTTP contracts, SSE, WebSockets and application composition to FastAPI. Define public errors once, reuse them across transports and export contracts for Python and TypeScript clients.

Install

uv add fastapi-canon

Python 3.12–3.14 is supported. Add extras for the features you use, for example fastapi-canon[sse,websockets] or fastapi-canon[codegen].

Published: 0.16.0. Prepared source: 0.17.0, unreleased. These docs follow the checkout. Version 0.17.0 replaces the combined SDK with separate client generators; follow the migration guide. For published behavior, read the 0.16.0 docs.

Shared error handling

Keep domain exceptions in ordinary Python and declare their public representation:

from fastapi import FastAPI

from fastapi_canon import APIRouter, Composition, Error, Feature


class ProjectMissing(Exception):
    pass


project_missing = Error(
    ProjectMissing,
    status=404,
    code="project_missing",
    title="Project not found",
    detail="Choose another project.",
)
router = APIRouter()


@router.get("/projects/{project_id}", raises=[project_missing])
async def get_project(project_id: int) -> dict[str, int]:
    if project_id == 0:
        raise ProjectMissing()
    return {"id": project_id}


app = Composition(
    features=(Feature(name="projects", routers=[router]),),
).build(FastAPI())

GET /projects/0 returns a 404 RFC 9457 Problem Details response. OpenAPI describes the same error; exception messages stay private by default. Reuse project_missing in SSE and RPC declarations. See the quickstart for the complete server and clients.

What you can build

Task Guide
HTTP routes, dependencies and feature lifecycles Composition
Shared public errors and typed extensions Problems
File uploads and binary downloads File transfers
Typed event streams SSE
RPC, sockets and binary streams WebSockets
Media sessions, tools or database resources WebRTC, MCP, database
Service tracing and request logs Telemetry, logging

Generate and check clients

The prepared 0.17.0 workflow exports contracts and runs specialized SSE, WebSocket and WebRTC generators. Add your HTTP generator through external commands. Configure it with the generation guide, then run:

uv run fastapi-canon generate
uv run fastapi-canon generate --check --diff
uv run fastapi-canon check errors src --strict --require-complete

Python models and error declarations are shared on the server. Generated clients have separate APIs and error classes. Static checks complement runtime tests and report paths they cannot resolve.

Browse the task guides, examples or contributor commands. Coding agents can install the bundled backend skill with uv run fastapi-canon skill install.

Metadata

Release files for fastapi-canon 0.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-canon 0.17.0
File Size Uploaded Provenance Actions
fastapi_canon-0.17.0.tar.gz 413.6 kB With provenance Details for fastapi_canon-0.17.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-canon 0.17.0
File Interpreter ABI Platform Actions
fastapi_canon-0.17.0-py3-none-any.whl Python 3 none any Details for fastapi_canon-0.17.0-py3-none-any.whl

Total release size: 906.7 kB

Release files / fastapi_canon-0.17.0.tar.gz

Download URL fastapi_canon-0.17.0.tar.gz
Size 413.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f9df281497414a3dfb6ae62b56e415fdc71a3d811470b6e51269f5ada04ebede
BLAKE2b-256 checksum
How to use checksums
3d58e2c393e1d221c26d23dd656de8d0ac0a6b683c9e203f43f9079396d0a14e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / fastapi_canon-0.17.0-py3-none-any.whl

Download URL fastapi_canon-0.17.0-py3-none-any.whl
Size 493.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02bccf5edbe705b968b06c034dbc34eba4416558a6240d86f131435d039aa67e
BLAKE2b-256 checksum
How to use checksums
083166b2f3616b97e55fd6981c77656ade18ba4113daa2edea7ed9054f774e94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for fastapi-canon 0.17.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fastapi_canon-0.17.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page