Skip to main content

A high-performance Rust-backed accelerator for Django REST Framework.

Project description

DRF Accelerator

Speed up Django REST Framework list serialization (many=True) by moving the hot object-to-dict loop into a Rust extension (PyO3).

What You Get

  • Big wins on large list responses where most fields are primitives (str/int/float/bool/None) and simple conversions.
  • No changes to your API output: you still get standard DRF serializer.data structures.
  • Minimal adoption: add one mixin to your serializer class.

Performance (Run Your Own)

Benchmarks are highly workload- and machine-dependent. This repo includes both:

  • A micro-benchmark of the Rust loop: test_bench_fast_serializer vs test_bench_standard_serializer.
  • An end-to-end DRF benchmark (what users actually run): test_bench_e2e_fast_mixin vs test_bench_e2e_standard.

Run:

cd drf_accelerator
pytest benchmarks/ -v --benchmark-only

Installation & Setup

Install

Install from PyPI:

pip install drf-accelerator

[!NOTE] This is a Rust extension. If a pre-built wheel is not available for your platform/Python version, you will need a Rust toolchain to build from source.

Compatibility

  • Python: CPython 3.10–3.13 (requires-python >=3.10,<3.14)
  • DRF: djangorestframework>=3.12

From Source

If you want to build locally:

  1. Prerequisites: Ensure you have Rust installed.
  2. Clone & Install:
    git clone https://github.com/p-r-a-v-i-n/drf-accelerator.git
    cd drf-accelerator
    pip install -e .
    

For Developers (Try it out)

If you want to run the benchmarks yourself:

  1. Build the extension:

    cd drf_accelerator
    maturin develop --release
    cd ..
    
  2. Run Benchmarks:

    cd drf_accelerator
    pytest benchmarks/ -v --benchmark-only
    

Usage

Simply inherit from FastSerializationMixin in your ModelSerializer:

from drf_accelerator import FastSerializationMixin
from rest_framework import serializers

class MySerializer(FastSerializationMixin, serializers.ModelSerializer):
    class Meta:
        model = MyModel
        fields = ["id", "title", "author", "is_published"]

Production Notes

  • Measure on your actual serializers and payload sizes; speedups vary a lot.
  • Biggest wins are typically list endpoints returning 100s–10,000s of items.
  • If your deployment platform doesn’t have wheels, add Rust to your build pipeline (or build wheels in CI).

Scope

  • Accelerates serialization of lists (many=True). Single-object serializers are unchanged.
  • This is about output serialization only (not validation, parsing, or saving).

Supported Features

  • Field sources: normal fields, dotted sources (source="a.b.c"), SerializerMethodField, and nested serializers.
  • Fast paths: str, int, float, bool, None, datetime/date/time, uuid.UUID, decimal.Decimal.
  • Fallback: other values call the DRF field’s cached to_representation(value).

Current Limitations

  • Dotted sources, nested serializers, and None values are supported, but may see smaller speedups because they involve more Python work per item.
  • FastSerializer is primarily an internal implementation detail of the DRF mixin. If you construct it manually and pass None as the field object, only the fast-path types work; otherwise it raises TypeError("unsupported type") because there is no to_representation fallback.

How it works

The Mixin swaps the standard DRF ListSerializer for a FastListSerializer that offloads the object-to-dict conversion loop to a Rust extension using PyO3. This significantly reduces Python interpreter overhead for large list responses.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

drf_accelerator-0.1.1-cp313-cp313-win_amd64.whl (168.4 kB view details)

Uploaded CPython 3.13Windows x86-64

drf_accelerator-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

