Skip to content
 
 

Latest commit

 

History

7,355 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ClaraX is a fork of PyO3.

The Rust–Python binding layer, the procedural macros and the CPython FFI bindings in this repository are PyO3's work, carried over under PyO3's dual MIT / Apache-2.0 licence. What this fork adds is clarax-core and clarax-django: a batching layer that crosses the Python/Rust FFI boundary once per batch of records rather than once per field, with a parallel path for large batches, plus the Django serializer and validator that sit on it.

Copyright and licence: see LICENSE-MIT and LICENSE-APACHE, which carry PyO3's notice above this fork's.

ClaraX

Keep Django and Python. Move the expensive serialization work to Rust.

clarax-django on PyPI clarax-core on PyPI clarax-core on crates.io MIT OR Apache-2.0 GitHub Release Sponsor ClaraX


Why ClaraX?

Django REST Framework is productive, but serialization and validation can become CPU-heavy at scale.

ClaraX adds a Rust fast path without asking your team to rewrite the application.

from django_clarax.serializers import RustSerializerMixin

class ApplicationSerializer(RustSerializerMixin, serializers.ModelSerializer):
    class Meta:
        model = Application
        fields = "__all__"

Same Django models. Same views. Same URLs. Rust underneath.

If ClaraX saves your team time or infrastructure cost, you can help keep it maintained:

❤️ Sponsor ClaraX development


Quick start

pip install clarax-django
# settings.py
INSTALLED_APPS = [
    ...,
    "django_clarax",
]

Then add RustSerializerMixin to the serializers where CPU time actually matters.

No Rust installation or Cargo setup is required for normal Python/Django use. Pre-built wheels are provided for supported platforms.


Check before changing anything

Not every endpoint needs Rust. ClaraX includes a doctor command so you can inspect your serializers first:

python manage.py clarax_doctor

Use ClaraX where it helps. Leave ordinary Django code alone where it does not.


Benchmark snapshot

Results published by the project benchmark suite against DRF ModelSerializer:

Workload DRF ClaraX Reported speedup
Serialize 1,000 records 475 ms 14 ms 33x
Validate 1,000 records 506 ms 10 ms 50x
Name validation, 150K strings 2,806 ms 339 ms 8x
Pattern matching, 50K IDs 82 ms 4 ms 15x

Simple operations can improve much less; the project also reports cases around 2.2x. The goal is not to claim Rust makes everything faster — it is to move the workloads that benefit from it.


Good fit

ClaraX is most useful when you have:

  • large list responses
  • bulk imports or exports
  • validation-heavy APIs
  • reporting workloads
  • repeated string/pattern processing
  • CPU-bound serialization where scaling application servers is becoming expensive

It is probably not your first fix when the real bottleneck is SQL, N+1 queries, or heavy SerializerMethodField logic.


Python without Django

clarax-core can also be used directly from Python:

pip install clarax-core
from clarax_core import Schema, Field, serialize_many
from decimal import Decimal

schema = Schema({
    "name": Field(str, max_length=100),
    "price": Field(Decimal, max_digits=10, decimal_places=2),
})

data = [{"name": "Example", "price": Decimal("199.99")}]
result = serialize_many(data, schema)

This makes ClaraX useful for Flask, FastAPI, ETL, scripts, and other Python workloads too.


How it works

ClaraX compiles schema information once and sends batch serialization/validation work across the Python↔Rust boundary in larger units rather than paying Python dispatch overhead for every field operation.

The public Python API stays small; the performance-sensitive implementation lives in Rust.

Python 3.11+ and Django 4.2+ are supported. The project also includes support for Python 3.14 free-threading work.

Supported Django field types
Django Field Rust representation
CharField, TextField, EmailField, SlugField String
IntegerField, BigIntegerField i64
DecimalField rust_decimal
DateField, DateTimeField, TimeField chrono
UUIDField uuid
BooleanField bool
FloatField f64
JSONField serde_json
BinaryField Vec<u8>

Why sponsor?

Open-source performance tooling needs more than the initial implementation. Sponsorship helps fund:

  • Python and Django compatibility work
  • wheel builds and releases
  • regression tests
  • reproducible benchmarks
  • documentation and examples
  • profiling and performance work
  • bug fixes from real-world usage

If ClaraX becomes useful in your project or company, sponsorship is a direct way to keep that work moving.

Support ClaraX on GitHub Sponsors


License

Dual-licensed under either MIT or Apache-2.0, at your option.

— Abdulwahed Mansour

About

Fork of PyO3 adding batch serialization and validation for Django. Upstream: github.com/PyO3/pyo3

Topics

Resources

Contributing

Security policy

Stars

31 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages