Flexible, dynamic fields and nested resources for Django REST Framework serializers (forked from drf-flex-fields).
Project description
drf-flex-fields2
Flexible dynamic fields and nested resources for Django REST Framework serializers.
This project is for people building APIs, people integrating them, and people maintaining the ecosystem around them. If you are new to flexible serializers, welcome. If you are evaluating this for production, welcome. If you want to contribute fixes, docs, tests, or ideas, welcome.
Migration from drf-flex-fields
This is a fork of drf-flex-fields developed and maintained by Robert Singer
between 2018 and 2023. For more details on why this fork exists, see
History below. See the Migration Guide
in the documentation for detailed instructions. The short version is:
- Upgrade Django and DRF dependencies, if not done already.
- Install
drf-flex-fields2instead ofdrf-flex-fields. - Fix package name in import paths:
rest_flex_fields2instead ofrest_flex_fields - Change package-level imports to deep imports, e.g.:
from rest_flex_fields2.serializers import FlexFieldsModelSerializer - Rename
REST_FLEX_FIELDStoREST_FLEX_FIELDS2in Django settings.
The drf-flex-fields2 API is stable and compatible with the original drf-flex-fields
package. There are currently no plans to break the existing API. However, if breaking
changes become necessary in the future, they will follow semantic versioning
guidelines and the major version number will be incremented accordingly.
Users, community contributors, and maintainers are warmly welcome to keep this package useful and maintained.
Documentation
The full documentation is published on Read the Docs: https://drf-flex-fields2.readthedocs.io/
Installation
pip install drf-flex-fields2
Quick Example
from rest_flex_fields2.serializers import FlexFieldsModelSerializer
class StateSerializer(FlexFieldsModelSerializer):
class Meta:
model = State
fields = ("id", "name")
class CountrySerializer(FlexFieldsModelSerializer):
class Meta:
model = Country
fields = ("id", "name", "population", "states")
expandable_fields = {
"states": (StateSerializer, {"many": True}),
}
class PersonSerializer(FlexFieldsModelSerializer):
class Meta:
model = Person
fields = ("id", "name", "country", "occupation")
expandable_fields = {
"country": CountrySerializer,
}
Default response:
{
"id": 142,
"name": "Jim Halpert",
"country": 1
}
Expanded response for GET /people/142/?expand=country.states:
{
"id": 142,
"name": "Jim Halpert",
"country": {
"id": 1,
"name": "United States",
"states": [
{
"id": 23,
"name": "Ohio"
},
{
"id": 2,
"name": "Pennsylvania"
}
]
}
}
Highlights
- Expand nested relations with
?expand=. - Limit response payloads with
?fields=and?omit=. - Use dot notation for nested expansion and sparse fieldsets.
- Reuse serializers by passing
expand,fields, andomitdirectly.
License
MIT. See LICENSE.md.
History
The original drf-flex-fields was developed and maintained by Robert Singer
between 2018 and 2023. However, in 2023 maintenance appeared to stop with no
further commits and issues and pull-requests remaining unanswered.
In March 2026, Django REST Framework 3.17.0 removed coreapi support, which unfortunately broke the existing package. Although the immediate fix was simple, the project was due for broader modernization, including tooling updates, Python 2 to 3 cleanup, dependency version maintenance and proper documentation.
This fork exists because drf-flex-fields is used in the
OpenBook project, and we want to
reduce supply-chain risk from outdated dependencies while keeping this
package healthy and maintained. Please join the community and help us with
this mission. Oh, and keep your own packages up to date and maintained, will
you? :-)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf_flex_fields2-2.0.2.tar.gz.
File metadata
- Download URL: drf_flex_fields2-2.0.2.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17fdf5ff7b759c1c8c19a2bec0afebf4b9a9ddb715dd7348a902008f9d82391e
|
|
| MD5 |
083dafdd2ada4220660c4be45bb0bec2
|
|
| BLAKE2b-256 |
1cbde09f162e2f833716125ff21934a5f71517926ec22402b37ccbbebc95fc33
|
Provenance
The following attestation bundles were made for drf_flex_fields2-2.0.2.tar.gz:
Publisher:
release.yml on openbook-education/drf-flex-fields2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
drf_flex_fields2-2.0.2.tar.gz -
Subject digest:
17fdf5ff7b759c1c8c19a2bec0afebf4b9a9ddb715dd7348a902008f9d82391e - Sigstore transparency entry: 1361719849
- Sigstore integration time:
-
Permalink:
openbook-education/drf-flex-fields2@433ea0ce084504766b19486de279f27b9df8d0dc -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/openbook-education
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@433ea0ce084504766b19486de279f27b9df8d0dc -
Trigger Event:
push
-
Statement type:
File details
Details for the file drf_flex_fields2-2.0.2-py3-none-any.whl.
File metadata
- Download URL: drf_flex_fields2-2.0.2-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22893fa7fa6cad4bd59dfb260e663411520b7f84f4d96e70dab805f9b19b9065
|
|
| MD5 |
659fe8d8a98474cabb4dfc64d2e399a0
|
|
| BLAKE2b-256 |
fa8f76a63c574ccaf85404794b9ba7488ab6d4f71cdecf60266244bc1735ddd4
|
Provenance
The following attestation bundles were made for drf_flex_fields2-2.0.2-py3-none-any.whl:
Publisher:
release.yml on openbook-education/drf-flex-fields2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
drf_flex_fields2-2.0.2-py3-none-any.whl -
Subject digest:
22893fa7fa6cad4bd59dfb260e663411520b7f84f4d96e70dab805f9b19b9065 - Sigstore transparency entry: 1361719855
- Sigstore integration time:
-
Permalink:
openbook-education/drf-flex-fields2@433ea0ce084504766b19486de279f27b9df8d0dc -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/openbook-education
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@433ea0ce084504766b19486de279f27b9df8d0dc -
Trigger Event:
push
-
Statement type: