py-ipld-dag
IPLD DAG implementation for Python — codecs for DAG-CBOR, DAG-JSON, DAG-PB, and Raw, aligned with the js-multiformats ecosystem.
Provides:
- DAG-CBOR (
0x71) – Deterministic CBOR with CID links (CBOR tag 42) - DAG-JSON (
0x0129) – Deterministic JSON with CID links ({"/": "bafy..."}) - DAG-PB (
0x70) – Protobuf-based Merkle DAG nodes (legacy IPFS/UnixFS) - Raw (
0x55) – Identity codec for raw binary data - Block API –
Block.encode()/Block.decode()/Block.create() - Codec registry – Pluggable codec architecture with auto-registration
- IPLD Data Model – Full support for Null, Bool, Int, Float, String, Bytes, List, Map, Link kinds
- CID integration – Seamless use of py-cid for content addressing
Read more in the documentation on ReadTheDocs. View the release notes.
Quick Start
from dag import Block
from dag.codecs import dag_cbor, dag_json, dag_pb, raw
block = Block.encode(value={"hello": "world", "n": 42}, codec=dag_cbor.codec)
print(block.cid)
print(block.bytes)
restored = Block.decode(data=block.bytes, codec=dag_cbor.codec)
assert restored.value == {"hello": "world", "n": 42}
child = Block.encode(value={"child": True}, codec=dag_cbor.codec)
parent = Block.encode(
value={"link": child.cid, "type": "parent"},
codec=dag_cbor.codec,
)
for path, cid in parent.links():
print(f"{path} -> {cid}")
json_block = Block.encode(
value={"ref": child.cid, "data": b"\xde\xad"},
codec=dag_json.codec,
)
pb_block = Block.encode(
value={
"Data": b"hello UnixFS",
"Links": [{"Hash": child.cid, "Name": "child", "Tsize": 10}],
},
codec=dag_pb.codec,
)
raw_block = Block.encode(value=b"raw binary", codec=raw.codec)
Examples
Example scripts are available in examples/, including
Python equivalents of js-multiformats interface demos:
examples/block_interface/block_interface.pyexamples/cid_interface/cid_interface.pyexamples/multicodec_interface/multicodec_interface.pyexamples/multihash_interface/multihash_interface.py
Run them from the repository root:
source venv/bin/activate
python -m examples.block_interface.block_interface
python -m examples.cid_interface.cid_interface
python -m examples.multicodec_interface.multicodec_interface
python -m examples.multihash_interface.multihash_interface
Installation and usage
Installation (venv, pip/uv, stable and development) and usage are documented in the docs — see Installation and Usage in the table of contents.
Installation
From PyPI (stable):
pip install py-ipld-dag
From source (development):
Same as in CONTRIBUTING.md. With uv (recommended):
git clone https://github.com/ipld/py-ipld-dag.git
cd py-ipld-dag
uv venv && source venv/bin/activate # Windows: venv\Scripts\activate
uv pip install --upgrade pip
uv pip install --group dev -e .
pre-commit install
With pip (requires pip >= 25.1):
python -m venv venv && source venv/bin/activate # Windows: venv\Scripts\activate
pip install --upgrade pip
pip install --group dev -e .
pre-commit install
Or run make install-dev after activating a venv (uses uv).
Full usage, API reference, and examples: Documentation.
Development
- Tests:
pytestormake test - Lint:
make lintorpre-commit run --all-files - Docs:
make docs-ci(build docs with Sphinx)
Contributing
See CONTRIBUTING.md for setup and pull request guidelines.
Release notes
Changelog and release notes are generated from newsfragments with Towncrier and published in the docs: Release notes.
Metadata
Release files for py-ipld-dag 0.3.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 |
|---|---|---|---|---|
| py_ipld_dag-0.3.0.tar.gz | 48.2 kB | Without provenance | Details for py_ipld_dag-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_ipld_dag-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for py_ipld_dag-0.3.0-py3-none-any.whl |
Total release size: 72.8 kB
Release files / py_ipld_dag-0.3.0.tar.gz
| Download URL | py_ipld_dag-0.3.0.tar.gz |
|---|---|
| Size | 48.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1405fbc23141f8c172faf0a14f3323d2e9ef891ae7a3811195e238fee1f1989
|
|
BLAKE2b-256 checksum How to use checksums |
203f94c2f6e4710e17bdfaad1a6beaa341a05e974a9d9d0a24c0022a0f53fcc6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Release files / py_ipld_dag-0.3.0-py3-none-any.whl
| Download URL | py_ipld_dag-0.3.0-py3-none-any.whl |
|---|---|
| Size | 24.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85db3101b70634e54516006684656d60dc528101377872e89a3a7c08c7aa0f19
|
|
BLAKE2b-256 checksum How to use checksums |
6831b1e530a875c0024e8469e7720a63fc74823c2b413ee8f45380dc5b21ad77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.10
|
Security for py-ipld-dag 0.3.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.