drf-writable-nested
Writable nested helpers for django-rest-framework's serializers
What it is and what it does
DRF Writable Nested is a Django REST Framework extension that lets you serialize and deserialize nested model relationships—OneToOne, ForeignKey, ManyToMany, and GenericRelation—in a single API request. Instead of making separate calls to create or update related objects, you pass a nested data structure to the serializer, and it handles all the database operations atomically.
The package provides WritableNestedModelSerializer as the main class, plus NestedCreateMixin and NestedUpdateMixin for more granular control. It also includes UniqueFieldsMixin to handle validation of unique fields on nested updates. The serializer automatically creates or updates all related instances and returns a complete object graph, making it useful for APIs that need to accept complex, hierarchical input in a single request.
Use it for:
- Accept a user profile with nested sites, access keys, and avatars in one POST request instead of multiple API calls.
- Update a parent object and its related children (e.g., a voucher and its line items) via a single PATCH or PUT.
- Build admin-style APIs where clients submit entire object trees with related data and expect atomic creation or update.
- Simplify client code by eliminating the need to orchestrate multiple serializer calls for interdependent model hierarchies.
- Handle reverse relationships (e.g., a user's profile, or a profile's avatars) without flattening or restructuring the data.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Extends Django REST Framework serializers to handle creation and updates of nested model relationships (OneToOne, ForeignKey, ManyToMany, GenericRelation) in a single request.
Yes, if you are building Django REST Framework APIs that accept nested model data. The package is stable (BSD licensed, no known vulnerabilities, 1139 GitHub stars), has low install friction, and solves a common pain point in DRF. The aging maintenance status (522 days since last release) is a minor concern for long-term support, but the repository remains active and the package supports current Django and Python versions. Install it when you need to handle nested creates/updates; skip it if your API only works with flat, single-model payloads.
Install
drf-writable-nested on PyPI
pip
pip install drf-writable-nesteduv
uv add drf-writable-nestedpoetry
poetry add drf-writable-nestedInstalling drf-writable-nested
Before you install
Low install friction with no runtime dependencies. Maintenance status is aging—last release was 522 days ago, though the repository remains active with recent commits and 1139 stars. Suitable for projects on Django 4.2–5.2 and Python 3.9–3.13.
License in practice
BSD license is permissive, allowing commercial and private use with minimal restrictions. Include a copy of the license in distributions.
Quickstart
pip install drf-writable-nested
from drf_writable_nested.serializers import WritableNestedModelSerializer
class ProfileSerializer(WritableNestedModelSerializer):
sites = SiteSerializer(many=True)
access_key = AccessKeySerializer(allow_null=True)
class Meta:
model = Profile
fields = ('pk', 'sites', 'access_key')
data = {'sites': [{'url': 'http://example.com'}], 'access_key': {'key': 'abc'}}
serializer = ProfileSerializer(data=data)
serializer.is_valid(raise_exception=True)
instance = serializer.save()
Requires Django 4.2+ and djangorestframework 3.14+; Python 3.9 or later.
Verify before relying
- Whether the aging maintenance status (522 days since last release) affects stability for new Django/Python versions beyond 5.2 and 3.13.
- Performance characteristics when handling deeply nested or large-scale related data structures.
- Compatibility with third-party DRF extensions or custom serializer mixins beyond those documented.
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 522 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 735,738/month — #5,195 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: drf_writable_nested-0.7.2-py3-none-any.whl
Keywords: drf, restframework, rest_framework, django_rest_framework, serializers, drf_writable_nested
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
django-modelclusterdjango-modelcluster extends Django models to…
permissive · top 5,000 on PyPI
djangorestframework-recursiveAdds a RecursiveField to Django REST Framework…
permissive · top 15,000 on PyPI
drf-nested-routersProvides routers and serializer fields for…
permissive · top 5,000 on PyPI
rest-framework-generic-relationsProvides Django REST Framework serializers that…
permissive · top 15,000 on PyPI
django-soloDjango Solo provides a base model class and…
unclear · top 15,000 on PyPI
django-rest-polymorphicProvides polymorphic serializers for Django…
permissive · top 5,000 on PyPI
drf-rw-serializersExtends Django REST Framework with separate…
permissive · top 15,000 on PyPI
django-typomaticGenerates TypeScript interfaces and enums from…
unclear · top 15,000 on PyPI
drf-dynamic-fieldsProvides a Django REST Framework mixin that…
permissive · top 15,000 on PyPI
swapperSwapper provides an API for Django's…
permissive · top 15,000 on PyPI