skillfed

drf-flex-fields

Flexible, dynamic fields and nested resources for Django REST Framework serializers.

drf-flex-fields v1.0.2 215.0K downloads/30d#9,406 on PyPI768
Permissive license MIT DORMANT released

What it is and what it does

drf-flex-fields extends Django REST Framework serializers to let API clients dynamically control which fields appear in responses and which nested relationships get fully expanded. Instead of returning fixed response shapes, you define expandable fields in your serializer's Meta class, then clients use query parameters like `?expand=country.states` or `?fields=id,name` to customize what they receive. The package supports dot notation for arbitrarily deep nesting, sparse field selection (include or exclude specific fields), and can be configured per-request or passed directly to serializer instantiation.

The package has no runtime dependencies and integrates as a mixin or base class for your existing DRF serializers. It includes a ViewSet subclass to prevent expensive expansions on list endpoints and utility functions to check expansion state in view logic. The core appeal is reducing over-fetching and under-fetching in REST APIs without duplicating serializer definitions.

Use it for:

  • Mobile apps that need lightweight responses with only essential fields to reduce bandwidth and latency
  • Admin dashboards that request full nested details on demand without creating separate serializer variants
  • GraphQL-like query control in REST APIs where clients specify exactly which relations to populate
  • Preventing N+1 query problems by letting clients opt into expensive nested expansions rather than always including them
  • Reusing a single serializer across multiple endpoints with different response shape requirements

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Adds dynamic field expansion and sparse field selection to Django REST Framework serializers, allowing API clients to request only the fields and nested resources they need via query parameters.

Yes, if you are already committed to Django REST Framework and need flexible field control without building custom logic. The permissive MIT license and zero runtime dependencies make adoption low-risk. However, the dormant maintenance status (last commit October 2023, no release for over a year) is a real concern—verify compatibility with your Django and DRF versions before relying on it for new projects, and be prepared to fork or patch if breaking changes emerge upstream.

Install

drf-flex-fields on PyPI

pip

pip install drf-flex-fields

uv

uv add drf-flex-fields

poetry

poetry add drf-flex-fields

Installing drf-flex-fields

Before you install

High install friction with no runtime dependencies. The package is dormant—last commit was 2023-10-16 and no release in over a year—so expect limited maintenance and potential compatibility drift with newer Django or DRF versions.

License in practice

MIT license permits free use, modification, and distribution with minimal restrictions, making it safe for commercial and open-source projects.

Quickstart

pip install drf-flex-fields

from rest_flex_fields import FlexFieldsModelSerializer

class CountrySerializer(FlexFieldsModelSerializer):
    class Meta:
        model = Country
        fields = ('id', 'name', 'population', 'states')
        expandable_fields = {'states': (StateSerializer, {'many': True})}

# GET /people/142/?expand=country.states

Verify before relying

  • Compatibility with current Django and Django REST Framework versions (classifiers list Python up to 3.7 only)
  • Whether the package works with modern async Django views or only synchronous serializers
  • Performance impact of deep nested expansion on large datasets beyond the database query warnings in the description

Package facts

License MIT (permissive)
Python support not specified
Install friction high — source build required
Runtime dependencies none
Maintenance dormant — 1,252 days since the last release
Last repo commit
First released
Downloads 215,044/month — #9,406 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: drf-flex-fields-1.0.2.tar.gz

Keywords: django, rest, api, dynamic, fields

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.2Programming Language :: Python :: 3.3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7

Tags

django rest framework dynamic fieldssparse fields api serializernested resource expansion querydrf flexible field selectionapi response field filteringdjango rest nested serializationquery parameter field control
django-rest-frameworkapi-designserialization

More Dynamic Content packages

MarkupSafe

MarkupSafe provides a text object that escapes…

permissive · top 100 on PyPI

Jinja2

Jinja2 is a templating engine that renders…

permissive · top 100 on PyPI

soupsieve

Soupsieve is a CSS selector library designed to…

permissive · top 100 on PyPI

Werkzeug

Werkzeug is a WSGI utility library providing…

permissive · top 1,000 on PyPI

Flask

Flask is a lightweight WSGI web application…

permissive · top 1,000 on PyPI

Mako

Mako compiles Python-embedded templates into…

permissive · top 1,000 on PyPI

drf-dynamic-fields

Provides a Django REST Framework mixin that…

permissive · top 15,000 on PyPI

drf-writable-nested

Extends Django REST Framework serializers to…

permissive · top 15,000 on PyPI

drf-nested-routers

Provides routers and serializer fields for…

permissive · top 5,000 on PyPI

djangorestframework-dataclasses

Automatically generates Django REST Framework…

permissive · top 5,000 on PyPI

rest-framework-generic-relations

Provides Django REST Framework serializers that…

permissive · top 15,000 on PyPI

djangorestframework-role-filters

Adds role-based access control to Django REST…

permissive · top 5,000 on PyPI

drf-rw-serializers

Extends Django REST Framework with separate…

permissive · top 15,000 on PyPI

drf-extra-fields

Provides specialized serializer fields for…

permissive · top 15,000 on PyPI

drf-jsonschema-serializer

Converts Django REST Framework serializers to…

permissive · top 15,000 on PyPI

drf-access-policy

Declares access control rules for Django REST…

permissive · top 15,000 on PyPI