A Python implementation of C0DATA — structured data built on ASCII C0 control codes.
This is not a reimplementation: it's a thin, fast binding over the
c0 C core (a CPython extension, no third-party
dependencies), so the scan-heavy work runs as native C while the Python layer
provides an idiomatic API. The read path is zero-copy — accessors return
memoryview slices into the input buffer.
import c0
# Write
buf = c0.build(lambda b: (
b.group("users", ["name", "amount"]),
b.record("Alice", "100"),
b.record("Bob", "200"),
))
# Read (zero-copy: fields are memoryviews into buf)
t = c0.Table(buf)
for rec in t:
name, amount = rec.fields # list[memoryview]
rec.value(0) # bytes, DLE-escapes decoded
# Compact form is canonical — hashable for content addressing
assert c0.canonical(buf)
# Documents, streams, pretty
doc = c0.Document(buf)
log = c0.StreamReader(open("claims.c0", "rb").read()) # .torn, .committed, blocks
print(c0.pretty_format(buf)) # Unicode Control PicturesThe C core and the shared conformance vectors are git submodules:
git submodule update --init # pulls in c0-c (the header) and c0-spec
pip install . # builds the extensionRequires a C compiler and the Python development headers.
Binds the c0-c core: tokenizer, table/record and document/group readers (zero-copy),
canonical helpers, ETB stream mode, and pretty (pretty_format/pretty_parse).
The builder is pure Python (byte-identical to the C builder). Passes the shared
conformance vectors from c0-spec.
Converters (CSV / JSON / C0DIFF) are not yet wrapped.
python -m unittest discover -s testsMIT