Registry / web-framework / drf-yasg

drf-yasg

JSON →
library1.21.15pypypi✓ verified 26d ago

drf-yasg is a powerful tool for automated generation of real Swagger/OpenAPI 2.0 schemas directly from Django Rest Framework code. It simplifies API documentation by integrating Swagger UI and ReDoc into Django projects. The current version is 1.21.15, and the project maintains an active release cadence with frequent updates and bug fixes.

pip install drf-yasg
INSTALL
IMPORT
SIG · DRF-YASG
D
drf-yasg
web-frameworkpythonv1.21.15
Install
4.6s avg
Import
Disk
94MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.21.15 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 93.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.6s · import 0.000s · 95MB
94MB installed
● package 94MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_schema_view
from drf_yasg import get_schema_view
from drf_yasg import get_schema_view

To quickly integrate drf-yasg, add 'drf_yasg' to your `INSTALLED_APPS` in `settings.py`. Then, include these URL patterns in your project's `urls.py`. This setup provides endpoints for the OpenAPI schema in JSON/YAML, the interactive Swagger UI, and the ReDoc documentation.

from django.urls import path, re_path from rest_framework import permissions from drf_yasg.views import get_schema_view from drf_yasg import openapi schema_view = get_schema_view( openapi.Info( title="My API", default_version='v1', description="Test description", terms_of_service="https://www.google.com/policies/terms/", contact=openapi.Contact(email="contact@snippets.local"), license=openapi.License(name="BSD License"), ), public=True, permission_classes=(permissions.AllowAny,), ) urlpatterns = [ re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'), path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), ]
Debug
Known issues
breakingdrf-yasg no longer guarantees preservation of schema field order due to a change from `OrderedDict` to native `dict` for schema generation.
fix
Review any client-side or external tools that strictly rely on the order of fields in the generated OpenAPI schema. Most OpenAPI consumers should not depend on field order, but if specific integrations break, consider custom schema generation or alternative validation.
affects: 1.21.15 and higher
deprecatedPython 3.6 support has been officially dropped. Installations on Python 3.6 may encounter issues or lack new features.
fix
Upgrade your Python environment to 3.7 or higher. The library officially supports Python 3.9+.
affects: 1.21.5 and higher
gotchaIssues with `from __future__ import annotations` and complex type hints, especially on Python 3.12, could lead to schema generation failures.
fix
Ensure you are on drf-yasg 1.21.15 or newer, which includes fixes for Python 3.12 type parameter syntax. For older versions or other type hint issues, review your type hint usage or consider temporarily disabling `from __future__ import annotations` if possible.
affects: Pre-1.21.15 (especially with Python 3.12)
gotchaWhen using `django-filter`, filter parameters might not appear in the generated Swagger UI if the drf-yasg version is too old.
fix
Upgrade drf-yasg to 1.21.11 or higher, which includes a fix for `django-filter>=25` compatibility.
affects: Pre-1.21.11
deprecatedThe `drf_yasg.inspectors.coreapi.CoreAPICompatInspector` has been replaced by `drf_yasg.inspectors.query.DrfAPICompatInspector`.
fix
If you were using custom inspectors based on `CoreAPICompatInspector`, update your configuration to use `DrfAPICompatInspector` for improved compatibility and future-proofing.
affects: 1.21.7 and higher
Upgrade
Version history
1.21.15latest on PyPI · released Feb 24, 2026
Audit
Dependencies
djangorestframeworkrequiredCore dependency for schema generation. While not a direct pip dependency, it's required for drf-yasg to function.
DjangorequiredCore framework dependency. While not a direct pip dependency, it's required for drf-yasg to function.
PyYAMLrequiredUsed for YAML schema generation, became a direct dependency in 1.21.6.
django-filteroptionalOptional. If using django-filter for API filtering, ensure compatibility with drf-yasg.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
drf-yasg — pip install drf-yasg · libregistry