drf-yasg: OpenAPI 2.0 Schemas from Django REST Framework Code
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
At a glance
- What is it?
- drf-yasg generates real Swagger/OpenAPI 2.0 specifications from Django REST Framework views and serializers, and ships swagger-ui and ReDoc to render them. It is a mature 2.0-only tool; the README itself points new projects at drf-spectacular for OpenAPI 3.0.
- Who is it for?
- Adopt drf-yasg if your consumers already work against Swagger 2.0, if you need the swagger-ui and ReDoc views served from Django, or if you depend on the caching and customization hooks described in the README. Do not adopt it for a new project that needs OpenAPI 3.0, since the README states 3.0 support is unlikely to arrive.
- Can I use it commercially?
- Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
- Is it still maintained?
- Yes. The repository last received commits 1 day ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.
Star history
- axnsan12/drf-yasg3,545 ★ · -1
| Repository | 2026-09-24 | 2026-11-24 |
|---|---|---|
| axnsan12/drf-yasg | 3.5k | 3.5k |
-1 Stars in the last 61 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The problem drf-yasg solves for Django REST Framework projects
A Django REST Framework API does not describe itself. Serializers define fields, views define which methods exist, and routers define paths, but nothing in that code produces a document another tool can read. drf-yasg walks that code and writes a Swagger/OpenAPI 2.0 specification from it. The audience is Django teams whose API is consumed by something that needs a machine-readable contract: code generators, client SDK builders, API gateways, or a documentation page that has to stay in sync with the serializers rather than being edited by hand.
The README's feature list is specific about what gets generated: full support for nested serializers and schemas, response schemas and descriptions, and model definitions that the project describes as compatible with codegen tools. That last point matters more than it sounds. A schema that merely renders in a browser is a documentation artifact; a schema whose definitions are shaped correctly is an input to swagger-codegen and similar generators. drf-yasg targets the second case.
How drf-yasg builds a schema from views and serializers
The mechanism is a schema view plus a generator. get_schema_view returns a SchemaView bound to an OpenAPISchemaGenerator subclass, and the generator inspects the URL configuration and the DRF views behind each route. Serializers supply the field types and nesting; the generator turns them into Swagger definitions and references them from the paths. You do not write the schema by hand; you annotate where the automatic pass is not enough.
The README advertises customization hooks at all points in the spec generation process, which is the honest description of how this kind of tool is used in practice. Automatic extraction handles the common cases and you patch the rest. The output is available as JSON or YAML, and the schema view is cacheable out of the box, with cache_timeout and cache_kwargs passed to Django's cached_page decorator. The UI is not fetched from a CDN: the package bundles swagger-ui and redoc, and the README notes that django.contrib.staticfiles is required in INSTALLED_APPS for serving their css and js files.
Versioning support is narrower than the feature list suggests. The README states that URLPathVersioning and NamespaceVersioning are supported and that other DRF or custom versioning schemes are not currently supported. If your API versions through a custom header or an Accept parameter, the generated paths will not reflect it.
Installing drf-yasg and serving a first schema
Installation is from PyPI. The README gives the command and notes that the built-in validation machinery needs an extra requirement set, so the validation extra is only worth adding if you intend to run swagger-spec-validator over the output.
pip install --upgrade drf-yasg
pip install --upgrade drf-yasg[validation]The second command pulls in the extra packages the README associates with the validation mechanisms. If you skip it, the validators option on the schema view has nothing to run.
Registration happens in settings.py. drf_yasg goes into INSTALLED_APPS alongside django.contrib.staticfiles, which the README marks as required for serving swagger-ui's css and js files.
INSTALLED_APPS = [
...
'django.contrib.staticfiles',
'drf_yasg',
...
]The URL wiring uses get_schema_view with an openapi.Info object carrying the title, default_version, description, contact and license fields. The README's example passes public=True and permission_classes=(permissions.AllowAny,), which exposes the schema to anonymous callers. That is convenient during development and worth reconsidering before deployment, since the schema enumerates every endpoint you expose.
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from rest_framework import permissions
schema_view = get_schema_view(
openapi.Info(title="Snippets API", default_version='v1'),
public=True,
permission_classes=(permissions.AllowAny,),
)Adding the three routes from the README produces four endpoints: a JSON view at /swagger.json, a YAML view at /swagger.yaml, a swagger-ui page at /swagger/, and a ReDoc page at /redoc/. The cache_timeout argument is passed on the view methods, and the README's example sets it to 0 to disable caching while you iterate.
urlpatterns = [
path('swagger.<format>/', 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'),
]Open /swagger/ in a browser and you should see the swagger-ui renderer populated from your routers. Open /swagger.json and you get the raw specification, which is the artifact to hand to a codegen tool.
Where drf-yasg stops: OpenAPI 2.0 only
The single limitation that decides most evaluations is stated plainly in the README: drf-yasg is unlikely to soon, if ever, get support for OpenAPI 3.0. This is not a backlog item that will land next quarter. The README frames 3.0 as offering considerably more flexibility in the types of API that can be described, and positions the project as staying on 2.0.
That has practical consequences. Specifications that use oneOf, anyOf, nullable as a first-class keyword, or request body variants beyond the 2.0 model cannot be expressed. If your organization has standardized on 3.0 tooling, drf-yasg produces a document those tools will reject or need to downgrade. The bundled swagger-ui version in package.json is 5.x, which renders 2.0 fine, but the UI version does not change the specification version.
The support policy is the second constraint. The README states that only the latest version of drf-yasg is supported, that support of old versions is dropped immediately with the release of a new version, and that issues should not be filed before upgrading to the latest release. For a team that pins dependencies for long release cycles, this means pinning drf-yasg also means accepting that a bug fix arrives as a version bump rather than a backport. Removed features usually go through a deprecation cycle of a few minor releases, according to the README, but that is the exception rather than the rule for support.
drf-yasg compared with drf-spectacular
The README names the alternative itself: drf-spectacular, described there as an actively maintained new library that shares most of the goals of this project while working with OpenAPI 3.0 schemas. The difference in approach is the specification version and what follows from it. drf-yasg emits 2.0 and therefore cannot describe the constructs 3.0 added. drf-spectacular emits 3.0, which the README credits with considerably more flexibility in the types of API that can be described.
For an existing project whose consumers already parse 2.0, migration buys flexibility the consumers may not use. For a new project, the README's own advice is to take a look at drf-spectacular before adding Swagger support. The other practical difference is the maintenance posture: drf-yasg's last push was on 2026-09-07 and its most recent release listed is 1.21.15 from 2026-02-24, so the project is not dormant, but the README is explicit that 3.0 is not on the roadmap. Choosing drf-yasg is choosing a specification version, not just a library.
Maintenance, releases and the licence question
The repository was last pushed on 2026-09-07 and is not archived. Releases in the recent list are 1.21.15 on 2026-02-24, 1.21.14 on 2026-01-15 and 1.21.12 on 2026-01-14. The README's support statement is the operative fact for upgrade planning: only the latest version is supported, and support for old versions is dropped immediately upon a new release. A team that stays several releases behind is, by the project's own terms, unsupported.
Versioning is handled by setuptools-scm. setup.py reads the version from source control metadata and, when that fails outside CI, falls back to a dummy version of the form 1!0.0.0.dev0+noscm.<timestamp> rather than failing the build. On CI the script raises instead, so a misconfigured build cannot publish a dummy version to PyPI. That fallback is worth knowing about if you build from a source archive that has no git metadata: the installed package will report a placeholder version.
The licence metadata is inconsistent across files. pyproject.toml declares license = "BSD-3-Clause" and points license-files at LICENSE.rst, while the repository's licence identifier is reported as NOASSERTION. The README's quickstart example also passes a BSD License name into the openapi.License object, but that is the API's declared licence in the generated document, not the licence of drf-yasg itself. If the licence matters to your legal review, read LICENSE.rst directly rather than relying on the classifier. This is a description of what the files say, not legal advice.
Editorial conclusion
Adopt drf-yasg if your consumers already work against Swagger 2.0, if you need the swagger-ui and ReDoc views served from Django, or if you depend on the caching and customization hooks described in the README. Do not adopt it for a new project that needs OpenAPI 3.0, since the README states 3.0 support is unlikely to arrive. Before committing, verify your DRF versioning scheme, because only URLPathVersioning and NamespaceVersioning are supported, and check the changelog for the release you install.
Frequently asked questions
What is drf-yasg?
drf-yasg is a Django REST Framework add-on that generates real Swagger/OpenAPI 2.0 specifications from your API code, rather than requiring you to write the schema by hand. It bundles swagger-ui and ReDoc for viewing the result and supports JSON and YAML output.
How to install drf_yasg?
Install it from PyPI with pip install --upgrade drf-yasg, then add 'drf_yasg' to INSTALLED_APPS alongside django.contrib.staticfiles. If you want the built-in validation mechanisms, the README gives pip install --upgrade drf-yasg[validation] as the extra step.
drf yasg vs spectacular: which should I use?
The README itself recommends looking at drf-spectacular for new projects, describing it as an actively maintained library sharing most of drf-yasg's goals while working with OpenAPI 3.0 schemas. drf-yasg stays on OpenAPI 2.0, and the README states 3.0 support is unlikely to arrive.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/axnsan12-drf-yasg)Star history chart for your README
[](https://hysenlabs.com/projects/axnsan12-drf-yasg)Was this useful?