Skip to main content

Pure-Python encoder/decoder for the Crous binary serialization format — compact, canonical, and human-readable alternative to JSON

Project description

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/Oload() / 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crousr-1.0.2.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crousr-1.0.2-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file crousr-1.0.2.tar.gz.

File metadata

  • Download URL: crousr-1.0.2.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for crousr-1.0.2.tar.gz
Algorithm Hash digest
SHA256 795d29f9eb911286ff0706694f8fe201b319512fb21b712d33f6789da8a0183b
MD5 552deead2da69d1c46c51eda93a85066
BLAKE2b-256 9615b79144bc7f31bf1a56eebc7c118895e2ebc84978adebada8b177819acbc5

See more details on using hashes here.

File details

Details for the file crousr-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: crousr-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for crousr-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1f75fd080dbe2d023292bd1e32780c7fb5bfe90b95ee351b5702f061284914e4
MD5 9bc3116ff9a76475e2c2874bcb3a74b8
BLAKE2b-256 8dfefc7625f9e2919a52756d84ec7484a26f308a8be4dbe192cb1ee7693fd3d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page