compact-encoding-python
Compact encoding schemes for Python. The Python counterpart of compact-encoding, and wire compatible with it. All multi-byte values are little-endian.
pip install compact-encoding
Only the codecs needed by hyperschema-python and bare-rpc-python are included so far. Others, such as raw, any, bigint, and the IP codecs, can be added without changing the wire format.
Usage
import compact_encoding as cenc
data = cenc.encode(cenc.uint, 42) # -> bytes
n = cenc.decode(cenc.uint, data) # -> 42
Codecs
Every codec exposes preencode, encode, and decode. Pass one to the encode/decode helpers, or drive it directly through a State (see Three-phase API).
Scalars
| Codec | Python type | Notes |
|---|---|---|
uint |
int |
varint, 0 .. 2**53 - 1 |
int |
int |
zigzag varint |
bool |
bool |
single byte |
buffer |
bytes |
length-prefixed |
utf8 (alias string) |
str |
length-prefixed UTF-8 |
json |
any | length-prefixed UTF-8 JSON |
Fixed-width numbers
Little-endian, fixed size. Unsigned: uint8, uint16, uint24, uint32, uint40, uint48, uint56. Signed: int24, int40, int48, int56. IEEE 754 floats: float32, float64.
Fixed-width buffers
fixed(n) encodes exactly n bytes (no length prefix). fixed32 and fixed64 are fixed(32) and fixed(64) - 32- and 64-byte buffers, not bits.
Composites
array(codec)- a length-prefixed list ofcodecvalues (decode rejects lengths above0x100000).record(key_codec, value_codec)- a length-prefixed dict.frame(codec)- a nested value with its encoded byte length written ahead of it.
Encode / decode
encode(codec, value) -> bytes and decode(codec, data) -> value are the one-shot helpers.
Three-phase API
To pack several values into one buffer, drive a State directly: preencode every value to measure the buffer, allocate(), then encode.
import compact_encoding as cenc
state = cenc.State()
cenc.uint.preencode(state, 42)
cenc.utf8.preencode(state, "hi")
state.allocate()
cenc.uint.encode(state, 42)
cenc.utf8.encode(state, "hi")
state = cenc.State(state.buffer)
cenc.uint.decode(state) # -> 42
cenc.utf8.decode(state) # -> "hi"
A State holds start, end, buffer, and a remaining property, plus allocate() and rewind(). Codec is a typing Protocol for writing your own.
Errors
CompactError is the base error; OutOfBounds (a subclass) is raised when a decode reads past the end of the buffer. Out-of-range encodes raise ValueError.
License
Apache-2.0
Metadata
Release files for compact-encoding 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| compact_encoding-0.1.1.tar.gz | 15.6 kB | With provenance | Details for compact_encoding-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| compact_encoding-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for compact_encoding-0.1.1-py3-none-any.whl |
Total release size: 29.6 kB
Release files / compact_encoding-0.1.1.tar.gz
| Download URL | compact_encoding-0.1.1.tar.gz |
|---|---|
| Size | 15.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c849d3379c0d297f89e4bc656d953b4c9599be9e7fec2d3ce77a5e78a50f301
|
|
BLAKE2b-256 checksum How to use checksums |
c6a897622f7cd388a3f4430695b5f4cf4b2b0e4763d39335af5206cb153436a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logRelease files / compact_encoding-0.1.1-py3-none-any.whl
| Download URL | compact_encoding-0.1.1-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
19bccc65a120b1ebdd3124ee50b86ffc700b3e3d8e4ad3c8f65fc7fc33806d90
|
|
BLAKE2b-256 checksum How to use checksums |
f9992000fda292734d025a9afaa9353bc5ad3b76e8d446bd04bd8f14c4ad0970
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logSecurity for compact-encoding 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for compact_encoding-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.