{"id":1468,"library":"drf-spectacular","title":"DRF Spectacular","description":"DRF Spectacular is a powerful and flexible OpenAPI 3 schema generation tool for Django REST Framework. It automates API documentation, offering robust support for Swagger UI and ReDoc. Actively maintained, it receives frequent updates, typically every 1-2 months, incorporating new features, bug fixes, and compatibility with the latest Django and DRF versions.","status":"active","version":"0.29.0","language":"en","source_language":"en","source_url":"https://github.com/tfranzel/drf-spectacular","tags":["django","drf","openapi","swagger","redoc","documentation","api-documentation"],"install":[{"cmd":"pip install drf-spectacular","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for any Django project.","package":"Django","optional":false},{"reason":"Required as it extends Django REST Framework.","package":"djangorestframework","optional":false},{"reason":"Used for YAML schema generation; C version provides performance benefits.","package":"PyYAML","optional":true},{"reason":"Required if Pydantic models are used in DRF serializers.","package":"Pydantic","optional":true}],"imports":[{"note":"Views are imported from `drf_spectacular.views` module.","wrong":"from drf_spectacular.urls import SpectacularAPIView","symbol":"SpectacularAPIView","correct":"from drf_spectacular.views import SpectacularAPIView"},{"note":"Views are imported from `drf_spectacular.views` module.","symbol":"SpectacularSwaggerView","correct":"from drf_spectacular.views import SpectacularSwaggerView"},{"note":"Views are imported from `drf_spectacular.views` module.","symbol":"SpectacularRedocView","correct":"from drf_spectacular.views import SpectacularRedocView"},{"note":"Decorators and utilities are found in `drf_spectacular.utils`.","symbol":"extend_schema","correct":"from drf_spectacular.utils import extend_schema"},{"note":"Decorators and utilities are found in `drf_spectacular.utils`.","symbol":"OpenApiParameter","correct":"from drf_spectacular.utils import OpenApiParameter"}],"quickstart":{"code":"import os\nfrom django.urls import path, include\nfrom drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView\n\n# --- In your Django settings.py ---\n# INSTALLED_APPS = [\n#     # ...\n#     'rest_framework',\n#     'drf_spectacular',\n#     # ...\n# ]\n#\n# SPECTACULAR_SETTINGS = {\n#     'TITLE': os.environ.get('DRF_SPECTACULAR_TITLE', 'Your Project API'),\n#     'DESCRIPTION': os.environ.get('DRF_SPECTACULAR_DESCRIPTION', 'Your project description'),\n#     'VERSION': os.environ.get('DRF_SPECTACULAR_VERSION', '1.0.0'),\n#     'SERVE_INCLUDE_SCHEMA': False, # Keep off for production, serve via SpectacularAPIView\n#     'SWAGGER_UI_SETTINGS': {\n#         'deepLinking': True,\n#         'displayRequestDuration': True,\n#     },\n# }\n\n# --- In your Django urls.py ---\nurlpatterns = [\n    path('api/schema/', SpectacularAPIView.as_view(), name='schema'),\n    # Optional UI: path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),\n    # Optional UI: path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),\n    # path('api/', include('your_app.urls')), # Example for your API endpoints\n]\n\n# To run a minimal example (requires Django setup)\n# from django.conf import settings\n# if not settings.configured:\n#     settings.configure(\n#         INSTALLED_APPS=['django.contrib.auth', 'django.contrib.contenttypes', 'rest_framework', 'drf_spectacular'],\n#         SPECTACULAR_SETTINGS={'TITLE': 'Test API'},\n#         ROOT_URLCONF=__name__,\n#         DEBUG=True\n#     )\n# This is a runnable snippet illustrating the `urls.py` config for drf-spectacular.","lang":"python","description":"To integrate DRF Spectacular, add `drf_spectacular` to your `INSTALLED_APPS` and define `SPECTACULAR_SETTINGS` in your `settings.py`. Then, include the schema and UI views in your `urls.py`. The `SpectacularAPIView` serves the raw OpenAPI schema, while `SpectacularSwaggerView` and `SpectacularRedocView` provide interactive documentation UIs."},"warnings":[{"fix":"After upgrading to 0.28.0+, thoroughly test your API schema generation if you use Pydantic models. Adjust any client-side code that relies on specific Pydantic-derived schema structures.","message":"Pydantic users might see a slightly different schema output due to changes in the serialization method. Review generated schemas carefully after upgrading.","severity":"breaking","affected_versions":"0.28.0 and later"},{"fix":"If you have a custom `postprocess_schema_enums` function, ensure it also calls or manually implements the logic of `postprocess_schema_enum_id_removal` to clean up temporary enum IDs introduced for OpenAPI 3.1 compatibility.","message":"With the official support for OpenAPI 3.1 and Pydantic>=2, if you use a custom `postprocess_schema_enums` function, you might need to manually add `postprocess_schema_enum_id_removal` to remove temporary IDs.","severity":"breaking","affected_versions":"0.27.0 and later"},{"fix":"Ensure your project is running on Python 3.7 or newer. Upgrade your Python environment if necessary.","message":"Python 3.6 support has been officially removed due to upstream library breakage. Attempts to use drf-spectacular on Python 3.6 will likely fail.","severity":"gotcha","affected_versions":"0.27.2 and later"},{"fix":"Upgrade to `drf-spectacular` version `0.29.0` or newer to benefit from the memory leak fix. Regular schema regeneration might be needed to mitigate effects in older versions.","message":"Versions prior to 0.29.0 contained a memory leak during schema generation, particularly noticeable with large or complex APIs.","severity":"gotcha","affected_versions":"Before 0.29.0"},{"fix":"Apply the `@extend_schema_serializer(many=False)` decorator or use the `drf_spectacular.utils.forced_singular_serializer` helper around your serializer if it's being misinterpreted as a list endpoint.","message":"For API endpoints that are serializers marked `many=False` but are incorrectly inferred as lists in the OpenAPI schema, the `forced_singular_serializer` helper function is available.","severity":"gotcha","affected_versions":"0.26.5 and later"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}