ipld-dag-pb
An implementation of the DAG-PB spec for Python.
Install
pip install ipld-dag-pb
Usage
from ipld_dag_pb import PBNode, encode, decode, code
from multiformats import multihash, CID
node = PBNode("Some data as a string".encode("utf-8"))
encoded_bytes = encode(node)
# Alternatively:
# from ipld_dag_pb import prepare
# encoded_bytes = encode(prepare("Some data as a string"))
digest = multihash.digest(encoded_bytes, "sha2-256")
cid = CID("base32", 1, code, digest)
print(str(cid) + " => " + encoded_bytes.hex())
# bafybeibweq2akodv3uezac2g225qvjynh7lv3xv4wp5c4uxfppogtwt3fe => 0a15536f6d652064617461206173206120737472696e67
decoded_bytes = decode(encoded_bytes)
print(decoded_bytes)
print("decoded 'Data': " + bytes(decoded_bytes.data).decode("utf-8"))
# decoded 'Data': Some data as a string
prepare()
The DAG-PB encoding is very strict about the Data Model forms that are passed in. The objects must exactly resemble what they would if they were to undergo a round-trip of encode & decode. Therefore, extraneous or mistyped properties are not acceptable and will be rejected. See the DAG-PB spec for full details of the acceptable schema and additional constraints.
Due to this strictness, a prepare() function is made available which simplifies construction and allows for more flexible input forms. Prior to encoding objects, call prepare() to receive a new object that strictly conforms to the schema.
from ipld_dag_pb import prepare
from multiformats import CID
print(vars(prepare("Some data as a string")))
# -> {'data': b'Some data as a string', 'links': []}
print(vars(prepare({"links": [CID.decode("bafkqabiaaebagba")]})))
# -> {'data': None, 'links': [<ipld_dag_pb.node.PBLink object at 0x102c1b0e0>]}
Contributing
All welcome! storacha.network is open-source.
License
Dual-licensed under Apache-2.0 OR MIT
Metadata
Release files for ipld-dag-pb 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ipld_dag_pb-0.0.1.tar.gz | 21.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ipld_dag_pb-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.1 kB
Release files / ipld_dag_pb-0.0.1.tar.gz
| Download URL | ipld_dag_pb-0.0.1.tar.gz |
|---|---|
| Size | 21.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e205f613d6a0f4b276bfc2d40f0c07db173a0fd2f938862f867ce05f2eddd417
|
|
BLAKE2b-256 checksum How to use checksums |
73426a6cbb0cab9bd644d561b7f1023b20d8b84cabee739b35f2c473a53e5606
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / ipld_dag_pb-0.0.1-py3-none-any.whl
| Download URL | ipld_dag_pb-0.0.1-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc5fee4bff126571446a4ae5ac8342c05221759f995e7d4ded22ad9df33c8c89
|
|
BLAKE2b-256 checksum How to use checksums |
c89c7a042e1b5e54ea807300fd96123767e7251bcd2bd59312ba2e33376bad5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|