skillfed

drf-spectacular

Sane and flexible OpenAPI 3 schema generation for Django REST framework

drf-spectacular v0.30.0 13.9M downloads/30d#1,258 on PyPI2,851
Permissive license BSD-3-Clause Active released

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-spectacular

uv

uv add drf-spectacular

poetry

poetry add drf-spectacular

Installing 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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 2.2Framework :: Django :: 3.2Framework :: Django :: 4.0Framework :: Django :: 4.1Framework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Framework :: Django :: 6.0Intended Audience :: DevelopersNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: DocumentationTopic :: Internet :: WWW/HTTPTopic :: Software Development :: Code Generators

Tags

openapi schema generation djangodrf api documentationswagger ui django restrest framework openapiapi schema generator djangorest api documentation toolopenapi 3 django
api-documentationcode-generationdjango-extension

More WWW/HTTP packages