skillfed

drf-yasg

Automated generation of real Swagger/OpenAPI 2.0 schemas from Django Rest Framework code.

drf-yasg v1.21.15 3.1M downloads/30d#2,755 on PyPI3,545
Permissive license BSD-3-Clause Active released

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

uv

uv add drf-yasg

poetry

poetry add drf-yasg

Installing 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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 4.0Framework :: Django :: 4.1Framework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Intended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: DocumentationTopic :: Software Development :: Code Generators

Tags

swagger documentation generatoropenapi 2.0 schema djangodrf api documentationrest framework schema generationswagger ui for djangoapi specification from codeopenapi schema validator
api-documentationschema-generationswagger-openapi

More Documentation packages

docutils

Docutils converts plaintext documentation in…

unclear · top 1,000 on PyPI

Sphinx

Sphinx generates professional documentation…

permissive · top 1,000 on PyPI

griffe

Griffe extracts the complete structure and…

permissive · top 1,000 on PyPI

sphinxcontrib-serializinghtml

A Sphinx extension that outputs documentation…

permissive · top 1,000 on PyPI

alabaster

Alabaster is a clean, responsive Sphinx theme…

permissive · top 1,000 on PyPI

sphinxcontrib-htmlhelp

A Sphinx extension that generates HTML help…

permissive · top 1,000 on PyPI

django-rest-swagger

Generates Swagger UI documentation and OpenAPI…

permissive · top 15,000 on PyPI

drf-spectacular

Generates OpenAPI 3.0.3, 3.1, and 3.2 schemas…

permissive · top 5,000 on PyPI

drf-spectacular-sidecar

Serves pre-built Swagger UI and Redoc…

permissive · top 5,000 on PyPI

bravado

Bravado generates a dynamic REST client from an…

permissive · top 15,000 on PyPI

flask-swagger

Extracts Swagger 2.0 API specifications from…

permissive · top 15,000 on PyPI

connexion

Connexion builds REST APIs from OpenAPI/Swagger…

permissive · top 5,000 on PyPI

bravado-core

bravado-core validates, marshals, and…

permissive · top 15,000 on PyPI

essentials-openapi

Generates OpenAPI v2 and v3 documentation in…

permissive · top 15,000 on PyPI

drf-spectacular-jsonapi

Generates OpenAPI 3 schemas for Django REST…

permissive · top 15,000 on PyPI

spectree

Generates OpenAPI documents and validates HTTP…

permissive · top 15,000 on PyPI