Skip to main content

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

Project description

DRF Accelerator

🚀 Turbocharge your Django REST Framework (DRF) list serialization by replacing Python's hot loop with a high-performance Rust extension.

PyPI version License: MIT

DRF Accelerator addresses one of the most common performance bottlenecks in Django applications: returning large lists of data. By offloading the innermost object-to-dict conversion loop to a Rust module (via PyO3), it bypasses the heavy Python interpreter overhead, resulting in massive throughput gains for your API endpoints.


💡 Why DRF Accelerator?

If you've ever profiled a DRF application returning standard many=True responses, you know that creating hundreds or thousands of dictionaries in pure Python is exceptionally slow.

The Solution:
We swap DRF's standard ListSerializer with a custom-built Rust implementation (FastListSerializer).

The Guarantees:

  • Zero API breakage: You still get exactly the same standard DRF serializer.data structures.
  • Zero logic changes: You don't need to rewrite your serializers into .values() queries or change how you query your database.
  • Minimal adoption effort: Add exactly one mixin to your existing serializer classes.

⚡ Performance

The largest speedups occur on list responses (many=True) containing 100s to 10,000s of items, particularly when the fields are primitive types (str, int, float, bool, None).

Because benchmarks are highly workload-dependent, this repository includes tooling for you to test the gains directly against your own hardware:

  • Micro-benchmarks: Tests the pure Rust loop vs pure Python loop.
  • End-to-End benchmarks: Tests an actual DRF request cycle.

To run the benchmarks locally (requires cloning the repository):

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

📦 Installation

Requirements:

  • Python 3.10 – 3.13
  • Django REST Framework >= 3.12

Install directly from PyPI:

pip install drf-accelerator

Note: This package ships with pre-built binary wheels for major platforms (Linux, macOS, Windows). If your specific architecture isn't covered, pip will automatically attempt to compile it from source (which requires a standard Rust toolchain).


🚦 Quickstart & Usage

DRF Accelerator is designed to be completely unobtrusive. To accelerate a serializer, simply inherit from FastSerializationMixin as your first base class.

from rest_framework import serializers
from drf_accelerator import FastSerializationMixin

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

When you use this serializer for list endpoints (many=True), the Rust accelerator automatically takes over!

# The FastListSerializer written in Rust will process this entire queryset
serializer = MyModelSerializer(queryset, many=True)
data = serializer.data 

🔍 How It Works & Supported Features

Under the hood, FastSerializationMixin overrides the many_init method to return our Rust-backed FastListSerializer.

Fast-Path Supported Types

The Rust extension has deeply optimized zero-overhead "fast paths" for standard conversions:

  • str, int, float, bool, None
  • datetime, date, time
  • uuid.UUID, decimal.Decimal

Universal Fallback

