Skip to main content

crous

A compact, canonical binary serializer and human-readable alternative to JSON — pure Python.

PyPI Python License

Overview

Crous is a production-grade binary serialization format that provides:

  • Compact binary encoding — 2×–5× smaller than equivalent JSON
  • Human-readable text notation — unique syntax with deterministic binary mapping
  • Zero-copy decoding — borrow directly from input buffers
  • Block-framed format — per-block XXH64 checksums for data integrity
  • File I/O — load() / dump() familiar API, like json.load / json.dump
  • Cross-language — wire-compatible with the Rust implementation

Installation

pip install crous

Quick Start

import crous

# Encode any Python object
data = crous.encode({"name": "Alice", "age": 30, "active": True})
print(data[:7])  # b'CROUSv1'

# Decode back to Python
obj = crous.decode(data)
print(obj)  # {'name': 'Alice', 'age': 30, 'active': True}

File I/O

import crous

# Write to a .crous file (like json.dump)
crous.dump({"name": "Alice", "age": 30}, "data.crous")

# Read from a .crous file (like json.load)
obj = crous.load("data.crous")
print(obj)  # {'name': 'Alice', 'age': 30}

# Append a value to an existing file
crous.append({"event": "stop"}, "log.crous")

# Lossless round-trip with Value objects
from crous.value import Value
crous.dump_values([Value.str_("hello"), Value.uint(42)], "typed.crous")
values = crous.load_values("typed.crous")
print(values[0].type)  # ValueType.STR

Human-Readable Text Format

{
    name: "Alice";
    age: 30;
    tags: ["admin", "user"];
    config: {
        theme: "dark";
        notifications: true;
    };
    avatar: b64#iVBORw0KGgo=;
}

Parse and pretty-print:

import crous

text = '{ name: "Alice"; age: 30; }'
value = crous.parse_text(text)
print(crous.pretty_print(value))

Encoder / Decoder Classes

from crous.encoder import Encoder
from crous.value import Value

enc = Encoder()
enc.enable_dedup()          # Enable string deduplication
enc.encode_value(Value.from_python({"key": "value"}))
data = enc.finish()
from crous.decoder import Decoder

dec = Decoder(data)
values = dec.decode_all()
print(values[0].to_python())

Wire Format

File:    [Header 8B] [Block]* [Trailer Block]
Header:  "CROUSv1" (7B) | flags (1B)
Block:   type(1B) | length(varint) | compression(1B) | checksum(8B) | payload

The format is deterministic: the same input always produces the same bytes.

Cross-Language Compatibility

Data encoded by the pure-Python crous package is fully wire-compatible with the Rust implementation (crous-core). Files can be written in Python and read in Rust, or vice versa.

License

Licensed under either of:

at your option.

Release files for crousr 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crousr 1.1.0
File Size Uploaded
crousr-1.1.0.tar.gz 31.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crousr 1.1.0
File Interpreter ABI Platform
crousr-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 53.8 kB

Release files / crousr-1.1.0.tar.gz

Download URL crousr-1.1.0.tar.gz
Size 31.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c68c2a4bf22e37b39031695aa579453db9b245e4eb62b4441d4b63547a8b7df2
BLAKE2b-256 checksum
How to use checksums
c5dbf8f298dc1a4bc46b52b242b62aab546c3740a72170735ed5a71a16b6f20f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / crousr-1.1.0-py3-none-any.whl

Download URL crousr-1.1.0-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8da4a9431776018981ece57785668b208fb48cfe9f0e0dea29efd7fa0a6a4cb
BLAKE2b-256 checksum
How to use checksums
bf97d72cc7a90ddb6be7de1f83bba6aedd5d8bae51dfd557c32f14b64261cdfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page