drf-nested-routers
Nested resources for the Django Rest Framework
What it is and what it does
drf-nested-routers extends Django REST Framework's routing system to handle nested resources—child resources that logically belong within parent resources. Instead of flat URLs like /domains/ and /nameservers/, it generates hierarchical URLs like /domains/{domain_pk}/nameservers/{pk}, where the nameserver is always accessed in the context of its parent domain. This is essential for building truly RESTful APIs where resource relationships are reflected in the URL structure.
The package provides NestedSimpleRouter and NestedDefaultRouter classes that chain off parent routers, plus optional serializer fields for building hyperlinks in nested contexts. It supports arbitrary nesting depth—you can nest routers multiple levels deep—and works with both Django ORM-based viewsets and custom ViewSet implementations. The package is lightweight, requires no Django app registration, and integrates directly into your URL configuration.
Use it for:
- Build a multi-tenant API where teams have projects and projects have tasks, with hierarchical URL scoping.
- Create a domain management API where domains have nested nameservers, SSL certificates, or DNS records scoped to each domain.
- Implement a content management system with nested resources like sites containing pages containing comments.
- Design a SaaS API with organizations, workspaces, and resources nested within each, maintaining proper authorization boundaries.
- Build a file system-like API structure with folders containing subfolders and files, using nested routers to reflect the hierarchy.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides routers and serializer fields for Django REST Framework to build nested REST API resources where child resources are scoped within parent resources.
Yes. The package is actively maintained (last commit 2026-08-10), has no known vulnerabilities, low install friction, and solves a genuine problem in REST API design. It is production-stable and widely used (top 5000 PyPI packages). Install it if you need to build hierarchical REST APIs with Django and Django REST Framework without manual routing logic.
Install
drf-nested-routers on PyPI
pip
pip install drf-nested-routersuv
uv add drf-nested-routerspoetry
poetry add drf-nested-routersInstalling drf-nested-routers
Before you install
Low friction install with only two runtime dependencies (Django and djangorestframework). Actively maintained with recent releases; last commit 2026-08-10. Requires Python 3.10 or higher and Django 4.2+.
License in practice
Apache-2.0 permissive license allows use in commercial and private projects with minimal restrictions; attribution required.
Quickstart
pip install drf-nested-routers
from drf_nested_routers import routers
router = routers.SimpleRouter()
router.register(r'domains', DomainViewSet)
domains_router = routers.NestedSimpleRouter(router, r'domains', lookup='domain')
domains_router.register(r'nameservers', NameserverViewSet, basename='domain-nameservers')
Requires Python 3.10 or higher; Django 4.2, 5.0, 5.1, or 5.2; and Django REST Framework 3.14, 3.15, or 3.16.
Verify before relying
- Whether the package fully handles all edge cases in production; the description notes it 'works for me' but cannot warranty full compatibility everywhere.
- Performance characteristics when nesting resources three or more levels deep.
- Compatibility with custom authentication or permission classes in nested contexts.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — djangorestframework, Django |
| Maintenance | actively maintained — 14 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,158,642/month — #3,244 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: drf_nested_routers-0.95.3-py3-none-any.whl
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
drf-writable-nestedExtends Django REST Framework serializers to…
permissive · top 15,000 on PyPI
djangorestframework-role-filtersAdds role-based access control to Django REST…
permissive · top 5,000 on PyPI
django-rest-polymorphicProvides polymorphic serializers for Django…
permissive · top 5,000 on PyPI
django-hostsRoutes HTTP requests to different Django URL…
permissive · top 15,000 on PyPI
django-tree-queriesQuery hierarchical tree structures in Django…
permissive · top 15,000 on PyPI
rest-framework-generic-relationsProvides Django REST Framework serializers that…
permissive · top 15,000 on PyPI
drf-dynamic-fieldsProvides a Django REST Framework mixin that…
permissive · top 15,000 on PyPI
djangorestframeworkBuilds web APIs on top of Django with…
permissive · top 1,000 on PyPI
adrfAdds async/await support to Django REST…
permissive · top 15,000 on PyPI
djangorestframework-filtersExtends Django REST Framework with advanced…
permissive · top 15,000 on PyPI