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-coreandclarax-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.
Keep Django and Python. Move the expensive serialization work to Rust.
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:
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.
Not every endpoint needs Rust. ClaraX includes a doctor command so you can inspect your serializers first:
python manage.py clarax_doctorUse ClaraX where it helps. Leave ordinary Django code alone where it does not.
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.
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.
clarax-core can also be used directly from Python:
pip install clarax-corefrom 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.
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> |
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.
Dual-licensed under either MIT or Apache-2.0, at your option.
