When to Use ClaraX
ClaraX replaces DRF's serialization and validation overhead, not Python itself. Use this decision guide:
Use ClaraX (Django)
| Scenario | Expected Speedup | Why |
|---|---|---|
| List API returning 50+ records | 2-3x over DRF | Rust bypasses DRF's per-field Python dispatch |
| Bulk create/update with validation | 2-3x over DRF | Batch validation in single Rust call |
| Export endpoint (1K+ records) | 3.5x via serialize_values_list() |
Single Rust call for entire queryset |
| Batch name/string validation | 9x over Python | Character scanning without per-char object allocation |
| Pattern matching (regex-like) | 15x over Python | Hand-written Rust byte matcher vs Python re |
| Batch statistics (mean/median/stdev) | 20x over Python statistics |
Rayon parallel reduce + sort |
Do NOT Use ClaraX
| Scenario | Why |
|---|---|
| Single-record detail views | Bridge overhead (~10us) exceeds DRF overhead for 1 record |
| Database-bound views | ClaraX does not touch query time. Optimize your queries first |
Raw .values() dict comprehensions |
Already C-speed. ClaraX replaces DRF, not CPython's dict ops |
Views with SerializerMethodField everywhere |
Python-computed fields bypass Rust entirely |
| Simple apps with <100 req/s | DRF is fast enough. Don't add complexity you don't need |
Quick Check
# Run on your Django project — tells you exactly which serializers benefit
Performance
Django (clarax-django vs DRF ModelSerializer)
Measured on a 17-field model, CPython 3.12, SQLite:
| Method | 500 records | vs DRF |
|---|---|---|
| Pure DRF ModelSerializer | 57 ms | baseline |
DRF + RustSerializerMixin |
26 ms | 2.2x |
serialize_batch() |
21 ms | 2.7x |
Standalone (clarax-core, 50K records)
| Operation | Python | ClaraX | Speedup |
|---|---|---|---|
| Name validation (150K names) | 2,147 ms | 237 ms | 9.1x |
| Pattern matching (50K IDs) | 46 ms | 3 ms | 15.5x |
| Risk computation (50K records) | 238 ms | 64 ms | 3.7x |
| Batch statistics (50K values) | 96 ms | 5 ms | 20.8x |
| Dict serialization (50K x 11 fields) | 284 ms | 127 ms | 2.2x |
Python 3.14 Free-Threading
ClaraX supports Python 3.14t (no-GIL) with zero code changes. Rayon parallel operations use all CPU cores:
| Operation | 3.12 (GIL) | 3.14t (no-GIL) | Change |
|---|---|---|---|
| serialize_many | 54 ms | 47 ms | 13% faster |
| validate_names | 106 ms | 77 ms | 27% faster |
Install
Add to INSTALLED_APPS:
=
Django Quickstart
Step 1: Add the mixin (one line)
=
=
Step 2: Check your project
Output tells you exactly which serializers benefit and which fields are Rust-accelerated.
Step 3: Use batch APIs for bulk operations
=
# From model instances (2.7x over DRF)
=
# From values_list (3.5x over DRF, lowest overhead)
=
# Streaming for large exports (constant memory)
yield
Standalone Quickstart (clarax-core)
=
=
=
=
Batch operations (where Rust dominates)
# Character scanning — 9x over Python
=
# Pattern matching — 15x over Python
=
# Statistics — 20x over Python's statistics module
=
Supported Django Fields
| Field | Rust Type | Notes |
|---|---|---|
| CharField, TextField, EmailField, URLField, SlugField | String |
Character counting, not byte counting |
| IntegerField, BigIntegerField | i64 |
Full 64-bit range |
| DecimalField | rust_decimal |
Full precision, never floats |
| DateField, DateTimeField, TimeField | chrono |
ISO 8601 / RFC 3339 |
| UUIDField | uuid |
Hyphenated string |
| BooleanField | bool |
True/False, never 1/0 |
| FloatField | f64 |
NaN/Infinity rejected |
| JSONField | serde_json |
Nested structures preserved |
| BinaryField | Vec<u8> |
Base64 encoded |
Requirements
- Python 3.11+ (pre-built wheels, no Rust installation needed)
- Python 3.14t supported (free-threading / no-GIL)
- Django 4.2 LTS or 5.x (for clarax-django)
- Any Python project (for clarax-core)
License
MIT -- Abdulwahed Mansour