pamoja-codec
CBOR, JSON, and raw codecs behind one trait, delta and varint batch packing, and an f32 quantizer for metered links. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.
Install
pip install pamoja-codec
from pamoja import codec
This pulls in pamoja-native, the compiled engine. pip install pamoja is the whole framework in one package.
Example
The script the test suite runs, spliced here as it ran.
From bindings/python/guides/codec.py:
import json
from pamoja.codec import Quantizer, from_cbor, pack_samples, to_cbor, unpack_samples
# The same reading as JSON and as CBOR. Nothing is lost, and 21.5 rides as a
# half-precision float, the shortest form RFC 8949 allows for it.
reading = {"c": 21.5, "ok": True}
as_json = json.dumps(reading, separators=(",", ":")).encode()
cbor = to_cbor(reading)
print(f"json {len(as_json)} bytes")
print(f"cbor {len(cbor)} bytes")
# A gateway that speaks JSON gets it back unchanged, so the compact form is a transport
# choice rather than a different data model.
restored = from_cbor(cbor)
print(f"back to json, unchanged: {restored == reading}")
# A batch of readings packs to a count, then the difference between each sample and the
# one before it. Successive readings differ by very little, so the differences cost about
# a byte each where the samples would cost eight.
samples = [10, 11, 13, 12, 900]
packed = pack_samples(samples)
print(f"batch {len(samples)} samples in {len(packed)} bytes")
print(f"unpacked {unpack_samples(packed)}")
# Readings that arrive as floats pack the same way once a scale is chosen. Nothing in the
# bytes records that scale, so the sender and the receiver have to agree on it.
quantizer = Quantizer(100)
celsius = [20.0, 20.1, 20.2, 20.3]
packed_celsius = quantizer.encode(celsius)
recovered = quantizer.decode(packed_celsius)
print(f"degrees {len(celsius)} readings in {len(packed_celsius)} bytes")
print(f"recovered {[round(value, 1) for value in recovered]}")
The same capability in every language
| Language | Package | Reference |
|---|---|---|
| Rust | pamoja-codec |
reference, docs.rs, install |
| TypeScript | @pamoja/codec |
reference, install |
| Python | pamoja-codec |
reference, install |
| C# | Pamoja.Codec |
reference, install |
Documentation
pamoja.codecreference, every class and function in this module.- The Codecs guide, with the same example in Rust, TypeScript, and C#.
- Every capability, and the install page.
License
MIT
Release files for pamoja-codec 0.1.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pamoja_codec-0.1.18.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pamoja_codec-0.1.18-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.4 kB
Release files / pamoja_codec-0.1.18.tar.gz
| Download URL | pamoja_codec-0.1.18.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9317c91b9973264fc9d989eb0b312ee3f0f3bf6de44f4f69d12ebd56a321ab1a
|
|
BLAKE2b-256 checksum How to use checksums |
879501c84fdcaf44e9182229546da81ca1dc815a11fcc8cbe070e375bb26ee68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / pamoja_codec-0.1.18-py3-none-any.whl
| Download URL | pamoja_codec-0.1.18-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d5a2dd0badc4eb1ac403524ae4f8e7be0e491b6b82aa6cf938bf07130b3da64c
|
|
BLAKE2b-256 checksum How to use checksums |
f95d33f508d66d1ddc05f278414f65ccf48850102203e75a8297097c0b498897
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|