drf-partial-response-fields¶
GraphQL-like sparse fieldsets for Django REST Framework, with automatic query optimization so that requesting fewer fields also means fewer database queries and less data read off the wire.
GET /api/articles/1/?fields=title,author(name,email),tags(label)
Why this exists¶
Most "sparse fieldset" packages for DRF stop at filtering the serializer's
output. They shrink the JSON payload but leave the ORM query untouched —
you still pay for every select_related-worthy join and every
SerializerMethodField computation, even for fields the client never asked
for. drf-partial-response-fields does both halves of the job:
- Output filtering — only the requested fields (and their requested nested sub-fields, at any depth) appear in the response.
- Query optimization —
select_related,prefetch_related, andonly()are derived automatically from what was requested, including recursively-optimized nestedPrefetchquerysets.
See Performance for measured query-count reductions.
Where to go next¶
- New to the package? Start with Getting Started.
- Wiring it into an existing project? See Installation and Configuration.
- Want the full picture of how it works? Read Architecture.
- Looking for a specific class or setting? Jump to API Reference or Settings.
- Something not behaving as expected? Check Troubleshooting and the FAQ.
At a glance¶
| Task | Where |
|---|---|
| Filter fields on a serializer | PartialFieldsSerializerMixin |
| Wire up a view/viewset | PartialResponseMixin |
Optimize a SerializerMethodField |
requires_related |
Document ?fields= in OpenAPI |
PartialResponseAutoSchema |
| Change the query parameter name, strictness, depth limit, etc. | Settings |