Django API Versioning
Django API Versioning is a Python package for version-aware endpoint registration in Django and Django REST Framework (DRF) projects.
Declare an endpoint with @endpoint, and the package generates its versioned URL patterns automatically. You define which view serves each version; the registry handles route registration and forward segment inheritance.
No manually maintained path() declarations for every API version. No need to duplicate unchanged endpoint registrations when a new version is introduced.
"I need to change the response. v1 clients must not break."
You shipped v1 with a string amount. Now the team needs integer cents and an explicit currency code. Changing the existing view would break clients that still depend on the v1 response contract.
With django-api-versioning, register a separate implementation for v2:
# apps/orders/views.py
from django.http import JsonResponse
from django_api_versioning import endpoint
@endpoint("orders/", version=1)
def order_list_v1(request):
return JsonResponse({"total": "19.99"})
@endpoint("orders/", version=2)
def order_list_v2(request):
return JsonResponse({
"total": 1999,
"currency": "USD",
})
Both declarations are registered when apps.orders.views is imported. Make sure endpoint modules are imported before the package's URL patterns are loaded (see Quick Start below).
With API_MAX_VERSION = 5, the resulting routes are:
GET /api/v1/orders/ → {"total": "19.99"}
GET /api/v2/orders/ → {"total": 1999, "currency": "USD"}
GET /api/v3/orders/ → {"total": 1999, "currency": "USD"}
GET /api/v4/orders/ → {"total": 1999, "currency": "USD"}
GET /api/v5/orders/ → {"total": 1999, "currency": "USD"}
Why do v3, v4, and v5 use the v2 implementation?
Because version=2 declares a forward segment: the view serves v2 through API_MAX_VERSION, unless a later declaration for the same route takes over.
When v4 needs its own response contract, add another declaration:
@endpoint("orders/", version=4)
def order_list_v4(request):
return JsonResponse({
"total": 1999,
"currency": "USD",
"status": "confirmed",
})
The resulting mapping becomes:
| Route version | Implementation |
|---|---|
| v1 | order_list_v1 |
| v2 | order_list_v2 |
| v3 | order_list_v2 |
| v4 | order_list_v4 |
| v5 | order_list_v4 |
The v2 implementation continues serving v2 and v3. The v4 implementation serves v4 and v5.
The function name order_list_v2 is a convention for readers. The segment is defined by version=2, not by the function name.
- Package: django-api-versioning on PyPI
- Source code: mojtaba-arvin/django-api-versioning
- License: MIT
Why not just use DRF's built-in versioning?
Django REST Framework provides several versioning schemes:
URLPathVersioningNamespaceVersioningAcceptHeaderVersioningQueryParameterVersioningHostNameVersioning
These mechanisms identify the requested API version according to a configured strategy. They do not, by themselves, define a separate view implementation for every version or generate a complete set of version-specific endpoint registrations.
DRF intentionally leaves the application-specific behavior to the developer.
For example, you can use DRF's version information inside a shared view:
def order_list(request):
if request.version == "1":
return ...
if request.version == "2":
return ...
Or you can maintain separate URL patterns and connect each version to its own view manually.
django-api-versioning addresses the endpoint-registration part of that problem: declare the view for a source version, and let the registry generate the corresponding versioned routes.
| Concern | DRF versioning mechanisms | django-api-versioning |
|---|---|---|
| Identify a requested version | Yes, according to the configured scheme | Routes requests to the registered version-specific view |
| Register version-specific URL patterns | Application configuration required | Generated from endpoint declarations |
| Map different versions to different views | Application code or URL configuration | @endpoint declarations |
| Reuse an implementation for later versions | Application-managed | Forward segment inheritance |
| Register explicit version sets | Application-managed | versions=[...] |
| Register bounded version ranges | Application-managed | ver_range() |
| Register unversioned endpoints in the same registry | Application-managed | Supported |
| Lifecycle headers and sunset enforcement | Application-managed | LifecycleMiddleware |
| Inspect registered route matrix | Application-managed | check_versions |
| Guard routing changes with a snapshot | Application-managed | assert_version_matrix() |
| Reverse a registered route by API version | Django URL reversal | api_reverse() |
| Work without DRF | Django-native schemes and URL configuration | Yes |
The two approaches solve different parts of the problem. You can continue using DRF for serializers, authentication, permissions, request parsing, and response handling while using this package for version-aware endpoint registration.
Important: The package does not automatically set request.version. Its registry maps generated URL patterns to views. If your application also needs DRF's request.version, configure the appropriate DRF versioning scheme separately.
Installation
Install Django API Versioning from PyPI:
pip install django-api-versioning
Requirements:
- Python >= 3.10
- Django >= 4.2
The automated compatibility matrix currently verifies Django 4.2, 5.2, 6.0, and 6.1 across the Python combinations listed in COMPATIBILITY_REPORT.md. Django 5.0 and 5.1 are not part of the verified matrix.
Django REST Framework is optional. The package can be used with Django-native function-based and class-based views without installing DRF.
Quick Start
1. Configure Django settings
Add the package to INSTALLED_APPS and configure the supported version range:
# settings.py
INSTALLED_APPS = [
# ... your other apps
"django_api_versioning",
]
API_BASE_PATH = "api/v{version}/"
API_MIN_VERSION = 1
API_MAX_VERSION = 3
API_BASE_PATH must contain exactly one plain {version} format field. Additional format fields, conversions, and format specifications are rejected.
The default values for API_MIN_VERSION and API_MAX_VERSION are both 1. Set API_MAX_VERSION to the highest route version your project intends to register.
2. Define your API endpoints
Create a view and decorate it with @endpoint.
For example, in your application's views.py:
# your_app/views.py
from rest_framework.response import Response
from rest_framework.views import APIView
from django_api_versioning import endpoint
@endpoint(
"invoices/<int:invoice_id>/",
version=2,
view_name="invoice-detail",
)
class InvoiceDetailView(APIView):
def get(self, request, invoice_id):
return Response({
"id": invoice_id,
"status": "paid",
})
The decorator registers the endpoint when this module is imported.
3. Import endpoint modules and include generated URLs
Django does not automatically import every application's views.py module.
You must import every module containing @endpoint declarations before importing the package's generated URL patterns.
In your project's root URL configuration:
# project/urls.py
from django.urls import include, path
from your_app import views # noqa: F401
from django_api_versioning.urls import urlpatterns as api_urlpatterns
urlpatterns = [
# ... your other URL patterns
path("", include(api_urlpatterns)),
]
Replace your_app with the actual Python package name of your Django application.
If endpoint declarations are spread across multiple modules, import each module before importing api_urlpatterns.
The imported modules do not need to be referenced elsewhere. Their imports execute the decorators and register the endpoints.
Import order matters:
- Import modules containing
@endpointdeclarations. - Import
api_urlpatterns. - Include the generated patterns in your root URL configuration.
You do not need to write individual path() entries for versioned endpoints. The package generates those patterns from the registered declarations.
With the example above, the endpoint is available for v2 and v3:
GET /api/v1/invoices/42/ → 404
GET /api/v2/invoices/42/ → {"id": 42, "status": "paid"}
GET /api/v3/invoices/42/ → {"id": 42, "status": "paid"}
The endpoint was introduced in v2, so it is not registered for v1.
Path converters such as <int:pk> and <slug:name> are supported by the generated Django path() patterns.
Before and after
Consider an API with 150 endpoints and five supported versions.
Some endpoints change their implementation between versions. Others remain unchanged and should continue using their existing implementation.
Without django-api-versioning
You maintain the URL patterns for every endpoint and version manually:
# urls.py
from django.urls import path
from . import views
urlpatterns = [
path("api/v1/users/", views.user_list_v1),
path("api/v2/users/", views.user_list_v2),
path("api/v3/users/", views.user_list_v2),
path("api/v4/users/", views.user_list_v4),
path("api/v5/users/", views.user_list_v4),
path("api/v1/orders/", views.order_list),
path("api/v2/orders/", views.order_list),
path("api/v3/orders/", views.order_list),
path("api/v4/orders/", views.order_list),
path("api/v5/orders/", views.order_list),
# Repeat for the remaining endpoints and versions.
]
If all 150 endpoints are registered for all five versions, that means 750 manually maintained URL patterns.
Every new API version requires reviewing the URL configuration, even when many endpoints have not changed.
With django-api-versioning
Declare the implementation at each change point:
# apps/users/views.py
from django_api_versioning import endpoint
@endpoint("users/", version=1)
def user_list_v1(request):
...
@endpoint("users/", version=2)
def user_list_v2(request):
...
@endpoint("users/", version=4)
def user_list_v4(request):
...
# apps/orders/views.py
@endpoint("orders/", version=1)
def order_list(request):
...
The user endpoint has three implementation declarations. The order endpoint has one declaration because its implementation does not change across the configured versions.
With API_MAX_VERSION = 5, the package generates the versioned routes from these declarations.
Import the endpoint modules and include the generated patterns once:
# project/urls.py
from django.urls import include, path
from apps.users import views as _user_views # noqa: F401
from apps.orders import views as _order_views # noqa: F401
from django_api_versioning.urls import urlpatterns as api_urlpatterns
urlpatterns = [
# ... your existing URLs
path("", include(api_urlpatterns)),
]
What changes?
| Concern | Manual URL configuration | django-api-versioning |
|---|---|---|
| Add a new endpoint implementation in v2 | Add a view and URL pattern | Add one @endpoint declaration |
| Keep an unchanged endpoint available in v3 | Add another URL pattern | No additional declaration |
| Change an endpoint in v4 | Update URL configuration and route mappings | Add a v4 declaration |
| Inspect which view serves a version | Review URL configuration | Run check_versions |
| Organize endpoint ownership | Often centralized in urls.py |
Declarations can live with their views |
| URL configuration | One entry per endpoint/version combination | One generated URL include |
For the example above, the user endpoint has three declarations because its implementation changes at v1, v2, and v4. The order endpoint has one declaration because it remains unchanged.
The package reduces repeated route declarations. It does not eliminate the need to implement and test behavior changes.
Inspect the generated routes
Run:
python manage.py check_versions
The command prints the registered route matrix and warns about missing versions within the configured range.
For the example above, the mapping is conceptually:
api/v1/users/:
v1 → user_list_v1
api/v2/users/:
v2 → user_list_v2
api/v3/users/:
v3 → user_list_v2
api/v4/users/:
v4 → user_list_v4
api/v5/users/:
v5 → user_list_v4
api/v1/orders/:
v1 → order_list
api/v2/orders/:
v2 → order_list
api/v3/orders/:
v3 → order_list
api/v4/orders/:
v4 → order_list
api/v5/orders/:
v5 → order_list
The command reports registered routes and gaps. A gap warning is a routing observation; whether a missing version is a problem depends on the intended API contract.
Add a new version without changing unchanged endpoints
Suppose v6 introduces a new users response contract, while orders remain unchanged.
Add a new declaration:
@endpoint("users/", version=6)
def user_list_v6(request):
...
The v6 implementation serves v6 and subsequent configured versions. Earlier user versions keep their existing mappings. The order endpoint requires no new declaration.
Four endpoint registration patterns
Each pattern represents a different API evolution requirement.
1. Segment — introduce an endpoint in v3
from django.http import JsonResponse
from django_api_versioning import endpoint
@endpoint("reports/", version=3)
def report_list(request):
return JsonResponse({"reports": []})
With API_MAX_VERSION = 5:
GET /api/v1/reports/ → 404
GET /api/v2/reports/ → 404
GET /api/v3/reports/ → {"reports": []}
GET /api/v4/reports/ → {"reports": []}
GET /api/v5/reports/ → {"reports": []}
The endpoint did not exist in v1 or v2. Its v3 implementation is reused for later versions until another declaration takes over.
2. Explicit set — v2 and v4 only
from django.http import JsonResponse
from django_api_versioning import endpoint
@endpoint("ranking/", versions=[2, 4])
def ranking(request):
return JsonResponse({"algorithm": "new"})
The endpoint is registered only for the specified versions:
GET /api/v1/ranking/ → 404
GET /api/v2/ranking/ → {"algorithm": "new"}
GET /api/v3/ranking/ → 404
GET /api/v4/ranking/ → {"algorithm": "new"}
GET /api/v5/ranking/ → 404
Use explicit versions when an implementation should be registered only for selected, potentially non-contiguous versions.
3. Bounded range — v1 through v3
from django.http import JsonResponse
from django_api_versioning import endpoint, ver_range
@endpoint("legacy/", versions=ver_range(1, 3))
def legacy_endpoint(request):
return JsonResponse({"deprecated": True})
GET /api/v1/legacy/ → {"deprecated": true}
GET /api/v2/legacy/ → {"deprecated": true}
GET /api/v3/legacy/ → {"deprecated": true}
GET /api/v4/legacy/ → 404
GET /api/v5/legacy/ → 404
ver_range(start, end) returns an inclusive list:
ver_range(1, 3) == [1, 2, 3]
Use it when an endpoint should stop being registered after a particular version.
4. Unversioned — no version prefix
from django.http import JsonResponse
from django_api_versioning import endpoint
@endpoint("health/")
def health_check(request):
return JsonResponse({"status": "ok"})
The endpoint is registered without the versioned API_BASE_PATH prefix.
With the root URL include shown in Quick Start:
GET /health/ → {"status": "ok"}
Unversioned routes are registered at the include prefix, not under the versioned base path.
If you need unversioned and versioned routes under a shared /api/ prefix, configure the base path and URL include accordingly. For example:
# settings.py
API_BASE_PATH = "v{version}/"
# project/urls.py
urlpatterns = [
path("api/", include(api_urlpatterns)),
]
This produces versioned paths such as /api/v1/... and an unversioned path such as /api/health/.
How segments resolve
Consider two declarations for the same route:
from django.http import JsonResponse
from django_api_versioning import endpoint
@endpoint("orders/", version=1)
def order_list_v1(request):
return JsonResponse({"version": 1})
@endpoint("orders/", version=3)
def order_list_v3(request):
return JsonResponse({"version": 3})
With API_MAX_VERSION = 5, the resulting mapping is:
GET /api/v1/orders/ → {"version": 1} # order_list_v1
GET /api/v2/orders/ → {"version": 1} # order_list_v1
GET /api/v3/orders/ → {"version": 3} # order_list_v3
GET /api/v4/orders/ → {"version": 3} # order_list_v3
GET /api/v5/orders/ → {"version": 3} # order_list_v3
The v3 declaration takes over from v3 onward. The v1 implementation continues serving v1 and v2.
This is route-level implementation inheritance. It does not imply Python class inheritance or automatic serializer compatibility.
Reliability tools
check_versions — inspect the registered matrix
python manage.py check_versions
Prints registered routes, their route versions, and the associated callback names. It also warns about missing versions in the configured range.
Use it to inspect the routing result after adding or changing endpoint declarations.
Output interpretation:
The command groups routes by their logical endpoint (the path without versioning), not by physical URL. This means:
users/:
v1 → users_list_v1
v2 → users_list_v2
v3 → users_list_v2
v4 → users_list_v2
Even though physical URLs are /api/v1/users/, /api/v2/users/, etc., the command groups them under the logical endpoint users.
Callback name resolution:
The command resolves callback names intelligently:
- Function-based views: Shows the function name (e.g.,
my_view) - Django View classes: Shows the class name (e.g.,
MyView) - DRF APIView: Shows the class name (e.g.,
MyAPIView) - DRF ViewSet actions: Shows the ViewSet class name (e.g.,
MyViewSet)
Gap detection:
The command warns about missing versions within an endpoint's span:
users:
v1 → users_list_v1
v3 → users_list_v3
[users] v2 is not defined.
It does NOT warn about versions before an endpoint's introduction or after its final declaration:
# No warning for v1 (starts at v2)
# No warning for v4 (ends at v3)
assert_version_matrix — guard routing changes in CI
The package provides a snapshot utility for detecting unintended changes to the registered route matrix.
# tests/test_versions.py
from django_api_versioning.testing import assert_version_matrix
def test_version_matrix():
assert_version_matrix(snapshot=".version_matrix.json")
If the current matrix differs from the snapshot, assert_version_matrix() raises VersionMatrixError with a diff.
To accept an intentional routing change, update the snapshot:
assert_version_matrix(
snapshot=".version_matrix.json",
update=True,
)
The snapshot is created automatically if it does not exist.
Import requirement: Build and compare the matrix only after all modules containing @endpoint declarations have been imported. The registry is populated at module import time.
The matrix checks routing structure only. It does not validate response schemas, serializer behavior, business logic, or backward compatibility of API contracts. Keep request-level and contract tests for those guarantees.
api_reverse — reverse a registered route by version
Use api_reverse() to reverse a route registered by this package:
from django_api_versioning import api_reverse
url = api_reverse("order-list", version=2)
When the same view_name is registered for multiple versions, pass the version to select the exact route.
If only one route is registered for the name, the version can be omitted:
url = api_reverse("health-check")
If multiple routes match and no version is supplied, the function raises AmbiguousVersionError rather than silently selecting one.
To use URL reversal, give the endpoint a view_name:
@endpoint(
"orders/",
version=2,
view_name="order-list",
)
def order_list_v2(request):
...
api_reverse() is intended for package-registered routes. It is not a general replacement for Django's reverse().
Deprecation and sunset headers
Configure lifecycle metadata in Django settings:
# settings.py
API_VERSION_LIFECYCLE = {
1: {"status": "retired", "sunset": "2025-01-01"},
2: {
"status": "deprecated",
"deprecated_at": "2026-01-01T00:00:00+00:00",
"sunset": "2027-06-01",
},
3: {"status": "active"},
}
MIDDLEWARE = [
"django_api_versioning.lifecycle.LifecycleMiddleware",
# ... your other middleware
]
For a version configured as deprecated with a future sunset date, the middleware adds:
Deprecation: @1767225600
Sunset: Tue, 01 Jun 2027 00:00:00 GMT
When a configured sunset date is in the past, the middleware returns:
HTTP/1.1 410 Gone
The expired sunset date triggers the 410 Gone response regardless of the lifecycle status string.
The middleware attempts to identify the request version in this order:
request.versionresolver_match.kwargs["version"]- The version in the request path, extracted using
API_BASE_PATH
This allows the middleware to identify versions from the package's static versioned URL paths even when request.version is not set.
Standards note: Configure deprecated_at as an ISO 8601 date or datetime for deprecated versions. The middleware emits the date-valued Structured Field required by RFC 9745, using @ followed by the Unix timestamp. A deprecated lifecycle entry without a valid deprecated_at is rejected during settings validation. If the value is changed after initialization, the middleware logs a warning and omits Deprecation rather than emitting a non-standard value. Sunset follows the HTTP-date format specified by RFC 8594.
Configuration reference
Django settings
| Setting | Default | Description |
|---|---|---|
API_BASE_PATH |
"api/v{version}/" |
Base path template for versioned routes. Must contain exactly one plain {version} format field and no other format fields. |
API_MIN_VERSION |
1 |
Lowest valid route version. |
API_MAX_VERSION |
1 |
Highest valid route version. |
API_VERSION_LIFECYCLE |
{} |
Per-version lifecycle metadata. |
API_VERSIONING_CHANNELS |
["path"] |
Validated channel configuration; not currently used by the route registry. |
API_EFFECTIVE_VERSION_RESOLVER |
None |
Validated callable configuration; not currently used for route selection. |
API_BASE_PATH is normalized to end with / if necessary.
API_MIN_VERSION and API_MAX_VERSION must be integers, and the minimum cannot exceed the maximum. Boolean values are not accepted as version integers.
@endpoint arguments
| Argument | Type | Default | Purpose |
|---|---|---|---|
postfix (positional) |
str |
Required | Resource path, e.g. "users/" or "users/<int:pk>/". |
version |
int | None |
None |
Registers a forward segment starting at this version. |
versions |
list[int] | None |
None |
Registers only the explicitly specified versions. |
app_name |
str | None |
None |
Optional path segment for grouping. |
view_name |
str | None |
None |
URL name used by api_reverse(). |
Examples:
@endpoint("users/", version=1)
def user_list_v1(request):
...
@endpoint("users/", versions=[1, 3])
def user_list_v1_and_v3(request):
...
@endpoint("users/", versions=ver_range(1, 3))
def user_list_v1_to_v3(request):
...
@endpoint("health/")
def health_check(request):
...
Registration rules:
versionandversionsare mutually exclusive. Providing both raisesVersionRangeError.- If neither is provided, the endpoint is registered as unversioned.
version=Nregisters the endpoint for versionsNthroughAPI_MAX_VERSION.versions=[...]registers the endpoint only for the listed versions.ver_range(start, end)returns an inclusive list of integer versions.- Version identifiers must be integers. Boolean values are rejected.
- A version greater than
API_MAX_VERSIONraisesInvalidVersionError. - A source version below
API_MIN_VERSIONproduces a warning and no routes are registered for that declaration. - Explicit versions below
API_MIN_VERSIONare warned about and skipped.
Collision resolution:
When two declarations produce the same complete route string:
- The declaration with the higher integer
source_versiontakes precedence. - If the source versions are equal, the last registration wins.
- If either source version is
None, the last registration wins.
Avoid relying on import order as an implicit policy when multiple modules declare the same route and source version.
Supported views and ViewSets
The package supports Django function-based views and supported class-based views, including Django REST Framework APIView and generic views.
For class-based views, the registry calls as_view() on the class when creating the URL pattern.
A generic view must implement the HTTP handlers required by its registered route.
ViewSets
A DRF ViewSet class cannot be passed directly to @endpoint as a normal class-based view. Its as_view() method requires an action mapping, while the package invokes as_view() without one.
To register a ViewSet action, pass a pre-configured callable:
from rest_framework.viewsets import ViewSet
from django_api_versioning import endpoint
class MyViewSet(ViewSet):
def list(self, request):
return JsonResponse({})
def create(self, request):
return JsonResponse({})
# ✓ Correct: pass a configured callable
@endpoint("items/", version=1)
def list_items(request):
return MyViewSet.as_view({"get": "list"})(request)
# ✗ Incorrect: class without action mapping
# @endpoint("items/", version=1, MyViewSet) # TypeError!
For standard ViewSet resource routing (list, create, retrieve, update, destroy), use DRF routers separately.
The package does not automatically generate router-style ViewSet routes.
Known limitations and scope
django-api-versioning focuses on version-aware endpoint registration and routing.
It does not:
- Automatically make response schemas backward-compatible.
- Select serializers based on a request version.
- Replace DRF authentication or permission classes.
- Replace DRF routers for ViewSet resource routing.
- Automatically set
request.version(DRF's concern). - Use
API_VERSIONING_CHANNELSto select routes. - Use
API_EFFECTIVE_VERSION_RESOLVERfor tenant-specific route selection. - Validate response payload compatibility through route-matrix checks.
Your application remains responsible for API contract design, serializer selection, authentication, permissions, business logic, and request-level compatibility tests.
Package vs. DRF: Division of responsibilities
Package responsibility: Route selection
The package registers literal URL paths (/api/v1/endpoint, /api/v2/endpoint) and selects the correct handler based on the URL path.
DRF responsibility: request.version
DRF's versioning classes (like URLPathVersioning) populate request.version if configured. However, DRF's URLPathVersioning uses a URL resolver keyword argument named version, which the package does not populate. This means:
- The package successfully routes requests to version-specific handlers.
request.versionmay beNoneunless you configure a custom versioning class.
If you need request.version populated, consider implementing a custom DRF versioning class that extracts the version from the URL path or adds a custom resolver keyword argument when registering routes.
Configuration timing
Route-registry settings, such as API_MAX_VERSION and API_BASE_PATH, are loaded when the package modules and endpoint declarations are imported. Changing these settings with override_settings after endpoint registration does not rebuild the existing URL patterns.
LifecycleMiddleware is different: it reads API_VERSION_LIFECYCLE and API_BASE_PATH from django.conf.settings at request time. This allows lifecycle behavior to respond to runtime setting overrides, but it does not make the already-registered URL patterns dynamic.
Configure route-registry settings before importing modules containing @endpoint declarations:
# ✓ Correct: configure before importing views
os.environ["DJANGO_SETTINGS_MODULE"] = "myapp.settings"
from django.conf import settings
settings.API_MAX_VERSION = 5
from myapp import views # Package uses the configured API_MAX_VERSION
# ✗ Incorrect: configure after importing
from django_api_versioning import api_settings
from django.test import override_settings
with override_settings(API_MAX_VERSION=5):
# This does NOT affect api_settings (already loaded)
...
Set all configuration in Django settings before importing modules containing @endpoint decorators.
Migration from 0.2.0
Version 0.3.0 replaced the previous forward/backward inheritance flags model with segment-based registration.
The current @endpoint signature accepts:
endpoint(
postfix,
version=None,
versions=None,
app_name=None,
view_name=None,
)
The forward and backward arguments are not part of the current decorator API. The old API_FORWARD_INHERITANCE setting is also not part of the current configuration.
Common migration patterns
| Previous intent | Current declaration |
|---|---|
| Start a forward segment at v3 | @endpoint("x/", version=3) |
| Register only v3 | @endpoint("x/", versions=[3]) |
| Register v1 through v3 explicitly | @endpoint("x/", versions=ver_range(1, 3)) |
| Register only v2 and v4 | @endpoint("x/", versions=[2, 4]) |
The exact replacement depends on the routing behavior your application relied on before upgrading. In particular, do not assume that every old combination of forward and backward flags has an identical one-line replacement.
Automated migration suggestions
The package includes a migrate_endpoints management command:
python manage.py migrate_endpoints --dry-run
python manage.py migrate_endpoints
The command parses Python source into an AST and uses tokenizer-aware checks to identify supported @endpoint declarations containing legacy forward or backward arguments. It rewrites only literal integer version values and literal boolean flags. Dynamic expressions, comments inside a decorator, unsupported forms, and files with syntax errors are left unchanged for manual migration.
Review every proposed change before applying it. This syntax-aware rewrite is not a proof of semantic equivalence: confirm the intended version coverage, inspect the generated route matrix with check_versions, and test request behavior for every affected API version.
After migration:
- Review every changed decorator.
- Inspect the generated route matrix with
check_versions. - Update routing snapshots intentionally.
- Run the complete test suite.
- Add request-level tests for every API version whose behavior changed.
Requirements and compatibility
The package requires:
- Python >= 3.10
- Django >= 4.2
Django REST Framework is optional.
For the current compatibility and CI verification status, see the GitHub Actions workflows.
Contributing
Contributions, bug reports, and documentation improvements are welcome. See CONTRIBUTING.md for the branch, commit, pull-request, and release workflow.
Setup
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pre-commit install
Running tests
Run the unit tests:
python -m pytest tests
Run the integration tests:
python -m pytest integration_test_project
Run the complete configured Python/Django test matrix:
python -m pip install tox
tox run-parallel -p auto
The parallel run uses the available CPU count; use tox run-parallel -p 4
to limit concurrency on memory-constrained machines.
Run pre-commit checks:
pre-commit run --all-files
Docker
The Dockerfile parameterizes Python via PYTHON_VERSION (default: 3.15)
and delegates execution to entrypoint.sh.
# Build the Docker image
docker build -t dapi .
# Run the default test command (unit tests)
docker run --rm dapi
# Run pre-commit checks followed by the unit tests
docker run --rm -e RUN_PRE_COMMIT=true dapi
# Build and run with a specific Python version
docker build --build-arg PYTHON_VERSION=3.15 -t dapi:py315 .
docker run --rm dapi:py315
Releasing
Releases are maintainer operations. Prepare the version bump and changelog
on a temporary release branch created from the latest main, then submit
them through a reviewed pull request. The pull request must pass the
compatibility and artifact checks for its latest commit. Do not push directly
to main or tag an unmerged release branch.
After the reviewed release commit is present on the default branch, create and push the matching version tag:
git tag -a vX.Y.Z -m "Release vX.Y.Z"
git push origin vX.Y.Z
Pushing a v* tag triggers GitHub Actions to run the compatibility matrix,
build and validate the exact distribution with twine check --strict,
smoke-test the wheel, and publish it to PyPI using Trusted Publishing
(GitHub Actions OIDC). A successful tag push alone does not prove that
publication completed; verify the workflow and the version-specific PyPI
release page before announcing the release.
Reporting issues
When reporting an issue, include:
- Python and Django versions.
- The package version and relevant settings.
- The
@endpointdeclarations involved. - Expected and actual URL patterns.
- A minimal example that reproduces the behavior.
License
Released under the MIT License.
Metadata
Release files for django-api-versioning 1.0.0
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.0.tar.gz | 74.6 kB | With provenance | Details for django_api_versioning-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_api_versioning-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for django_api_versioning-1.0.0-py3-none-any.whl |
Total release size: 105.9 kB
Release files / django_api_versioning-1.0.0.tar.gz
| Download URL | django_api_versioning-1.0.0.tar.gz |
|---|---|
| Size | 74.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
486b8d9dd9fc5132f3c5f19f0a35f08e482b3fcb8fe55fe8e5410510984f74c3
|
|
BLAKE2b-256 checksum How to use checksums |
8c2de0f43d6b0f9b4ab9a7acefa43f92960b9e1f4747ac25258e213dcf910d6d
|
| 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 16, 2026.
Transparency logRelease files / django_api_versioning-1.0.0-py3-none-any.whl
| Download URL | django_api_versioning-1.0.0-py3-none-any.whl |
|---|---|
| Size | 31.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f9068a53e9b331fae897ab6e017d450e089081264266a6bc434420f2935f8b4
|
|
BLAKE2b-256 checksum How to use checksums |
e3237f90dd36b2e42d1d26ff0d2d7a160dee3e0d7d7ab2d63840a64abe54d3e4
|
| 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 16, 2026.
Transparency logSecurity for django-api-versioning 1.0.0
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.0.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 16, 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.