drf_accelerator-0.1.1-cp313-cp313-macosx_11_0_arm64.whl (272.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

drf_accelerator-0.1.1-cp312-cp312-win_amd64.whl (168.5 kB view details)

Uploaded CPython 3.12Windows x86-64

drf_accelerator-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

drf_accelerator-0.1.1-cp312-cp312-macosx_11_0_arm64.whl (272.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

drf_accelerator-0.1.1-cp311-cp311-win_amd64.whl (167.9 kB view details)

Uploaded CPython 3.11Windows x86-64

drf_accelerator-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (313.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

drf_accelerator-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (276.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

drf_accelerator-0.1.1-cp310-cp310-win_amd64.whl (168.1 kB view details)

Uploaded CPython 3.10Windows x86-64

drf_accelerator-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

drf_accelerator-0.1.1-cp310-cp310-macosx_11_0_arm64.whl (276.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file drf_accelerator-0.1.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f0f52bc90cf0d24d2a0098e2b7dcb540327b870d512c1c2cd175406f6aea63ee
MD5 f8a86b70999121b84ff0ac8fe698a312
BLAKE2b-256 850c02e9fead67234f392fb425e4e918e8dd76cf1d04da3993f6dd3ffb3a654f

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp313-cp313-win_amd64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30ef4c4ec3df65a86f7f59cf2a1a998ba92d6174d19df7218efc5cf72f2bc9e4
MD5 ac5dead0d7618ccbe6d3c4c7d0976a52
BLAKE2b-256 76e18ee727cfd6390fff4598aea5c74a3db52194c2faf407e1c065236b1782a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a2f2b30261be1d8de34922fc5be9f9d14297467c0923027c534a4ea85c8f5d84
MD5 b1ec4179240a0020deef240a82272e9a
BLAKE2b-256 0fb73d4c2e0b14a16cc4c549f4e1e0a91ca2ed2824f96f1d54d6d85a499149c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ac8c80559bf93d864228d65601fe7c1abe2fbd9402040a5f2e6daa29983af877
MD5 e3e74f3e4e9523029ad30afde572167c
BLAKE2b-256 8ced0a83ed9a2bd5dd1881d32f03a846bf49908022993f7e335f7ad7e797da68

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp312-cp312-win_amd64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b5855d4b5c924f416b42c5fd313b629503863a69c863fa3d243ef7719ed0ed28
MD5 c5218696861569a46a510d01f3cbde93
BLAKE2b-256 b6c0b059b27d36b77261ea73397f8c6b054fc7ed45d32c107801d7ff3f7259e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 79cad5fbefbbef62b9f0e77faa392222f5e54e4eaec725ac6e61211f663cd5a7
MD5 2a850701dcb944f9605a2b7f3ecb45cf
BLAKE2b-256 de7aabd9d3257681518c005d61f4342b04d797b0050d2845832a5cc9391bf53a

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9cba5cc3eb61ef4aaf2daa8f5e20b3d5fc4fbb0c6d2ab16eccd3013ac44a91e8
MD5 512b7dad2b3912fbc7923c3317823f17
BLAKE2b-256 2215e4df749f1490c92d570ff39ef3575b6e514f9ec1423add333dda112f1d6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp311-cp311-win_amd64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8e515e81f1d053d2c80e524ba4183e66ccdf1508feda799f2bb3b6662498a9cd
MD5 bc96ec9f993ea124a47207c5dfda24e9
BLAKE2b-256 13a0a00a5e737027b3b25505c049fbc22d1a0374cecfe5b8854ffaaa048a0312

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e7d203e46637e3b8d0f9cc385773a7f99842bc5fb5a56a98abf8bc0720060280
MD5 af771c50d2ca156dc975b2179907728b
BLAKE2b-256 85cad53de90c4c7bc67881137209724711ea2bb8debbdc4c587723c7eda9e6c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 13e9a91a18b336054d6cd09d7cf6dcb081727c4864875ad4ea1fcd97123f1776
MD5 53f0660ff6b03c45ee5e6ed4dc2bec9f
BLAKE2b-256 2fc660b172345c343491eafb36337c82564a275b4035d5362ef265cf191adab5

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp310-cp310-win_amd64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 83577d589baa9d74f62f530aac5484744dbd67d428978fd72c74fd09f30fefad
MD5 d95583b4eaa9e435970101fd31713339
BLAKE2b-256 1bd563970ee83c5411faecce93f88442a76ff88279ab1f987d05eb19ceb6b94a

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drf_accelerator-0.1.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3266b447bf2767c07ee77e7b5e2f0496edaebd1f12ef18c2b2208b256da5e6af
MD5 450aa670c7f0e3872a872cf992e5d966
BLAKE2b-256 fe5c6471da44a5996b4b5234d97dd51de467556afe70994672840223503c9175

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.1-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on p-r-a-v-i-n/drf-accelerator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page