Skip to main content

larzcbor

CBOR (RFC 8949) encode/decode. Pure Python, zero dependencies.

CBOR is the IETF's standard binary data format — compact like MessagePack, but an actual internet standard used by WebAuthn/FIDO2, COSE, and IoT (CoAP). larzcbor encodes and decodes the core data model with canonical map ordering.

from larzcbor import encode, decode

encode({"a": 1, "b": [2, 3]})     # b'\xa2aba\x01ab\x82\x02\x03'
decode(encode([1, "two", 3.0, {"x": True}]))

Why

  • A standard, not a convention. CBOR is defined by RFC 8949; larzcbor is tested against the RFC's own byte vectors, so its output interoperates with every conformant CBOR tool and the systems that mandate it (WebAuthn attestation, COSE signing, CoAP payloads).
  • Canonical output. Map keys are emitted in sorted byte order, so equal values encode to identical bytes — safe to hash or sign (pair with larzcrypt).
  • Compact. Binary, with the same small-value efficiency as MessagePack; decodes float16/32/64 for full interop.
  • Zero dependencies. No cbor2, no C extension.

Install

pip install larzcbor

Usage

from larzcbor import encode, decode

blob = encode({"user": 42, "roles": ["admin"], "active": True})
decode(blob)     # {'user': 42, 'roles': ['admin'], 'active': True}

Supports None, bool, int, float, str, bytes, list, dict.

larzcbor vs larzpack

Both are compact, canonical, zero-dep binary serializers. Choose larzpack for MessagePack compatibility; choose larzcbor when you need the IETF CBOR standard (WebAuthn/COSE/IoT).

Tests

python -m unittest discover -s tests -v   # 16 tests incl. RFC 8949 vectors

The Larz stack

One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.

License

MIT © larz-scripter

Download files

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

Source Distribution

larzcbor-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

larzcbor-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file larzcbor-0.1.0.tar.gz.

File metadata

  • Download URL: larzcbor-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzcbor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cfcb6567441f12f2aee42053df9f391d18be0a8d81abbe8e507bc1e3b56d0d8a
MD5 0d6f48fd035b719dfacbe850aba719d6
BLAKE2b-256 8cbacc2a359f78bc39ca60103d08c13815aa06c0e4f155ee6c6eb95a77fda226

See more details on using hashes here.

File details

Details for the file larzcbor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larzcbor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzcbor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ea09e1482978d00603609fb9bbec471e8d263e16c457ce1dee0fb3031b8dc2d
MD5 bc46cc944e7438ee374560d0355142cd
BLAKE2b-256 3231f53035828ed608c228fa9967d673ababb3add426d8491548e99ca79710d9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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