Python CBOR-LD Processor
A Python CBOR-LD processor for encoding and decoding JSON-LD documents.
Table of Contents
Background
This library provides a CBOR-LD 1.0 processor for Python applications, ported from @digitalbazaar/cborld.
CBOR-LD is a compact binary serialization of JSON-LD that uses semantic compression to achieve significantly better compression ratios than general-purpose algorithms.
Features
- Encode JSON-LD documents to compact CBOR-LD binary format
- Decode CBOR-LD bytes back to JSON-LD
- CBOR-LD 1.0 tag support (
0xCB1D/ 51997) - Legacy format support (
legacy-range,legacy-singleton) - Built-in codecs: HTTP URLs, UUID URNs, DID URLs, data URLs, multibase, XSD dates/datetimes, cryptosuite strings
- Custom type table / registry entry support
Requirements
Python 3.12+
Install
PyPI
pip install cborld
With optional PyLD support for remote context resolution:
pip install cborld[context]
Development
To install locally (for development):
git clone https://github.com/subfile-llc/cborld.git
cd cborld
pip install -e ".[dev]"
Usage
Encode
from cborld import encode
cborld_bytes = encode(
jsonld_document={
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Note",
"summary": "CBOR-LD",
"content": "CBOR-LD is awesome!",
},
document_loader=my_loader,
registry_entry_id=1,
)
Decode
from cborld import decode
jsonld_document = decode(
cborld_bytes=cborld_bytes,
document_loader=my_loader,
)
Document Loader
Both encode and decode accept an optional document_loader — a sync
callable that resolves JSON-LD context URLs. If you have PyLD installed, you
can use the built-in adapter:
from cborld import pyld_document_loader
loader = pyld_document_loader(extra_documents={
"https://example.org/v1": {"@context": {...}},
})
cborld_bytes = encode(
jsonld_document=doc,
document_loader=loader,
registry_entry_id=1,
)
Using in Async Apps
encode and decode are synchronous. When called from an async application
(FastAPI, Starlette, etc.) and the document loader performs blocking network
I/O, run them in a thread pool:
import asyncio
from cborld import encode
cborld_bytes = await asyncio.to_thread(
encode,
jsonld_document=doc,
document_loader=loader,
registry_entry_id=1,
)
Custom Type Tables
For registry entry IDs other than 0 (uncompressed) and 1 (default table),
supply a type_table_loader:
def my_type_table_loader(*, registry_entry_id: int) -> dict:
return {
"context": {"https://example.org/v1": 0x8000},
"url": {"https://example.org/v1": 0x8000},
"none": {"https://example.org/v1": 0x8000},
}
cborld_bytes = encode(
jsonld_document=doc,
document_loader=loader,
registry_entry_id=100,
type_table_loader=my_type_table_loader,
)
Error Handling
All CBOR-LD processing errors raise CborldError, which carries a
machine-readable .code attribute:
from cborld import CborldError
try:
doc = decode(cborld_bytes=data, document_loader=loader)
except CborldError as e:
print(f"Error [{e.code}]: {e}")
API
encode(**kwargs) -> bytes
Encodes a given JSON-LD document into CBOR-LD bytes.
| Parameter | Type | Description |
|---|---|---|
jsonld_document |
dict |
The JSON-LD document to encode. |
document_loader |
(str) -> dict |
Resolves context URLs. |
format |
str |
"cbor-ld-1.0" (default), "legacy-range", or "legacy-singleton". |
registry_entry_id |
int |
Registry entry ID (0 = uncompressed, 1 = default table). |
type_table_loader |
(registry_entry_id=int) -> dict |
Resolves registry IDs to type tables. Required when registry_entry_id > 1. |
diagnose |
(str) -> None |
Optional diagnostic callback. |
decode(**kwargs) -> dict
Decodes CBOR-LD bytes into a JSON-LD document.
| Parameter | Type | Description |
|---|---|---|
cborld_bytes |
bytes |
The CBOR-LD bytes to decode. |
document_loader |
(str) -> dict |
Resolves context URLs. |
type_table_loader |
(registry_entry_id=int) -> dict |
Resolves registry IDs to type tables. |
diagnose |
(str) -> None |
Optional diagnostic callback. |
Migrating from 0.1.x
Version 1.0.0 makes the public API synchronous. Drop await on encode /
decode, and pass sync document_loader / type_table_loader callables.
See CHANGELOG.md for the full migration notes.
Contribute
Please follow the existing code style.
pip install -e ".[dev]"
pytest
ruff check src tests
Specifications
License
Metadata
Release files for cborld 1.0.0
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 |
|---|---|---|---|---|
| cborld-1.0.0.tar.gz | 31.0 kB | With provenance | Details for cborld-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cborld-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for cborld-1.0.0-py3-none-any.whl |
Total release size: 67.5 kB
Release files / cborld-1.0.0.tar.gz
| Download URL | cborld-1.0.0.tar.gz |
|---|---|
| Size | 31.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
247206d3a4efae3f146ee7c9281be0482ff01abd8c5a0d58e031f319f2c34e92
|
|
BLAKE2b-256 checksum How to use checksums |
59b2e7603acf3d65056c7ab875c9f95d78cbda7d05fc15531d22c0b740b92b4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 8, 2026.
Transparency logRelease files / cborld-1.0.0-py3-none-any.whl
| Download URL | cborld-1.0.0-py3-none-any.whl |
|---|---|
| Size | 36.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4316679ea0333d574130884c43da12c411bc46a331dc22170ec99a753f42be71
|
|
BLAKE2b-256 checksum How to use checksums |
8f529e05a5593bc08646a2e1e948278b220413867c1f76688b9a84967d43f292
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 8, 2026.
Transparency logSecurity for cborld 1.0.0
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 cborld-1.0.0.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 Aug 8, 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.