Skip to main content

fastapi-canon

PyPI Python CI Ruff Checked with mypy License

FastAPI for streams, WebSockets and AI apps, with typed clients.

FastAPI is great at JSON endpoints. WebSockets, streams and their errors are left to you, and none of it shows up in OpenAPI. Canon makes them typed contracts and generates Python and TypeScript clients.

Plain FastAPI: your own protocol, dispatch and error format, no schema.

@app.websocket("/ws")
async def ws(websocket: WebSocket) -> None:
    await websocket.accept()
    while True:
        message = await websocket.receive_json()
        if message.get("method") != "tasks.complete":
            await websocket.send_json({"id": message.get("id"), "error": "unknown"})
            continue
        try:
            task = await service.complete(int(message["params"]["task_id"]))
            await websocket.send_json(
                {"id": message["id"], "result": task.model_dump()}
            )
        except TaskMissing:
            await websocket.send_json({"id": message["id"], "error": "not found"})

Canon: a typed method with a declared error.

tasks = RpcChannel(namespace="tasks")


@tasks.method(raises=[task_missing])
async def complete(task_id: int, service: Inject[TaskService]) -> Task:
    return await service.complete(task_id)


router.include_channel(tasks, path="/ws")

The generated client is one call: task = await client.tasks.complete(task_id=1).

What Canon adds

  • Errors, declared once. Raise plain exceptions; get the response, OpenAPI entry and client error from one Error.
  • WebSocket RPC. Typed methods, streams and events, no request-ID plumbing.
  • Typed SSE. Clients iterate typed events and know when a stream failed.
  • Everything in the contract. HTTP, streams, sockets and WebRTC, checked in CI.
  • One app model. Features, Dishka dependencies and lifecycles for every transport.

Installation

uv add fastapi-canon

Python 3.12–3.14. Extras: sse, websockets, webrtc, mcp, codegen. Upgrading? See the changelog and upgrade guide.

Learn Canon

The docs are a learning path; start with the quickstart.

Step Guide You learn
1 Quickstart HTTP, SSE and RPC with one error, plus generated clients
2 Errors Public errors, fields and headers
3 Streaming Typed SSE, POST streams, event unions
4 WebSockets Methods, streams and events
5 Composition Features, Dishka services, policies, tests
6 Client generation Generating clients and catching drift
7 Error checking Finding undeclared errors before runtime
8–10 Files, database, observability Production concerns
11–12 WebRTC, MCP Media sessions and agent tools

Runnable apps are in examples/. Coding agents can install the bundled backend skill with uv run fastapi-canon skill install.

Metadata

Release files for fastapi-canon 0.29.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.29.0
File Size Uploaded Provenance Actions
fastapi_canon-0.29.0.tar.gz 491.3 kB With provenance Details for fastapi_canon-0.29.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.1 MB

Release files / fastapi_canon-0.29.0.tar.gz

Download URL fastapi_canon-0.29.0.tar.gz
Size 491.3 kB
Tags Source
SHA-256 checksum
How to use checksums
de3d183c8da7a2f534649b5eb372f5978ba0d1437c8167c873768a8d84bfb5d2
BLAKE2b-256 checksum
How to use checksums
2843222fe6c41782f933c90a676de6f05e11352fd32634ea345d9e18f9822569
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 25, 2026.

Transparency log

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

Download URL fastapi_canon-0.29.0-py3-none-any.whl
Size 574.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5fa9acbe19c76f330371be3c348385d0fd9dd4f6a594acaa6c9283efb447c9ac
BLAKE2b-256 checksum
How to use checksums
e9596865ab4504b92fd68d183c67b90fad921e121fea85772c525d10c6286a2e
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 25, 2026.

Transparency log

Security for fastapi-canon 0.29.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.29.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 25, 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

This release

0.29.0 This release

2 release files Full provenance

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