Skip to main content

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#.

API reference read the guide documentation

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

License

MIT

Release files for pamoja-codec 0.1.17

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

Source distribution (sdist)

Source distribution for pamoja-codec 0.1.17
File Size Uploaded
pamoja_codec-0.1.17.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pamoja-codec 0.1.17
File Interpreter ABI Platform
pamoja_codec-0.1.17-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / pamoja_codec-0.1.17.tar.gz

Download URL pamoja_codec-0.1.17.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d9a5ccc96b530edacd75b9e64944f58401af98dc91d94f1da8a2b31e0aeded33
BLAKE2b-256 checksum
How to use checksums
61586972bd831fd6b4c4f361b6a2c6f16ab2d7e01f9ee34f64c54d7d0ffef9c4
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.17-py3-none-any.whl

Download URL pamoja_codec-0.1.17-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c85e4d308e405f357dc361cd9b8778798543a8514fe5adfd20fb98d6c9129786
BLAKE2b-256 checksum
How to use checksums
86fa885ddd33251f49b12c092de3d3cbb3931311ac83e55b7b387f7a94cf61d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.2.0

2 release files

0.1.18

2 release files

This release

0.1.17 This release

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