skillfed

drf-writable-nested

Writable nested helpers for django-rest-framework's serializers

drf-writable-nested v0.7.2 735.7K downloads/30d#5,195 on PyPI1,139
Permissive license BSD AGING released

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

uv

uv add drf-writable-nested

poetry

poetry add drf-writable-nested

Installing 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

Development Status :: 4 - BetaEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Internet :: WWW/HTTP

Tags

django rest framework nested serializerdrf writable nested relationscreate update nested models djangodjango rest framework foreign key serializernested model serialization djangodrf many-to-many nesteddjango rest framework one-to-one nested
django-rest-frameworkserializationnested-data

More WWW/HTTP packages