dj-rest-filters
A Django REST Framework filter backend that lets you declaratively validate query parameters and filter querysets using DRF serializer syntax. Validate query params the same way you validate request bodies, with the same fields, the same Meta, and the same validate_* hooks.
📖 Full docs: https://dj-rest-filters.readthedocs.io/en/latest/
Features
- DRF-native syntax — filters look like serializers; reuse what you already know.
- Validation-only mode — drop the queryset to use a filter purely for query-param validation; cleaned values land on
request.cleaned_args. ListFieldandRangeFieldforINand range queries; accepts comma-separated, JSON-array, or repeated-key inputs.- Custom per-field filtering via
filter_<name>(self, qs, value), pluslookup_expr,exclude=True, anddistinct=Trueon every field. - OpenAPI / Swagger — schema parameters auto-generated for both drf-spectacular and drf-yasg.
- Browsable API support out of the box.
Requirements
| Minimum | Tested up to | |
|---|---|---|
| Python | 3.8 | 3.14 |
| Django | 3.2 | 5.2 |
| Django REST Framework | 3.12 | 3.17 |
Installation
pip install dj-rest-filters
Add djfilters to your INSTALLED_APPS:
INSTALLED_APPS = [
...,
"djfilters",
]
Quickstart
Define a filter — same shape as a DRF serializer:
from djfilters import filters
class TodoFilter(filters.Filter):
title = filters.CharField(required=False, lookup_expr="icontains")
completed = filters.BooleanField(required=False)
tags = filters.ListField(child=filters.CharField(), required=False)
Wire it into a view:
from rest_framework import generics
from djfilters.backend import DjFilterBackend
class TodoView(generics.ListAPIView):
queryset = Todo.objects.all()
serializer_class = TodoSerializer
filter_class = TodoFilter
filter_backends = [DjFilterBackend]
GET /todos/?title=buy&completed=true&tags=urgent,today filters by title__icontains="buy", completed=True, and tags__in=("urgent", "today").
Validation-only mode
Omit queryset to use a filter purely for query-param validation. The filter still runs, errors still surface as 400s, and the cleaned values land on request.cleaned_args:
class TodoView(generics.GenericAPIView):
serializer_class = TodoSerializer
filter_class = TodoFilter
filter_backends = [DjFilterBackend]
def get(self, request):
params = request.cleaned_args # validated query params
...
Filter context
Just like serializer context, extra context can be passed to the filter from the view:
class TodoView(generics.ListAPIView):
...
def get_filter_context(self):
return {"user": self.request.user}
The returned dict is merged with the default {"request": ...} and is accessible as self.context inside the filter.
Documentation
License
MIT — see LICENSE.
Metadata
Release files for dj-rest-filters 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dj_rest_filters-1.1.0.tar.gz | 24.2 kB | With provenance | Details for dj_rest_filters-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dj_rest_filters-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for dj_rest_filters-1.1.0-py3-none-any.whl |
Total release size: 42.9 kB
Release files / dj_rest_filters-1.1.0.tar.gz
| Download URL | dj_rest_filters-1.1.0.tar.gz |
|---|---|
| Size | 24.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dcb911bc5ebe8731aeca1199ba2503977172b3c79656f20808f6f2cfccabbfd4
|
|
BLAKE2b-256 checksum How to use checksums |
3943ccd80f8875452bb47f761053706b5c5566d9f4b8d15344614deb59dd7f82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.
Transparency logRelease files / dj_rest_filters-1.1.0-py3-none-any.whl
| Download URL | dj_rest_filters-1.1.0-py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e1d51e762a4dc0d6e0dc4885b49bb9a946ea4704f6cafa0071c5c2482cd7f9a6
|
|
BLAKE2b-256 checksum How to use checksums |
7826f23dab46193de6217be5cc15c10ddbc81b3c2e63a261a9f915a8eb0a1ed0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.
Transparency logSecurity for dj-rest-filters 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for dj_rest_filters-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.