drf-extensions

Caching, conditional requests, nested routes, bulk operations, and mixins for Django REST Framework.

Library
PyPI
v0.8.0
1,549stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
59/100Fair
Development Activity44
Maintenance20
Community84
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
69/100Good
Architecture72
Code Quality70
Innovation60
Learning Curve74

DRF-extensions is a collection of viewset mixins, routers, and utilities that fill gaps in Django REST Framework’s built-in generic views. It adds response caching keyed off request parameters, conditional request support (ETags), nested resource routing, bulk create/update/delete operations, and a DetailSerializerMixin for using a different serializer on detail vs. list endpoints.

Each feature is delivered as an opt-in mixin or router class that composes with DRF’s existing ViewSet/GenericAPIView classes, so teams adopt only the pieces they need rather than replacing their existing DRF setup. The project has been maintained since Django REST Framework’s early days and tracks current DRF/Django releases.

What You Get

  • CacheResponseMixin for caching DRF responses with customizable, request-aware cache keys
  • Conditional request (ETag) support for reducing bandwidth on unchanged resources
  • DetailSerializerMixin to use a different serializer/queryset for detail vs. list endpoints
  • Nested routers for building resource hierarchies like /parents/{id}/children/
  • Bulk operation mixins (ListUpdateModelMixin, ListDestroyModelMixin) for batch create/update/delete

Common Use Cases

  • Caching expensive DRF list/detail responses without hand-rolling cache-key logic
  • Serving lighter list serializers while keeping a richer serializer for detail views
  • Modeling nested REST resources (e.g. comments under posts) with nested routers
  • Supporting bulk update/delete endpoints for admin or data-migration tooling
  • Reducing bandwidth with ETag-based conditional GET requests

Under The Hood

Architecture The package is organized as a set of independent submodules under rest_framework_extensions/: cache/ implements response caching with a pluggable key-constructor system, etag/ implements conditional-request support, bulk_operations/ adds list-level update/destroy mixins, key_constructor/ provides the composable cache-key-building blocks shared by caching and ETags, and routers.py/decorators.py add nested-route support on top of DRF’s SimpleRouter. mixins.py re-exports the most commonly used mixins (DetailSerializerMixin, CacheResponseMixin, bulk mixins) as the primary integration surface.

Tech Stack Pure Python, built against Django REST Framework 3.12-3.16 and Django 3.2-6.0, tested across Python 3.9-3.14 via tox. No dependencies beyond DRF and Django themselves (django-filter is an optional test dependency).

Code Quality tests_app/ is a full Django test project exercising each mixin (caching, ETags, bulk ops, nested routing, serializer switching) through DRF’s test client, run via tox across the supported Python/Django/DRF matrix. The project has a documented contribution process requiring every new feature to ship documented, tested, and implemented together, and long-running community stewardship (Tidelift-listed, Open Collective sponsorship) suggests an established review process even though release cadence has slowed.

API Design Every feature is delivered as an additive mixin or router subclass rather than a replacement base class, so adopting one feature (say, caching) doesn’t require restructuring a viewset to also get bulk operations or nested routing — this composability is the library’s central design decision and keeps the learning curve low for anyone already familiar with DRF’s GenericAPIView/ViewSet patterns.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search