--- id: drf-yasg version: "1.21.15" license: BSD-3-Clause license_treatment: permissive maintenance: active --- # drf-yasg — Automated generation of real Swagger/OpenAPI 2.0 schemas from Django Rest Framework code. License: permissive · Maintenance: active · Downloads: 3.1M/mo ## 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 above — 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 pip install drf-yasg uv add drf-yasg 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_current - Install friction: low - Maintenance: active - Downloads: 3.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags swagger documentation generator, openapi 2.0 schema django, drf api documentation, rest framework schema generation, swagger ui for django, api specification from code, openapi schema validator, api-documentation, schema-generation, swagger-openapi [View on SkillFed](https://skillfed.io/packages/drf-yasg) · [View on PyPI](https://pypi.org/project/drf-yasg/)