Skip to main content

django-fastdrf

Opt-in serializer, query and response optimizations for synchronous Django REST framework projects.

django-fastdrf is for DRF projects that stay synchronous (WSGI, or ASGI with synchronous views) and want less time per request without leaving DRF. It adds subclasses, mixins and settings next to DRF's own classes. Each optimization is enabled explicitly, per project, per view or per serializer, and falls back to DRF's code wherever it cannot produce DRF's result.

It does not replace or patch any Django or DRF class, add async support, or change DRF's validation errors.

Installation

pip install django-fastdrf

The distribution is django-fastdrf; the import name is fastdrf. Two extras install the optional backends:

pip install "django-fastdrf[msgspec]"    # msgspec backend, renderer, parser, codec
pip install "django-fastdrf[pydantic]"   # pydantic backend, schema serializers, codec

Adding "fastdrf" to INSTALLED_APPS is optional. It registers system checks and two management commands; everything else works without it.

Quick start

Use fastdrf's serializer bases and choose a backend for their output:

# settings.py
FASTDRF = {
    "SERIALIZER_BACKEND": "msgspec",  # or "pydantic", or "python" (no dependency)
    "CACHE_SERIALIZER_FIELDS": True,
    "FIELD_COPY_MODE": "compiled",
}
# serializers.py
from fastdrf import serializers


class ArticleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Article
        fields = ["id", "title", "author", "published_at"]
        auto_prefetch = True
# views.py
from rest_framework import viewsets

from fastdrf.views import DispatchOptimizationMixin, QueryOptimizationMixin


class ArticleViewSet(
    DispatchOptimizationMixin, QueryOptimizationMixin, viewsets.ModelViewSet
):
    queryset = Article.objects.all()
    serializer_class = ArticleSerializer

.data, .is_valid(), .save(), many=True, routers, pagination, permissions and error responses are DRF's. With "fastdrf" in INSTALLED_APPS, this command lists which serializers the backend compiles, and why the others stay on DRF:

python manage.py fastdrf_inspect_serializers

Features

Serialization:

  • Compiled serializer output with the msgspec, pydantic or dependency-free python backend, equal to DRF's .data in the default strict parity mode (serializers).
  • Input recognition: JSON input that DRF would accept unchanged is validated by a compiled class; everything else, including every error, is DRF's (input recognition).
  • Cached field templates, copied per request with deepcopy, a scalar clone or a compiled copy plan (field caching).
  • List serializers whose child refers to the list weakly (list serializers).
  • Schema serializers: a msgspec Struct or a pydantic model as a DRF serializer, and SchemaViewMixin for views (schema serializers).

Queries:

  • select_related and prefetch_related derived from the serializer by QueryOptimizationMixin, explicit Meta.prefetch hints, Django 6.1's FETCH_MODE, one query for many-valued primary-key input, and PrefetchListSerializer for per-list enrichment (queries).

Views and responses:

  • Dispatch mixins that keep content negotiation and request construction between requests, compiled create and update responses, a Response that releases its request objects when closed, and DataResponse, rendered without DRF's template response (views and responses).
  • A JSONRenderer that keeps its encoder, msgspec's JSON renderer and parser, and msgspec and pydantic codecs for Django's Redis cache (rendering and codecs).

Tooling:

  • System checks for the FASTDRF setting and two management commands: fastdrf_inspect_serializers and fastdrf_convert, which writes a schema for a serializer or a serializer for a schema (commands).

Guarantees and limits

  • No Django or DRF class is replaced, patched or monkeypatched. fastdrf's classes are subclasses and mixins that a project selects.
  • Everything is opt-in. With the default settings, fastdrf's serializer bases behave as DRF's.
  • In strict parity, compiled output equals DRF's output; a field, value or hook the compiler cannot prove equal keeps the serializer, or that one source, on DRF. Input recognition never produces an error of its own.
  • Synchronous only: no ORM call becomes asynchronous, and transactions, authentication, permissions, throttling and pagination are DRF's and Django's.
  • Schema serializers, fast parity and the msgspec renderer have their own documented output and validation rules; they are not DRF-identical by design.
  • A serializer instance belongs to one request; do not share it between threads.

See architecture for how the caches are bounded and invalidated, and for the deliberate differences.

Compatibility

Django DRF Python
5.2 3.16, 3.17, 3.18 3.12, 3.13, 3.14
6.0 3.17, 3.18 3.12, 3.13, 3.14
6.1 3.18 3.12, 3.13, 3.14

The test suite also runs on free-threaded Python 3.14t (Django 6.1, DRF 3.18) and at the declared minimum versions (Django 5.2, DRF 3.16, msgspec 0.19, pydantic 2.9). FETCH_MODE needs Django 6.1.

Documentation

License

BSD 3-Clause. See LICENSE and NOTICE: the optimizations derive from the aiodrf project, and the list-construction protocol from Django REST framework.

Metadata

Release files for django-fastdrf 0.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 django-fastdrf 0.1.0
File Size Uploaded
django_fastdrf-0.1.0.tar.gz 279.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-fastdrf 0.1.0
File Interpreter ABI Platform
django_fastdrf-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 395.2 kB

Release files / django_fastdrf-0.1.0.tar.gz

Download URL django_fastdrf-0.1.0.tar.gz
Size 279.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8d1150ac7e501173a3280fdf0679dad0666acb122c346ee44d2038926fa024f7
BLAKE2b-256 checksum
How to use checksums
77c8f2548de5f56ae77bded5709793995ac78e6854076cfd996a934ef64d8428
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 1, 2026.

Transparency log

Release files / django_fastdrf-0.1.0-py3-none-any.whl

Download URL django_fastdrf-0.1.0-py3-none-any.whl
Size 116.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bb260dd18deee6b57735aadd60e8ee629ff9fb62ba1d2d7184d7c13a2da0bf8
BLAKE2b-256 checksum
How to use checksums
c34a1228d90c61ee2a070bab0d541637249f35987817f4e92e775e73f026831f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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