For any deeply custom fields (or object types the Rust layer doesn't explicitly know how to fast-path), the serializer gracefully falls back to calling the standard DRF field’s to_representation(value) method. It will never break your data structure.

Supported Field Configurations

  • Standard fields (CharField, IntegerField, etc.)
  • Dotted sources (source="author.user.email")
  • SerializerMethodField
  • Nested Serializers

⚠️ Scope & Limitations

  • Read-Only Focus: This accelerator strictly improves output serialization. It does not speed up incoming data parsing, validation, or saving (.is_valid() or .save()).
  • List Serialization Only: It accelerates iterables (many=True). Single-object serialization (many=False) remains unchanged because the overhead of calling the Rust extension outweighs the benefits for a single dictionary.
  • Fallbacks cause slowdowns: Relying heavily on manual MethodFields or custom data types that require the Python fallback will naturally reduce your overall speedup multiplier, though it will still be faster than native DRF.

Project details


Download files

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

Source Distribution

drf_accelerator-0.1.2.tar.gz (13.4 kB view details)

Uploaded Source

Built Distributions

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

drf_accelerator-0.1.2-cp313-cp313-win_amd64.whl (168.2 kB view details)

Uploaded CPython 3.13Windows x86-64

drf_accelerator-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

drf_accelerator-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (271.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

drf_accelerator-0.1.2-cp312-cp312-win_amd64.whl (167.9 kB view details)

Uploaded CPython 3.12Windows x86-64

drf_accelerator-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

drf_accelerator-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (271.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

drf_accelerator-0.1.2-cp311-cp311-win_amd64.whl (167.3 kB view details)

Uploaded CPython 3.11Windows x86-64

drf_accelerator-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

drf_accelerator-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (274.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

drf_accelerator-0.1.2-cp310-cp310-win_amd64.whl (167.5 kB view details)

Uploaded CPython 3.10Windows x86-64

drf_accelerator-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (314.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

drf_accelerator-0.1.2-cp310-cp310-macosx_11_0_arm64.whl (274.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file drf_accelerator-0.1.2.tar.gz.

File metadata

  • Download URL: drf_accelerator-0.1.2.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for drf_accelerator-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8d94229284d318907a3b8f88f95b7e7b792a162d3856c3e3e674efefad21e8bf
MD5 6269f3f94f800488f7d790b708dfb63b
BLAKE2b-256 3e4c1b4b2b28d3759e307fdcb6c8d4411659b6afe68964abf7c6edf411688662

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2.tar.gz:

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.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1c94ecbc89ae2881251cf299c687e7cdd4d9e3c488a5a0a54d75d2a83883089a
MD5 42ad48e09de8d46c83b260a042c21372
BLAKE2b-256 562c3962a6dd1debbf34630eaefb14046ddca713d470b8f1c3267320a068116a

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 524c9936a3671a44115e25d066fcfe5714fac73ede3905aa4aac2a70b58412d6
MD5 706ebe7c562bcd418219a4d54ddc29d2
BLAKE2b-256 555895003ea2b2227bff56b7a0f84d16a9bdd84f2073e2c94b92baecf7c36645

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a6c7094fc56962dede6e30ec1ce16bc449f3baffb6363872e6aaf545fefaaf1d
MD5 8b3f435ea487d7526d32212e5bc53978
BLAKE2b-256 bb013da9694c2e7282ba30bb8f9f9912240d62725a17b56a3303fb847c0a404e

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 27271ded49de760b0e6f8ba670a66764bd501173c76e9d86608ea78aec76a334
MD5 1ece9edcc69b91260fd55d38ada7bf15
BLAKE2b-256 d5dde3b909206e144b5e4fa75857be05854631a379200c54cfbcbdf71f3c6da6

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e6c97fda66256c4735df9719cfd2394ea25a6a2d2feb02fa3b250df73a7da0d
MD5 f56b83f39421c62cb9f20c98725425aa
BLAKE2b-256 379fdd7a86f39b95e67efdb2e4927a4427eab1553ea95c3702ed712bc20cdb42

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 566eea8bba4654ef19f999f5f3c5c310c141605124f5584145254dbb64319866
MD5 183a710e8d17a6971adb0908c5a3c1a6
BLAKE2b-256 cc958715150dcf1bfe8745105674c9ed74bd08244293cfd9f35e1e02d9427f7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9cd0fd94cfcbe7a3ce58486c1895380f9074be907e3b8784ed122efc510f7439
MD5 3b137edb54e8e3076e3f664280a1d43d
BLAKE2b-256 af3efbf777e50e6515ae88286ee37b395b81ab4e5a30c72c421d4d56742af8cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 acf4042f8659d991b770469cd575d32332502c486782aefeced5ed22e86dfaa5
MD5 4a21620e20bfcc0541260b5d20d3d1e7
BLAKE2b-256 1901889dd11ac2003cb2ba42934770baab7b43a20c6a8e68992b8b7a0e9b41ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e9ed9b516358b0d8d3ac3842cca43aeaa2c1387444fc04270ac5afbb74c1f316
MD5 16e503eb31448335f08cfd338608af14
BLAKE2b-256 d8e3dfd796630ea3f61507dc0221e04d1b50af007b1bdb940f1b0d1d7b20370e

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bbd522dbb7a36b3001fd9d0ef9c935c2d4c2a1f02f2e1dd0aab1d01d2b086984
MD5 f504618eb9bf969a3799cb66f4dcc2c8
BLAKE2b-256 f5ffefb554727ce9bde16dc4941eed8092dda12f5005f06ec44dff7e9b69dabd

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5364782af39d2fa9a58ded62c3425ccb7c7c54a1a7e87517fdaf75255c8f744c
MD5 8fa1eb612603780cc1a93066b5f0d0ee
BLAKE2b-256 aca0b17f3fb11ad465341e9a08d1e08751730f647876e73653e8df094812e265

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drf_accelerator-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4d2a2a1fb5b316d8646a72559939aebd19ecacffd52d6589f34b89d4da9dd237
MD5 e753de595f760c2eb7d7bc27157cd9b0
BLAKE2b-256 b2db5187436905db83eefe12ad2bf6f5570d64a8660820f8047f309ccbf0bfbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for drf_accelerator-0.1.2-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