Django API Versioning
Version your Django API by endpoint, not by duplicating URL patterns. Register a view once; unchanged routes carry forward to later API versions, and a newer declaration replaces the implementation from that version onward.
Explore Django API Versioning — documentation, examples, and interactive playground · Install django-api-versioning from PyPI
See how it works
Install the package and Django REST Framework:
pip install django-api-versioning djangorestframework
Declare only the versions where an endpoint's behavior changes:
from rest_framework.response import Response
from rest_framework.views import APIView
from django_api_versioning import endpoint
@endpoint("orders/", version=1, view_name="order-list")
class OrderListV1(APIView):
def get(self, request):
return Response({"total": "19.99"})
@endpoint("orders/", version=2, view_name="order-list")
class OrderListV2(APIView):
def get(self, request):
return Response({"total": 1999, "currency": "USD"})
With API_MAX_VERSION = 3, the generated routes are:
| Request | View |
|---|---|
GET /api/v1/orders/ |
OrderListV1 |
GET /api/v2/orders/ |
OrderListV2 |
GET /api/v3/orders/ |
OrderListV2 |
The v1 view serves v1 until another declaration replaces it. The v2 view then serves v2 and v3. You write a new view when the endpoint changes—not another copy of every unchanged route.
For the complete setup, including Django settings and URL configuration, see the Django API Versioning getting-started guide.
What problem does it solve?
In a growing API, only some endpoints change between releases. Manually maintaining a separate URL configuration for every version can repeat registrations and obscure which implementation handles each version.
Django API Versioning makes that mapping explicit with @endpoint:
- Forward route inheritance:
version=1registers the endpoint from v1 throughAPI_MAX_VERSION. - Version-specific replacement: a v2 declaration takes over from v2 onward; earlier versions retain the v1 implementation.
- Explicit registration: use
versions=[...]orver_range(...)when an endpoint should exist only in selected versions. - Visibility: inspect the generated route matrix with
check_versionsand test it withassert_version_matrix().
This is inheritance of route registrations, not automatic backward compatibility. Your application remains responsible for response schemas, business behavior, and compatibility tests.
Why use it with Django REST Framework?
DRF already provides versioning schemes to identify the requested API version, for example through request.version. This package solves a related but different problem: mapping versioned URL paths to specific view implementations and carrying unchanged registrations forward.
Use DRF's built-in versioning when request-version identification is all you need. Use this package when you want declarative version-to-view routing and an inspectable route matrix. They can be used together; this package does not automatically populate request.version.
DRF is optional. The package also supports Django function-based and class-based views. For a Django-only project, install just:
pip install django-api-versioning
Quick configuration
Add the package (and DRF, if used) to INSTALLED_APPS and configure the supported version range:
# settings.py
INSTALLED_APPS = [
"rest_framework", # omit when using Django-native views only
"django_api_versioning",
]
API_MIN_VERSION = 1
API_MAX_VERSION = 3
# API_BASE_PATH defaults to "api/v{version}/"
Import modules containing endpoint declarations before including the generated patterns:
# project/urls.py
from django.urls import include, path
from orders import views as _order_views # noqa: F401
from django_api_versioning.urls import urlpatterns as api_urlpatterns
urlpatterns = [
path("", include(api_urlpatterns)),
]
Run the route-matrix check:
python manage.py check_versions
Registration options
| Declaration | Routes created |
|---|---|
@endpoint("orders/", version=2) |
v2 through API_MAX_VERSION |
@endpoint("orders/", versions=[1, 3, 5]) |
Only v1, v3, and v5 |
@endpoint("health/") |
One unversioned route |
For an inclusive range, use ver_range(1, 3). Other APIs include api_reverse() for version-aware URL reversal and assert_version_matrix() for regression tests.
See the versioning contract for exact URL construction, import order, collision precedence, validation, and edge cases.
DRF ViewSet boundary
A DRF ViewSet or ModelViewSet cannot be passed directly to @endpoint, because as_view() requires an action mapping. You can register a configured callable for an individual route, but this does not create the full router-managed set of list, detail, and custom-action routes. Use DRF's DefaultRouter or SimpleRouter when you need standard ViewSet routing.
See ViewSet support and limitations.
Requirements
- Python 3.10+
- Django 4.2+
- Django REST Framework is optional.
The configured CI matrix covers selected combinations of Python 3.10–3.15 and Django 4.2, 5.2, 6.0, and 6.1. See tox.ini for configured environments and GitHub Actions for results tied to a specific commit.
Upgrading to 1.0.0
Version 1.0.0 tightened API lifecycle configuration and changed the Deprecation response header format. If you use API_VERSION_LIFECYCLE:
- Every entry must have a
statusofactive,deprecated, orretired. - A deprecated version must define
deprecated_atas an ISO 8601 date or datetime. - A retired version must define a
sunsetdate. - The
Deprecationheader now uses the RFC 9745 date-valued Structured Field (for example,Deprecation: @1767225600), not the legacyDeprecation: truevalue.
For migration steps, see the 1.0.0 changelog.
Documentation
- Django API Versioning documentation and interactive playground — overview, examples, lifecycle demonstration, and guides.
- API reference — settings, decorators, URL reversal, validation, and management commands.
- Routing contract — implementation-backed behavior and limitations.
- DRF integration guide.
- Python and Django compatibility guide.
- Documentation source map.
Contributing
Bug reports, corrections, and pull requests are welcome. Read the contribution guidelines and security policy.
License
Released under the MIT License.
Metadata
Release files for django-api-versioning 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_api_versioning-1.0.1.tar.gz | 49.7 kB | With provenance | Details for django_api_versioning-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_api_versioning-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for django_api_versioning-1.0.1-py3-none-any.whl |
Total release size: 73.3 kB
Release files / django_api_versioning-1.0.1.tar.gz
| Download URL | django_api_versioning-1.0.1.tar.gz |
|---|---|
| Size | 49.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d1357060658050062062ac2de4a93a1e42d08d7f78c60eb9b003be33b82b45f3
|
|
BLAKE2b-256 checksum How to use checksums |
e31b2029954ed5f68c346718849ec108a29e36e440242568ab8f52f5cb20f84a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / django_api_versioning-1.0.1-py3-none-any.whl
| Download URL | django_api_versioning-1.0.1-py3-none-any.whl |
|---|---|
| Size | 23.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
becb2615024d06ff2de839ea801202f9097961fe2c30cfae57816566e7d4484f
|
|
BLAKE2b-256 checksum How to use checksums |
62eb05317ae1d0871809cd44fe3094a94750638136dac856e577f71ce7f775c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for django-api-versioning 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for django_api_versioning-1.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.