DocTreen
Adapters

Django / DRF

Python adapter — URLconf introspection and DRF serializer schemas, no router to replace.

Splice the URLs into the URLconf you already have. There is no router to replace and no base class to inherit — DocTreen walks the patterns Django has been keeping all along, and reads your DRF serializers, because that is what a Django API already uses to describe its payloads.

pip install "doctreen[drf]"     # Django + djangorestframework
pip install "doctreen[django]"  # Django only

Mount

# urls.py
from doctreen.adapters.django import doctreen_urls

urlpatterns = [
    path("api/", include(router.urls)),
    *doctreen_urls({"meta": {"title": "My API"}, "drift": {"enabled": True}}),
]
# settings.py — for drift sampling
MIDDLEWARE = [..., "doctreen.adapters.django.DocTreenMiddleware"]

That serves GET /docs, GET /docs/openapi.json, and (with drift enabled) GET /docs/drift.json from your existing URLconf.

What gets documented

  • A DRF ViewSet expands into one documented route per action, each carrying its own docstring: list becomes GET /users, create becomes POST /users, and so on.
  • Serializers provide the request/response schemas.
  • Router regexes and path() converters are both understood, so <int:pk> arrives typed — nothing to declare.

Scope is deliberately DRF. A plain Django view returning HttpResponse declares no contract, so it is listed but carries no schema — inferring one would produce confident documentation of something nobody promised.

What it deliberately doesn't do

Request validation is not installed: a serializer already validates in the view, with an error format your clients depend on. Use DocTreen here for docs, the OpenAPI export, drift, and flows.

On this page