--- id: drf-flex-fields version: "1.0.2" license: MIT license_treatment: permissive maintenance: dormant --- # drf-flex-fields — Flexible, dynamic fields and nested resources for Django REST Framework serializers. License: permissive · Maintenance: dormant · Downloads: 215.0K/mo ## 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 above — 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 pip install drf-flex-fields uv add drf-flex-fields 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: unspecified - Install friction: high - Maintenance: dormant - Downloads: 215.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django rest framework dynamic fields, sparse fields api serializer, nested resource expansion query, drf flexible field selection, api response field filtering, django rest nested serialization, query parameter field control, django-rest-framework, api-design, serialization [View on SkillFed](https://skillfed.io/packages/drf-flex-fields) · [View on PyPI](https://pypi.org/project/drf-flex-fields/)