{"id":13633855,"url":"https://github.com/tfranzel/drf-spectacular","last_synced_at":"2025-05-13T17:04:14.965Z","repository":{"id":38328916,"uuid":"244234763","full_name":"tfranzel/drf-spectacular","owner":"tfranzel","description":"Sane and flexible OpenAPI 3 schema generation for Django REST framework.","archived":false,"fork":false,"pushed_at":"2025-05-05T09:38:40.000Z","size":1688,"stargazers_count":2583,"open_issues_count":185,"forks_count":282,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-06T16:17:00.739Z","etag":null,"topics":["django","documentation-generator","drf","openapi-generator","openapi-specification","openapi3","rest-api","rest-framework","swagger"],"latest_commit_sha":null,"homepage":"https://drf-spectacular.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tfranzel.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-03-01T22:36:54.000Z","updated_at":"2025-05-06T14:30:34.000Z","dependencies_parsed_at":"2022-08-09T03:00:49.466Z","dependency_job_id":"906f8d69-a92a-418b-bf5b-0ad0bbc69043","html_url":"https://github.com/tfranzel/drf-spectacular","commit_stats":{"total_commits":905,"total_committers":98,"mean_commits":9.23469387755102,"dds":0.5723756906077349,"last_synced_commit":"28b858e83e8341c806cc23e7cb09ea1f06b2b357"},"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfranzel%2Fdrf-spectacular","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfranzel%2Fdrf-spectacular/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfranzel%2Fdrf-spectacular/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tfranzel%2Fdrf-spectacular/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tfranzel","download_url":"https://codeload.github.com/tfranzel/drf-spectacular/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253342299,"owners_count":21893558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","documentation-generator","drf","openapi-generator","openapi-specification","openapi3","rest-api","rest-framework","swagger"],"created_at":"2024-08-01T23:00:52.689Z","updated_at":"2025-05-13T17:04:14.954Z","avatar_url":"https://github.com/tfranzel.png","language":"Python","funding_links":[],"categories":["API","Release Features","Third-Party Packages","Packages","Python","OpenAPI Utilities","Best Django Admin Interface Resources","APIs \u0026 REST"],"sub_categories":["APIs","Documentation","**🖥️ Django REST Framework \u0026 API-Related Packages**"],"readme":"===============\ndrf-spectacular\n===============\n\n|build-status| |codecov| |docs| |pypi-version| |pypi-dl|\n\nSane and flexible `OpenAPI`_ (`3.0.3`_ \u0026 `3.1`_) schema generation for `Django REST framework`_.\n\nThis project has 3 goals:\n    1. Extract as much schema information from DRF as possible.\n    2. Provide flexibility to make the schema usable in the real world (not only toy examples).\n    3. Generate a schema that works well with the most popular client generators.\n\nThe code is a heavily modified fork of the\n`DRF OpenAPI generator \u003chttps://github.com/encode/django-rest-framework/blob/master/rest_framework/schemas/openapi.py/\u003e`_,\nwhich is/was lacking all of the below listed features.\n\nFeatures\n    - Serializers modelled as components. (arbitrary nesting and recursion supported)\n    - `@extend_schema \u003chttps://drf-spectacular.readthedocs.io/en/latest/drf_spectacular.html#drf_spectacular.utils.extend_schema\u003e`_ decorator for customization of APIView, Viewsets, function-based views, and ``@action``\n        - additional parameters\n        - request/response serializer override (with status codes)\n        - polymorphic responses either manually with ``PolymorphicProxySerializer`` helper or via ``rest_polymorphic``'s PolymorphicSerializer)\n        - ... and more customization options\n    - Authentication support (DRF natives included, easily extendable)\n    - Custom serializer class support (easily extendable)\n    - `SerializerMethodField() \u003chttps://drf-spectacular.readthedocs.io/en/latest/customization.html#step-3-extend-schema-field-and-type-hints\u003e`_ type via type hinting or ``@extend_schema_field``\n    - i18n support\n    - Tags extraction\n    - Request/response/parameter examples\n    - Description extraction from ``docstrings``\n    - Vendor specification extensions (``x-*``) in info, operations, parameters, components, and security schemes\n    - Sane fallbacks\n    - Sane ``operation_id`` naming (based on path)\n    - Schema serving with ``SpectacularAPIView`` (Redoc and Swagger-UI views are also available)\n    - Optional input/output serializer component split\n    - Callback operations\n    - OpenAPI 3.1 support (via setting ``OAS_VERSION``)\n    - Included support for:\n        - `django-polymorphic \u003chttps://github.com/django-polymorphic/django-polymorphic\u003e`_ / `django-rest-polymorphic \u003chttps://github.com/apirobot/django-rest-polymorphic\u003e`_\n        - `SimpleJWT \u003chttps://github.com/jazzband/djangorestframework-simplejwt\u003e`_\n        - `DjangoOAuthToolkit \u003chttps://github.com/jazzband/django-oauth-toolkit\u003e`_\n        - `djangorestframework-jwt \u003chttps://github.com/jpadilla/django-rest-framework-jwt\u003e`_ (tested fork `drf-jwt \u003chttps://github.com/Styria-Digital/django-rest-framework-jwt\u003e`_)\n        - `dj-rest-auth \u003chttps://github.com/iMerica/dj-rest-auth\u003e`_ (maintained fork of `django-rest-auth \u003chttps://github.com/Tivix/django-rest-auth\u003e`_)\n        - `djangorestframework-camel-case \u003chttps://github.com/vbabiy/djangorestframework-camel-case\u003e`_ (via postprocessing hook ``camelize_serializer_fields``)\n        - `django-filter \u003chttps://github.com/carltongibson/django-filter\u003e`_\n        - `drf-nested-routers \u003chttps://github.com/alanjds/drf-nested-routers\u003e`_\n        - `djangorestframework-recursive \u003chttps://github.com/heywbj/django-rest-framework-recursive\u003e`_\n        - `djangorestframework-dataclasses \u003chttps://github.com/oxan/djangorestframework-dataclasses\u003e`_\n        - `django-rest-framework-gis \u003chttps://github.com/openwisp/django-rest-framework-gis\u003e`_\n        - `Pydantic (\u003e=2.0) \u003chttps://github.com/pydantic/pydantic\u003e`_\n\n\nFor more information visit the `documentation \u003chttps://drf-spectacular.readthedocs.io/\u003e`_.\n\nLicense\n-------\n\nProvided by `T. Franzel \u003chttps://github.com/tfranzel\u003e`_. `Licensed under 3-Clause BSD \u003chttps://github.com/tfranzel/drf-spectacular/blob/master/LICENSE\u003e`_.\n\nRequirements\n------------\n\n-  Python \u003e= 3.7\n-  Django (2.2, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1, 5.2)\n-  Django REST Framework (3.10.3, 3.11, 3.12, 3.13, 3.14, 3.15)\n\nInstallation\n------------\n\nInstall using ``pip``\\ ...\n\n.. code:: bash\n\n    $ pip install drf-spectacular\n\nthen add drf-spectacular to installed apps in ``settings.py``\n\n.. code:: python\n\n    INSTALLED_APPS = [\n        # ALL YOUR APPS\n        'drf_spectacular',\n    ]\n\n\nand finally register our spectacular AutoSchema with DRF.\n\n.. code:: python\n\n    REST_FRAMEWORK = {\n        # YOUR SETTINGS\n        'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',\n    }\n\ndrf-spectacular ships with sane `default settings \u003chttps://drf-spectacular.readthedocs.io/en/latest/settings.html\u003e`_\nthat should work reasonably well out of the box. It is not necessary to\nspecify any settings, but we recommend to specify at least some metadata.\n\n.. code:: python\n\n    SPECTACULAR_SETTINGS = {\n        'TITLE': 'Your Project API',\n        'DESCRIPTION': 'Your project description',\n        'VERSION': '1.0.0',\n        'SERVE_INCLUDE_SCHEMA': False,\n        # OTHER SETTINGS\n    }\n\n.. _self-contained-ui-installation:\n\nSelf-contained UI installation\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nCertain environments have no direct access to the internet and as such are unable\nto retrieve Swagger UI or Redoc from CDNs. `drf-spectacular-sidecar`_ provides\nthese static files as a separate optional package. Usage is as follows:\n\n.. code:: bash\n\n    $ pip install drf-spectacular[sidecar]\n\n.. code:: python\n\n    INSTALLED_APPS = [\n        # ALL YOUR APPS\n        'drf_spectacular',\n        'drf_spectacular_sidecar',  # required for Django collectstatic discovery\n    ]\n    SPECTACULAR_SETTINGS = {\n        'SWAGGER_UI_DIST': 'SIDECAR',  # shorthand to use the sidecar instead\n        'SWAGGER_UI_FAVICON_HREF': 'SIDECAR',\n        'REDOC_DIST': 'SIDECAR',\n        # OTHER SETTINGS\n    }\n\n\nRelease management\n^^^^^^^^^^^^^^^^^^\n\n*drf-spectacular* deliberately stays below version *1.x.x* to signal that every\nnew version may potentially break you. For production we strongly recommend pinning the\nversion and inspecting a schema diff on update.\n\nWith that said, we aim to be extremely defensive w.r.t. breaking API changes. However,\nwe also acknowledge the fact that even slight schema changes may break your toolchain,\nas any existing bug may somehow also be used as a feature.\n\nWe define version increments with the following semantics. *y-stream* increments may contain\npotentially breaking changes to both API and schema. *z-stream* increments will never break the\nAPI and may only contain schema changes that should have a low chance of breaking you.\n\n\nTake it for a spin\n------------------\n\nGenerate your schema with the CLI:\n\n.. code:: bash\n\n    $ ./manage.py spectacular --color --file schema.yml\n    $ docker run -p 8080:8080 -e SWAGGER_JSON=/schema.yml -v ${PWD}/schema.yml:/schema.yml swaggerapi/swagger-ui\n\nIf you also want to validate your schema add the ``--validate`` flag. Or serve your schema directly\nfrom your API. We also provide convenience wrappers for ``swagger-ui`` or ``redoc``.\n\n.. code:: python\n\n    from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView\n    urlpatterns = [\n        # YOUR PATTERNS\n        path('api/schema/', SpectacularAPIView.as_view(), name='schema'),\n        # Optional UI:\n        path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),\n        path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),\n    ]\n\nUsage\n-----\n\n*drf-spectacular* works pretty well out of the box. You might also want to set some metadata for your API.\nJust create a ``SPECTACULAR_SETTINGS`` dictionary in your ``settings.py`` and override the defaults.\nHave a look at the `available settings \u003chttps://drf-spectacular.readthedocs.io/en/latest/settings.html\u003e`_.\n\nThe toy examples do not cover your cases? No problem, you can heavily customize how your schema will be rendered.\n\nCustomization by using ``@extend_schema``\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nMost customization cases should be covered by the ``extend_schema`` decorator. We usually get\npretty far with specifying ``OpenApiParameter`` and splitting request/response serializers, but\nthe sky is the limit.\n\n.. code:: python\n\n    from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiExample\n    from drf_spectacular.types import OpenApiTypes\n\n    class AlbumViewset(viewset.ModelViewset):\n        serializer_class = AlbumSerializer\n\n        @extend_schema(\n            request=AlbumCreationSerializer,\n            responses={201: AlbumSerializer},\n        )\n        def create(self, request):\n            # your non-standard behaviour\n            return super().create(request)\n\n        @extend_schema(\n            # extra parameters added to the schema\n            parameters=[\n                OpenApiParameter(name='artist', description='Filter by artist', required=False, type=str),\n                OpenApiParameter(\n                    name='release',\n                    type=OpenApiTypes.DATE,\n                    location=OpenApiParameter.QUERY,\n                    description='Filter by release date',\n                    examples=[\n                        OpenApiExample(\n                            'Example 1',\n                            summary='short optional summary',\n                            description='longer description',\n                            value='1993-08-23'\n                        ),\n                        ...\n                    ],\n                ),\n            ],\n            # override default docstring extraction\n            description='More descriptive text',\n            # provide Authentication class that deviates from the views default\n            auth=None,\n            # change the auto-generated operation name\n            operation_id=None,\n            # or even completely override what AutoSchema would generate. Provide raw Open API spec as Dict.\n            operation=None,\n            # attach request/response examples to the operation.\n            examples=[\n                OpenApiExample(\n                    'Example 1',\n                    description='longer description',\n                    value=...\n                ),\n                ...\n            ],\n        )\n        def list(self, request):\n            # your non-standard behaviour\n            return super().list(request)\n\n        @extend_schema(\n            request=AlbumLikeSerializer,\n            responses={204: None},\n            methods=[\"POST\"]\n        )\n        @extend_schema(description='Override a specific method', methods=[\"GET\"])\n        @action(detail=True, methods=['post', 'get'])\n        def set_password(self, request, pk=None):\n            # your action behaviour\n            ...\n\nMore customization\n^^^^^^^^^^^^^^^^^^\n\nStill not satisfied? You want more! We still got you covered.\nVisit `customization \u003chttps://drf-spectacular.readthedocs.io/en/latest/customization.html\u003e`_ for more information.\n\n\nTesting\n-------\n\nInstall testing requirements.\n\n.. code:: bash\n\n    $ pip install -r requirements.txt\n\nRun with runtests.\n\n.. code:: bash\n\n    $ ./runtests.py\n\nYou can also use the excellent `tox`_ testing tool to run the tests\nagainst all supported versions of Python and Django. Install tox\nglobally, and then simply run:\n\n.. code:: bash\n\n    $ tox\n\n.. _Django REST framework: https://www.django-rest-framework.org/\n.. _OpenAPI: https://swagger.io/\n.. _3.0.3: https://spec.openapis.org/oas/v3.0.3\n.. _3.1: https://spec.openapis.org/oas/v3.1.0\n.. _tox: https://tox.wiki/\n.. _drf-spectacular-sidecar: https://github.com/tfranzel/drf-spectacular-sidecar\n\n.. |build-status| image:: https://github.com/tfranzel/drf-spectacular/actions/workflows/ci.yml/badge.svg\n   :target: https://github.com/tfranzel/drf-spectacular/actions/workflows/ci.yml\n.. |pypi-version| image:: https://img.shields.io/pypi/v/drf-spectacular.svg\n   :target: https://pypi.org/project/drf-spectacular/\n.. |codecov| image:: https://codecov.io/gh/tfranzel/drf-spectacular/branch/master/graph/badge.svg\n   :target: https://codecov.io/gh/tfranzel/drf-spectacular\n.. |docs| image:: https://readthedocs.org/projects/drf-spectacular/badge/\n   :target: https://drf-spectacular.readthedocs.io/\n.. |pypi-dl| image:: https://img.shields.io/pypi/dm/drf-spectacular\n   :target: https://pypi.org/project/drf-spectacular/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftfranzel%2Fdrf-spectacular","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftfranzel%2Fdrf-spectacular","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftfranzel%2Fdrf-spectacular/lists"}