drf-yasg
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django Rest Framework code.
What it is and what it does
drf-yasg is a code-first API documentation tool for Django REST Framework that introspects your DRF views and serializers to generate a Swagger/OpenAPI 2.0 specification. It bundles swagger-ui and ReDoc viewers, so you get interactive documentation endpoints out of the box—no manual schema writing required. The generated specs can be served as JSON or YAML and are cacheable for performance.
The package handles nested serializers, response schemas, and model definitions compatible with code generation tools. It supports DRF's URLPathVersioning and NamespaceVersioning schemes. The documentation notes that OpenAPI 3.0 support is unlikely; for new projects targeting OpenAPI 3.0, the maintainers recommend drf-spectacular instead. Validation against the OpenAPI 2.0 spec is optional but can catch schema errors at generation time.
Use it for:
- Auto-generate interactive API documentation for a Django REST Framework service without writing YAML or JSON by hand.
- Expose Swagger UI and ReDoc viewers at standard endpoints for API consumers to explore and test endpoints.
- Generate OpenAPI 2.0 specs for code generation tools to produce client libraries in other languages.
- Validate generated schemas against the OpenAPI 2.0 spec to catch structural errors early in development.
- Cache the schema view to avoid regenerating specs on every request in production.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates Swagger/OpenAPI 2.0 specifications automatically from Django REST Framework APIs, with built-in UI viewers for swagger-ui and ReDoc.
Yes. drf-yasg is a mature, actively maintained tool for Django REST Framework projects that need Swagger/OpenAPI 2.0 documentation. Low install friction, no security issues, and permissive licensing make it a straightforward choice. The main caveat is that it targets OpenAPI 2.0, not 3.0; if you need OpenAPI 3.0 support, consider drf-spectacular instead. For existing DRF projects or new ones committed to OpenAPI 2.0, this is a reliable dependency.
Install
drf-yasg on PyPI
pip
pip install drf-yasguv
uv add drf-yasgpoetry
poetry add drf-yasgInstalling drf-yasg
Before you install
Low friction installation with a pure-Python wheel. Actively maintained with a recent release; supports current Django (4.0–5.2) and Python (3.9–3.13) versions. No known vulnerabilities.
License in practice
BSD-3-Clause permissive license allows commercial and private use with minimal restrictions; you must include a copy of the license and retain copyright notices.
Quickstart
pip install drf-yasg
# In settings.py
INSTALLED_APPS = ['django.contrib.staticfiles', 'drf_yasg', ...]
# In urls.py
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
schema_view = get_schema_view(
openapi.Info(title="API", default_version='v1'),
public=True,
)
urlpatterns = [
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
]
Requires Django and Django REST Framework installed; static files must be served (django.contrib.staticfiles required).
Verify before relying
- Whether the package's OpenAPI 2.0 output is compatible with all code generation tools mentioned in the description.
- Performance impact of schema generation on larger APIs beyond the caching mitigation described.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 7 — django, djangorestframework, inflection, packaging, pytz, pyyaml, uritemplate |
| Maintenance | actively maintained — 171 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,099,552/month — #2,755 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: drf_yasg-1.21.15-py3-none-any.whl
Keywords: codegen, django, django-rest-framework, django-rest-swagger, documentation, drf, drf-openapi, drf-yasg, openapi, schema, swagger, swagger-codegen
Tags
More Documentation packages
Docutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
SphinxSphinx generates professional documentation…
permissive · top 1,000 on PyPI
griffeGriffe extracts the complete structure and…
permissive · top 1,000 on PyPI
sphinxcontrib-serializinghtmlA Sphinx extension that outputs documentation…
permissive · top 1,000 on PyPI
alabasterAlabaster is a clean, responsive Sphinx theme…
permissive · top 1,000 on PyPI
sphinxcontrib-htmlhelpA Sphinx extension that generates HTML help…
permissive · top 1,000 on PyPI
django-rest-swaggerGenerates Swagger UI documentation and OpenAPI…
permissive · top 15,000 on PyPI
drf-spectacularGenerates OpenAPI 3.0.3, 3.1, and 3.2 schemas…
permissive · top 5,000 on PyPI
drf-spectacular-sidecarServes pre-built Swagger UI and Redoc…
permissive · top 5,000 on PyPI
bravadoBravado generates a dynamic REST client from an…
permissive · top 15,000 on PyPI
flask-swaggerExtracts Swagger 2.0 API specifications from…
permissive · top 15,000 on PyPI
connexionConnexion builds REST APIs from OpenAPI/Swagger…
permissive · top 5,000 on PyPI
bravado-corebravado-core validates, marshals, and…
permissive · top 15,000 on PyPI
essentials-openapiGenerates OpenAPI v2 and v3 documentation in…
permissive · top 15,000 on PyPI
drf-spectacular-jsonapiGenerates OpenAPI 3 schemas for Django REST…
permissive · top 15,000 on PyPI
spectreeGenerates OpenAPI documents and validates HTTP…
permissive · top 15,000 on PyPI