DocTreen
Adapters

FastAPI

Python adapter — drift detection over the spec FastAPI already produces, mounted beside its own docs.

FastAPI is the one framework DocTreen does not try to document. It already gives you Pydantic-native docs, an OpenAPI 3.1 spec, and 422-on-invalid-request validation. So the adapter reads rather than derives — it consumes app.openapi() and adds the layer FastAPI does not have: schema drift detection and the shared docs UI.

pip install "doctreen[fastapi]"

Mount

from doctreen.adapters.fastapi import mount_doctreen

mount_doctreen(app, {"drift": {"enabled": True}})

FastAPI's Swagger UI stays exactly where it is at /docs; DocTreen defaults its docsPath to /doctreen so the two never collide (pass docsPath explicitly to override). You get:

  • GET /doctreen — the shared DocTreen UI, built from the app's own spec
  • GET /doctreen/openapi.json — the spec
  • GET /doctreen/drift.json — what your clients are actually sending, measured against what your routes declare

What it deliberately doesn't do

Request validation is not installed: FastAPI already rejects invalid bodies, and a second validator would either duplicate that work or disagree with it. Keep FastAPI's docs and validation; use DocTreen for drift and flows.

Notes

On this page