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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfcb6567441f12f2aee42053df9f391d18be0a8d81abbe8e507bc1e3b56d0d8a
|
|
| MD5 |
0d6f48fd035b719dfacbe850aba719d6
|
|
| BLAKE2b-256 |
8cbacc2a359f78bc39ca60103d08c13815aa06c0e4f155ee6c6eb95a77fda226
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ea09e1482978d00603609fb9bbec471e8d263e16c457ce1dee0fb3031b8dc2d
|
|
| MD5 |
bc46cc944e7438ee374560d0355142cd
|
|
| BLAKE2b-256 |
3231f53035828ed608c228fa9967d673ababb3add426d8491548e99ca79710d9
|