# drf-yasg

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

- **URL**: https://www.freshcrate.ai/projects/drf-yasg
- **Author**: pypi
- **Category**: Frameworks
- **Latest version**: `1.21.15` (2026-04-21)
- **License**: Unknown
- **Source**: https://github.com/axnsan12/drf-yasg
- **Homepage**: https://pypi.org/project/drf-yasg/
- **Language**: Python
- **GitHub**: 3,546 stars, 437 forks
- **Registry**: pypi (`drf-yasg`)
- **Tags**: `codegen`, `django`, `django-rest-framework`, `django-rest-swagger`, `documentation`, `drf`, `drf-openapi`, `drf-yasg`, `pypi`

## Description

.. role:: python(code)
   :language: python

########################################
drf-yasg - Yet another Swagger generator
########################################

|actions| |nbsp| |codecov| |nbsp| |rtd-badge| |nbsp| |pypi-version| |nbsp| |gitter|

Generate **real** Swagger/OpenAPI 2.0 specifications from a Django Rest Framework API.

Compatible with

- **Django Rest Framework**: 3.13, 3.14, 3.15
- **Django**: 4.0, 4.1, 4.2, 5.0, 5.1, 5.2
- **Python**: 3.9, 3.10, 3.11, 3.12, 3.13

Only the latest patch version of each ``major.minor`` series of Python, Django and Django REST Framework is supported.

**Only the latest version of drf-yasg is supported.** Support of old versions is dropped immediately with the release
of a new version. Please do not create issues before upgrading to the latest release available at the time. Regression
reports are accepted and will be resolved with a new release as quickly as possible. Removed features will usually go
through a deprecation cycle of a few minor releases.

Resources:

* `Sources <https://github.com/axnsan12/drf-yasg>`_
* `Documentation <https://drf-yasg.readthedocs.io>`_
* `Changelog <https://drf-yasg.readthedocs.io/en/stable/changelog.html>`_
* `Discussion <https://app.gitter.im/#/room/#drf-yasg:gitter.im>`_

.. image:: https://img.shields.io/badge/live%20demo-blue?style=for-the-badge&logo=django
   :target: https://drf-yasg.com
   :alt: Live Demo

****************
OpenAPI 3.0 note
****************

If you are looking to add Swagger/OpenAPI support to a new project you might want to take a look at
`drf-spectacular <https://github.com/tfranzel/drf-spectacular>`_, which is an actively maintained new library that
shares most of the goals of this project, while working with OpenAPI 3.0 schemas.

OpenAPI 3.0 provides a lot more flexibility than 2.0 in the types of API that can be described.
``drf-yasg`` is unlikely to soon, if ever, get support for OpenAPI 3.0.


********
Features
********

- full support for nested Serializers and Schemas
- response schemas and descriptions
- model definitions compatible with codegen tools
- customization hooks at all points in the spec generation process
- JSON and YAML format for spec
- bundles latest version of
  `swagger-ui <https://github.com/swagger-api/swagger-ui>`_ and
  `redoc <https://github.com/Rebilly/ReDoc>`_ for viewing the generated documentation
- schema view is cacheable out of the box
- generated Swagger schema can be automatically validated by
  `swagger-spec-validator <https://github.com/Yelp/swagger_spec_validator>`_
- supports Django REST Framework API versioning with ``URLPathVersioning`` and ``NamespaceVersioning``; other DRF
  or custom versioning schemes are not currently supported

.. figure:: https://raw.githubusercontent.com/axnsan12/drf-yasg/1.0.2/screenshots/redoc-nested-response.png
   :width: 100%
   :figwidth: image
   :alt: redoc screenshot

   **Fully nested request and response schemas.**

.. figure:: https://raw.githubusercontent.com/axnsan12/drf-yasg/1.0.2/screenshots/swagger-ui-list.png
   :width: 100%
   :figwidth: image
   :alt: swagger-ui screenshot

   **Choose between redoc and swagger-ui.**

.. figure:: https://raw.githubusercontent.com/axnsan12/drf-yasg/1.0.2/screenshots/swagger-ui-models.png
   :width: 100%
   :figwidth: image
   :alt: model definitions screenshot

   **Real Model definitions.**


