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.2.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.2.0
File Size Uploaded
django_fastdrf-0.2.0.tar.gz 290.3 kB Details

Built distribution (wheel)

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

Total release size: 410.7 kB

Release files / django_fastdrf-0.2.0.tar.gz

Download URL django_fastdrf-0.2.0.tar.gz
Size 290.3 kB
Tags Source
SHA-256 checksum
How to use checksums
555d75798522a26ec78182b7745c374674fa6c1ade7c2d2f4365e9755d70fc6b
BLAKE2b-256 checksum
How to use checksums
0ff86ec17224f134b0e1d1c0ec9be4a42cef8bc4bedbd69562c0528ea0f626f8
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 2, 2026.

Transparency log

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

Download URL django_fastdrf-0.2.0-py3-none-any.whl
Size 120.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1191a69b12d60705170c41114595fe8e4d0809a690c70a9e57d960b2fdec22f8
BLAKE2b-256 checksum
How to use checksums
ad8fa91ff1bd7c27920580cfbd0c94bdb0f11e172ebde4e9369b2c59ee989870
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 2, 2026.

Transparency log

Release history Release notifications | RSS feed

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

This release

0.2.0 This release

2 release files

0.1.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