drf-spectacular
Sane and flexible OpenAPI 3 schema generation for Django REST framework
What it is and what it does
drf-spectacular is an OpenAPI schema generator for Django REST framework that extracts API structure directly from your code and produces valid OpenAPI 3.0.3, 3.1, or 3.2 specifications. It replaces the basic schema generation built into DRF with a more capable alternative that handles real-world API patterns: nested and recursive serializers, polymorphic responses, custom authentication schemes, and vendor extensions. The package works out of the box with sensible defaults but offers deep customization through the @extend_schema decorator and settings, allowing you to override serializers, add examples, control operation IDs, and adjust how components are split.
The tool integrates with popular DRF extensions (SimpleJWT, django-filter, Pydantic, django-polymorphic) and provides built-in views to serve the schema via Swagger UI or Redoc. You can generate schemas via CLI (./manage.py spectacular) or serve them live from your API. It depends on Django, djangorestframework, uritemplate, PyYAML, jsonschema, inflection, and typing-extensions—all lightweight, widely-used libraries.
Use it for:
- Generate and serve interactive API documentation (Swagger UI or Redoc) directly from your Django REST framework code.
- Export OpenAPI schemas for use with code generators (client SDKs, mock servers) or third-party API tools.
- Document complex APIs with nested serializers, polymorphic responses, and custom authentication without manual schema writing.
- Validate API schemas during CI/CD pipelines using the --validate CLI flag.
- Customize schema output per-endpoint using @extend_schema decorators to override auto-detected types or add examples.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates OpenAPI 3.0.3, 3.1, and 3.2 schemas automatically from Django REST framework APIs, with extensive customization options for real-world use cases.
Yes. drf-spectacular is actively maintained, has no known vulnerabilities, installs with low friction, and is licensed permissively. It solves a real problem—generating accurate OpenAPI documentation from Django REST framework code—and is widely used (top 5000 PyPI packages). Install it if you need OpenAPI schemas for a DRF API and want automation over manual maintenance.
Install
drf-spectacular on PyPI
pip
pip install drf-spectacularuv
uv add drf-spectacularpoetry
poetry add drf-spectacularInstalling drf-spectacular
Before you install
Low friction install with a pure-Python wheel. Actively maintained with a recent release (39 days ago) and 2851 repository stars. Depends on Django, djangorestframework, and several lightweight utilities (uritemplate, PyYAML, jsonschema, inflection, typing-extensions).
License in practice
Licensed under BSD-3-Clause (permissive), allowing commercial and private use with minimal restrictions—only requiring license and copyright notice inclusion.
Quickstart
pip install drf-spectacular
# In settings.py
INSTALLED_APPS = ['drf_spectacular']
REST_FRAMEWORK = {'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema'}
# In urls.py
from drf_spectacular.views import SpectacularAPIView
urlpatterns = [path('api/schema/', SpectacularAPIView.as_view(), name='schema')]
Requires Django 3.2+ and Django REST Framework 3.12+; Python >= 3.8.
Verify before relying
- Whether the package's schema generation works correctly with all listed framework versions without manual intervention.
- Performance characteristics when generating schemas for large or deeply nested API structures.
- Compatibility with third-party DRF extensions beyond those explicitly listed in the description.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 7 — Django, djangorestframework, uritemplate, PyYAML, jsonschema, inflection, typing-extensions |
| Maintenance | actively maintained — 39 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 13,905,521/month — #1,258 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: drf_spectacular-0.30.0-py3-none-any.whl
Keywords: django, rest, openapi, schema, api, swagger
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
drf-spectacular-jsonapiGenerates OpenAPI 3 schemas for Django REST…
permissive · top 15,000 on PyPI
drf-spectacular-sidecarServes pre-built Swagger UI and Redoc…
permissive · top 5,000 on PyPI
drf-yasgGenerates Swagger/OpenAPI 2.0 specifications…
permissive · top 5,000 on PyPI
drf-standardized-errorsConverts all Django REST Framework API error…
permissive · top 15,000 on PyPI
flask-openapi3Builds REST APIs on Flask with automatic…
permissive · top 15,000 on PyPI
mkdocs-render-swagger-pluginRenders Swagger and OpenAPI schemas as…
permissive · top 15,000 on PyPI
voluptuous-openapiConverts Voluptuous validation schemas into…
permissive · top 15,000 on PyPI
djangorestframeworkBuilds web APIs on top of Django with…
permissive · top 1,000 on PyPI
flask-openapi3-swaggerProvides Swagger UI integration for…
permissive · top 15,000 on PyPI
drf-jsonschema-serializerConverts Django REST Framework serializers to…
permissive · top 15,000 on PyPI