Introduction
Crous is a high-performance binary serialization library implemented as a C extension for Python. It provides compact, type-preserving serialization that is significantly smaller and faster than JSON for most workloads.
Version 2.0.0
Crous v2.0.0 introduces the FLUX binary format as the default encoding, CROUT text format for human-readable output, and comprehensive custom serializer support.
Key Features
- Blazing fast — C extension core with zero-copy optimizations
- Ultra compact — Zigzag varint encoding, small-integer optimization, up to 75% smaller than JSON
- Type preserving — Native support for
int,float,bytes,tuple,set,frozenset, and tagged values - Three formats — FLUX binary (default), CROUT text (human-readable), and legacy CROUS binary
- Streaming — File and stream-based I/O with
dump/load - Custom serializers — Register handlers for any Python type with MRO-aware lookup
- Thread safe — Lock-protected custom serializer registry for concurrent use
- Cross-platform — Compatible with Node.js SDK for polyglot applications
Quick Example
example.py
import crous
# Serialize Python data to compact binary
data = {
"name": "Alice",
"scores": [98, 95, 100],
"active": True,
"tags": {"python", "developer"},
}
# Encode to FLUX binary
binary = crous.dumps(data)
print(f"Encoded: {len(binary)} bytes")
# Decode back to Python
result = crous.loads(binary)
assert result == data
print(f"Decoded: {result}")Supported Types
| Python Type | Crous Type | Round-trip |
|---|---|---|
None | NULL | ✅ |
bool | BOOL | ✅ |
int | INT (64-bit signed) | ✅ |
float | FLOAT (64-bit IEEE 754) | ✅ |
str | STRING (UTF-8) | ✅ |
bytes / bytearray | BYTES | ✅ |
list | LIST | ✅ |
tuple | TUPLE | ✅ |
dict | DICT (string keys only) | ✅ |
set | TAGGED(90) | ✅ |
frozenset | TAGGED(91) | ✅ |
Architecture
Crous uses a three-layer architecture:
- Python Wrapper (
__init__.py) — Enhanced API with file path support and error handling - C Extension (
pycrous.c) — N-API bindings that convert between Python objects and the C value tree - Core C Library — Arena allocator, value tree, FLUX/CROUT/CROUS encoders, lexer, and parser
Data flows through an intermediate crous_value tree that decouples Python types from the wire format, enabling format-agnostic encoding and easy addition of new formats.
Wire Format Versions
| Format | Magic Bytes | Version | Default |
|---|---|---|---|
| FLUX Binary | FLUX | 1 | ✅ (v2.0.0+) |
| CROUT Text | CROUT1 | 1 | — |
| CROUS Binary (Legacy) | CROU | 2 | — (auto-detected on decode) |