Skip to main content

dj-rest-filters

Build codecov Docs

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.
  • ListField and RangeField for IN and range queries; accepts comma-separated, JSON-array, or repeated-key inputs.
  • Custom per-field filtering via filter_<name>(self, qs, value), plus lookup_expr, exclude=True, and distinct=True on 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)

Source distribution for dj-rest-filters 1.1.0
File Size Uploaded
dj_rest_filters-1.1.0.tar.gz 24.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dj-rest-filters 1.1.0
File Interpreter ABI Platform
dj_rest_filters-1.1.0-py3-none-any.whl Python 3 none any Details

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 log

Release 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 log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

1 release file

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page