drf-spectacular

Sane, flexible OpenAPI 3.0/3.1/3.2 schema generation for Django REST Framework

Library
PyPI
v0.30.0
2,863 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
62 /100 Good
Development Activity 48
Maintenance 32
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
81 /100 Excellent
Architecture 82
Code Quality 84
Innovation 80
Learning Curve 78

drf-spectacular generates OpenAPI schemas directly from a Django REST Framework project’s serializers, views, and viewsets, going well beyond DRF’s built-in schema generator. It started as a heavily modified fork of DRF’s native OpenAPI generator, built specifically to extract more accurate schema information automatically, stay usable on real-world (not toy) APIs, and produce output that works cleanly with popular client-code generators like openapi-generator and Swagger Codegen.

The library covers the parts of API documentation that are otherwise painful to keep accurate by hand: nested/recursive serializer components, polymorphic responses, authentication scheme detection, i18n, request/response examples, and built-in extension points for a long list of common DRF add-ons (SimpleJWT, django-filter, django-oauth-toolkit, django-polymorphic, drf-nested-routers, Pydantic, and more).

What You Get

  • Automatic OpenAPI 3.0.3 / 3.1 / 3.2 schema generation from DRF serializers, views, viewsets, and function-based views
  • @extend_schema and @extend_schema_field decorators to override or augment inferred schema details (parameters, request/response bodies, examples, polymorphic responses)
  • Built-in SpectacularAPIView, Swagger UI, and Redoc views for serving and browsing the generated schema
  • Authentication scheme detection for DRF-native auth plus SimpleJWT, OAuth Toolkit, dj-rest-auth, and others out of the box
  • First-class integrations for django-filter, drf-nested-routers, django-polymorphic, Pydantic (>=2.0), and django-rest-framework-gis
  • Vendor extension (x-*) support across info, operations, parameters, components, and security schemes, plus i18n and sane operation_id naming

Common Use Cases

  • Generating an always-in-sync OpenAPI spec for a DRF API instead of hand-maintaining Swagger/YAML files
  • Serving interactive Swagger UI or Redoc documentation directly from a Django app with no extra infrastructure
  • Feeding a generated schema into client-code generators (TypeScript, Java, etc.) to produce typed API clients
  • Documenting polymorphic or deeply nested serializer responses that DRF’s built-in schema generator can’t express
  • Auditing an API’s authentication and permission surface via the generated security schemes

Under The Hood

Architecture — The package is organized as a Django app (drf_spectacular/) with generators.py performing the core schema-building walk over a DRF Router/APIView set, openapi.py assembling the resulting OpenAPI document, and plumbing.py/utils.py housing the serializer/field introspection helpers that turn DRF component types into OpenAPI schema fragments. extensions.py implements an extension-point system (OpenApiSerializerExtension, OpenApiAuthenticationExtension, etc.) that the contrib/ package uses to register first-class support for third-party libraries (SimpleJWT, django-filter, Pydantic, django-oauth-toolkit) without touching the core generator. views.py/renderers.py expose the schema and Swagger/Redoc UI as ordinary DRF views.

Tech Stack — Pure Python, built against Django and Django REST Framework, packaged with a standard pyproject.toml/setup.cfg, using PyYAML/uritemplate/jsonschema as core runtime dependencies and an extensive requirements/ directory of optional dependencies for each contrib integration it supports.

Code Quality — The tests/ directory is large and organized by feature area (test_basic.py, test_callbacks_split_request.yml, a dedicated tests/contrib/ suite per third-party integration, and both OAS 3.0 and 3.1 golden-file fixtures), run via runtests.py/tox.ini across multiple Django/DRF version combinations, with Codecov coverage tracking. The project ships a py.typed marker and has years of continuous, active maintenance (drf-spectacular is the de facto standard OpenAPI generator for DRF, having effectively superseded drf-yasg).

API Design — Zero-config usage works for straightforward serializers (add it to INSTALLED_APPS, point DEFAULT_SCHEMA_CLASS at it, done), while the @extend_schema decorator gives an escape hatch for every case introspection can’t resolve alone — extra parameters, response overrides per status code, polymorphic responses, and per-field type hints via @extend_schema_field. The contrib/ extension mechanism means adopting a supported third-party library (SimpleJWT, django-filter) requires no manual schema code at all, which keeps the common path close to zero-boilerplate despite the underlying introspection being substantial.

Used by 13 apps in this directory

Python
55%
Other

authentik

Authentication · Security

25,758

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
Python 55%
TypeScript 36%
Updated 4 days ago
Python
68%
Other

Baserow

Databases · No Code Platforms

6,012

Open-source no-code platform to build databases, apps, automations, and AI agents — self-hosted or cloud, with full data ownership.

View details
89
Repo Health
84
Technical
68
Dependency
Built with
Python 68%
JavaScript 16%
Vue 11%
Updated 5 days ago
Python
84%
Other

Bugsink

Developer Tools · Monitoring

2,095

Self-hosted error tracking that accepts Sentry SDKs out of the box, so you keep your instrumentation and drop the monthly bill.

View details
84
Repo Health
80
Technical
71
Dependency
Built with
Python 84%
HTML 14%
Updated 1 weeks ago
Python
47%
MIT

Docs

CMS · File Storage

16,868

Open-source collaborative knowledge platform with real-time editing, AI writing tools, and full self-hosting control — built by the French and German governments.

View details
88
Repo Health
81
Technical
68
Dependency
Built with
Python 47%
TypeScript 45%
Updated 4 days ago
Python
63%
BSD 3

Flagsmith

Ab Testing Experimentation · Developer Tools · Devops

6,577

Open-source feature flagging, remote config, and A/B/multivariate testing platform for web, mobile, and server-side apps — self-host or use the hosted SaaS.

View details
90
Repo Health
82
Technical
63
Dependency
Built with
Python 63%
TypeScript 31%
Updated 6 days ago
TypeScript
39%
Apache 2.0

Label Studio

AI Development · Data Engineering

28,358

Label Studio is an open-source, multi-type data labeling platform that lets teams annotate images, text, audio, video, and time series data with a configurable XML-based UI and export annotations in formats ready for any ML framework.

View details
93
Repo Health
87
Technical
67
Dependency
Built with
TypeScript 39%
JavaScript 27%
Python 25%
Updated 4 days ago
Python
58%
MIT

LibrePhotos

File Storage

8,083

Self-hosted photo library with AI-powered face recognition, semantic search, and automatic event albums — no cloud required.

View details
83
Repo Health
78
Technical
65
Dependency
Built with
Python 58%
TypeScript 40%
Updated 5 days ago
Python
45%
GPL 3.0

MaxKB

AI Development · Knowledge Management

22,882

Build enterprise-grade AI agents with RAG, workflows & multi-modal support

View details
92
Repo Health
68
Technical
66
Dependency
Built with
Python 45%
Vue 37%
TypeScript 17%
Updated 4 days ago
Python
63%
GPL 3.0

Paperless-ngx

Bookmarks Archiving

46,108

Turn your paper pile into a searchable digital archive with OCR, AI classification, and automated workflows — all running on your own server.

View details
91
Repo Health
88
Technical
67
Dependency
Built with
Python 63%
TypeScript 28%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers