skillfed

drf-nested-routers

Nested resources for the Django Rest Framework

drf-nested-routers v0.95.3 2.2M downloads/30d#3,244 on PyPI1,799
Permissive license Apache-2.0 Active released

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-routers

uv

uv add drf-nested-routers

poetry

poetry add drf-nested-routers

Installing 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

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Intended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Topic :: Internet :: WWW/HTTP

Tags

nested REST API routesdjango rest framework nested resourceshierarchical API endpointsparent-child resource routingdrf nested routersRESTful nested URL patterns
rest-apidjango-extension

More WWW/HTTP packages