*****************
Table of contents
*****************

.. contents::
   :depth: 4

*****
Usage
*****

0. Installation
===============

The preferred installation method is directly from pypi:

.. code:: console

   pip install --upgrade drf-yasg

Additionally, if you want to use the built-in validation mechanisms (see `4. Validation`_), you need to install
some extra requirements:

.. code:: console

   pip install --upgrade drf-yasg[validation]

.. _readme-quickstart:

1. Quickstart
=============

In ``settings.py``:

.. code:: python

   INSTALLED_APPS = [
      ...
      'django.contrib.staticfiles',  # required for serving swagger ui's css/js files
      'drf_yasg',
      ...
   ]

In ``urls.py``:

.. code:: python

   ...
   from django.urls import 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="Snippets 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 = [
      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=

## Recent releases

| Version | Date | Urgency | Changes |
| --- | --- | --- | --- |
| `1.21.15` | 2026-04-21 | Low | Imported from PyPI (1.21.15) |
| `1.21.14` | 2026-01-15 | Low | **FIXED:** Fix missing swagger-ui sourcemaps (#950) |
| `1.21.12` | 2026-01-14 | Low | **FIXED:** Bring the bundled swagger ui up to date (#944) **IMPROVED:** Update the logout button to use a POST request. (#945) **ADDED:** Add a live demo domain (#946) **ADDED:** Handle annotations that are not available at runtime (#941) |
| `1.21.11` | 2025-09-26 | Low | **FIXED:** Fix list views with parameters in last path segment not named "list" views (#917) **ADDED:** Allow overriding produces/consumes with @swagger_auto_schema decorator (#916) **FIXED:** Fix filter parameters not appearing in swagger with django-filter>=25 (#926) **IMPROVED:** Update Python, Django, and DRF versions and packaging configuration (#922) **IMPROVED:** Remove usage of pkg_resources (#928) **FIXED:** Fix call_view_method warning to include the method name again (#923) **AD |
| `1.21.10` | 2025-03-10 | Low | **FIXED:** Fix type hints when using postponed evaluation of annotations (PEP-563) (#840) **IMPROVED:** Update JSON & YAML renderers to not use a "." in their format string (#911) **FIXED:** Fix lint errors when comparing types with == instead of is (#868) **IMPROVED:** Update swagger-ui-dist to address CVE-2021-46708 (#904) |
| `1.21.9` | 2025-03-07 | Low | **ADDED:** Added support for zoneinfo object fields (#908) |
| `1.21.8` | 2024-10-17 | Low | **ADDED:** Python 3.11 and 3.12 support (#891) **FIXED:** Fix pkg_resources version lookups for Python 3.9+ (#891) |
| `1.21.7` | 2024-10-17 | Low | **ADDED:** Added ``drf_yasg.inspectors.query.DrfAPICompatInspector`` (#857) **ADDED:** Added ``DrfAPICompatInspector`` to serve as a replacement ``CoreAPICompatInspector`` (#857) **ADDED:** Allow ``DEFAULT_SPEC_RENDERERS`` default renderers to be overriden in the settings (#857) **FIXED:** Fixed redoc source mapping (#859) |
| `1.21.6` | 2024-10-17 | Low | **IMPROVED:** Remove required coreapi dependency (#854) **IMPROVED:** Feature: Migrate to PyYAML for yaml generator (#845) **FIXED:** Keep path parameters in their given order (#841) **FIXED:** Provide support for enums in codecs (#837) |
| `1.21.5` | 2023-02-09 | Low | **ADDED:** Python 3.10 support  (#818) **DEPRECATED:** Python 3.6 support as it's been deprecated by swagger-spec-validator **FIXED:** RecursiveField resolver (#822) |

## Citation

- HTML: https://www.freshcrate.ai/projects/drf-yasg
- Markdown: https://www.freshcrate.ai/projects/drf-yasg.md
- Dependencies JSON: https://www.freshcrate.ai/api/projects/drf-yasg/deps

_Generated by freshcrate.ai. Indexes pypi releases for AI-agent ecosystem packages._
