libipld 3.5.0__cp315-cp315-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libipld/__init__.py +21 -0
- libipld/_libipld.cp315-win_amd64.pyd +0 -0
- libipld/_libipld.pyi +127 -0
- libipld/py.typed +0 -0
- libipld-3.5.0.dist-info/METADATA +153 -0
- libipld-3.5.0.dist-info/RECORD +9 -0
- libipld-3.5.0.dist-info/WHEEL +4 -0
- libipld-3.5.0.dist-info/licenses/LICENSE +21 -0
- libipld-3.5.0.dist-info/sboms/libipld.cyclonedx.json +1097 -0
libipld/__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from ._libipld import (
|
|
2
|
+
decode_car,
|
|
3
|
+
decode_cid,
|
|
4
|
+
decode_dag_cbor,
|
|
5
|
+
decode_dag_cbor_multi,
|
|
6
|
+
decode_multibase,
|
|
7
|
+
encode_cid,
|
|
8
|
+
encode_dag_cbor,
|
|
9
|
+
encode_multibase,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
'decode_car',
|
|
14
|
+
'decode_cid',
|
|
15
|
+
'decode_dag_cbor',
|
|
16
|
+
'decode_dag_cbor_multi',
|
|
17
|
+
'decode_multibase',
|
|
18
|
+
'encode_cid',
|
|
19
|
+
'encode_dag_cbor',
|
|
20
|
+
'encode_multibase',
|
|
21
|
+
]
|
|
Binary file
|
libipld/_libipld.pyi
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
def decode_cid(data: str | bytes) -> dict[str, Any]:
|
|
4
|
+
"""Decode a CID from either its string representation or raw bytes.
|
|
5
|
+
|
|
6
|
+
Args:
|
|
7
|
+
data: Either a CID string (e.g. 'bafy...') or raw CID bytes
|
|
8
|
+
|
|
9
|
+
Returns:
|
|
10
|
+
A dict containing:
|
|
11
|
+
- version: int (0 or 1)
|
|
12
|
+
- codec: int (e.g. 113 for DAG-CBOR)
|
|
13
|
+
- hash: dict containing:
|
|
14
|
+
- code: int (hash algorithm code)
|
|
15
|
+
- size: int (hash size in bytes)
|
|
16
|
+
- digest: bytes (hash digest)
|
|
17
|
+
|
|
18
|
+
Raises:
|
|
19
|
+
ValueError: If the input is not a valid CID or is of an unsupported type.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def encode_cid(data: str | bytes) -> str:
|
|
23
|
+
"""Encode a CID to its string representation.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
data: Either a CID string (will be returned as-is) or raw CID bytes
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
A CID string (e.g. 'bafy...')
|
|
30
|
+
|
|
31
|
+
Raises:
|
|
32
|
+
ValueError: If the input is not a valid CID or is of an unsupported type.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def decode_car(data: bytes) -> tuple[dict[str, Any], dict[bytes, dict[str, Any]]]:
|
|
36
|
+
"""Decode a CAR file.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
data: Raw CAR file bytes
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
A tuple containing:
|
|
43
|
+
- header: dict (CAR header)
|
|
44
|
+
- blocks: dict mapping CID bytes to block data
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
ValueError: If the header or any block is malformed. This includes
|
|
48
|
+
a non-DAG-CBOR block codec and text strings that are not valid UTF-8.
|
|
49
|
+
RecursionError: If a block is nested deeper than sys.getrecursionlimit().
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
def decode_dag_cbor(data: bytes) -> Any:
|
|
53
|
+
"""Decode DAG-CBOR data to Python objects.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
data: Raw DAG-CBOR bytes
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
A Python object
|
|
60
|
+
|
|
61
|
+
Raises:
|
|
62
|
+
ValueError: If the data is malformed or is not strict DAG-CBOR. This
|
|
63
|
+
includes trailing data, unsupported tags, non-string map keys, and
|
|
64
|
+
text strings that are not valid UTF-8.
|
|
65
|
+
RecursionError: If the data is nested deeper than sys.getrecursionlimit().
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def decode_dag_cbor_multi(data: bytes) -> list[Any]:
|
|
69
|
+
"""Decode multiple DAG-CBOR objects from bytes.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
data: Raw DAG-CBOR bytes containing multiple objects
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
A list of Python objects
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
ValueError: If any object is malformed or is not strict DAG-CBOR. This
|
|
79
|
+
includes unsupported tags, non-string map keys, and text strings
|
|
80
|
+
that are not valid UTF-8.
|
|
81
|
+
RecursionError: If an object is nested deeper than sys.getrecursionlimit().
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
def encode_dag_cbor(data: Any) -> bytes:
|
|
85
|
+
"""Encode Python objects to DAG-CBOR.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
data: Any Python object that can be encoded to DAG-CBOR
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
Raw DAG-CBOR bytes
|
|
92
|
+
|
|
93
|
+
Raises:
|
|
94
|
+
ValueError: If the object cannot be represented in DAG-CBOR. This
|
|
95
|
+
includes unsupported types, integers outside the 64-bit range,
|
|
96
|
+
non-finite floats, and map keys that are not strings.
|
|
97
|
+
RecursionError: If the object is nested deeper than sys.getrecursionlimit().
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
def decode_multibase(data: str) -> tuple[str, bytes]:
|
|
101
|
+
"""Decode multibase-encoded data.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
data: Multibase-encoded string (e.g. 'ueWVzIG1hbmkgIQ')
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
A tuple containing:
|
|
108
|
+
- base: str (the base code, e.g. 'u')
|
|
109
|
+
- data: bytes (the decoded data)
|
|
110
|
+
|
|
111
|
+
Raises:
|
|
112
|
+
ValueError: If the input is not valid multibase.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
def encode_multibase(code: str, data: str | bytes) -> str:
|
|
116
|
+
"""Encode data using multibase.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
code: Base code (e.g. 'u' for base64url, 'z' for base58btc)
|
|
120
|
+
data: Data to encode (bytes or string that can be converted to bytes)
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
Multibase-encoded string
|
|
124
|
+
|
|
125
|
+
Raises:
|
|
126
|
+
ValueError: If the base code is unknown or the data is of an unsupported type.
|
|
127
|
+
"""
|
libipld/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: libipld
|
|
3
|
+
Version: 3.5.0
|
|
4
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: Intended Audience :: Information Technology
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Natural Language :: English
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Rust
|
|
11
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
12
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
22
|
+
Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
|
|
23
|
+
Classifier: Topic :: Software Development
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Topic :: Software Development :: Pre-processors
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Summary: Python binding to the Rust IPLD library
|
|
28
|
+
Keywords: ipld,cid,car,multibase,multihash,dag,cbor,dag-cbor,atproto,bluesky,rust
|
|
29
|
+
Author-email: "Ilya (Marshal)" <ilya@marshal.dev>
|
|
30
|
+
License-Expression: MIT
|
|
31
|
+
Requires-Python: >=3.8
|
|
32
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
33
|
+
Project-URL: Author, https://github.com/MarshalX
|
|
34
|
+
Project-URL: Changelog, https://github.com/MarshalX/python-libipld/blob/main/CHANGES.md
|
|
35
|
+
Project-URL: Homepage, https://github.com/MarshalX/python-libipld
|
|
36
|
+
Project-URL: Repository, https://github.com/MarshalX/python-libipld
|
|
37
|
+
Project-URL: Tracker, https://github.com/MarshalX/python-libipld/issues
|
|
38
|
+
|
|
39
|
+
## Python IPLD
|
|
40
|
+
|
|
41
|
+
> This project aims to speed up [The AT Protocol SDK](https://github.com/MarshalX/atproto) by using Rust for the heavy lifting. Only atproto related parts are implemented first.
|
|
42
|
+
|
|
43
|
+
Code snippet:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import libipld
|
|
47
|
+
|
|
48
|
+
# CID
|
|
49
|
+
print(libipld.decode_cid('bafyreig7jbijxpn4lfhvnvyuwf5u5jyhd7begxwyiqe7ingwxycjdqjjoa'))
|
|
50
|
+
# Output: {'hash': {'size': 32, 'code': 18, 'digest': b'\xdfHP\x9b\xbd\xbcYOV\xd7\x14\xb1{N\xa7\x07\x1f\xc2C^\xd8D\t\xf44\xd6\xbe\x04\x91\xc1)p'}, 'version': 1, 'codec': 113}
|
|
51
|
+
print(libipld.encode_cid(bytes.fromhex('01711220b6811a1d7f8c1791da6d1b4f136dc0e22679eafeaa58d64d7e2faad5890e9d9c')))
|
|
52
|
+
# Output: bafyreifwqenb274mc6i5u3i3j4jw3qhcez46v7vkldle27rpvlkysdu5tq
|
|
53
|
+
|
|
54
|
+
# DAG-CBOR
|
|
55
|
+
print(libipld.decode_dag_cbor(b'\xa2aa\x0cabfhello!'))
|
|
56
|
+
# Output: {'a': 12, 'b': 'hello!'}
|
|
57
|
+
print(libipld.encode_dag_cbor({'a': 12, 'b': 'hello!'}))
|
|
58
|
+
# Output: b'\xa2aa\x0cabfhello!'
|
|
59
|
+
|
|
60
|
+
# multibase
|
|
61
|
+
print(libipld.decode_multibase('ueWVzIG1hbmkgIQ'))
|
|
62
|
+
# Output: ('u', b'yes mani !')
|
|
63
|
+
print(libipld.encode_multibase('u', b'yes mani !'))
|
|
64
|
+
# Output: ueWVzIG1hbmkgIQ
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Features
|
|
68
|
+
|
|
69
|
+
#### 🔗 CID (Content Identifier) Operations
|
|
70
|
+
- **`decode_cid(data: str | bytes) -> dict[str, Any]`** - Decode CIDs from string representation (e.g., `'bafy...'`) or raw bytes into structured data containing version, codec, and hash information
|
|
71
|
+
- **`encode_cid(data: str | bytes) -> str`** - Encode CID raw bytes to string representation, or return string CIDs as-is
|
|
72
|
+
|
|
73
|
+
#### 📦 DAG-CBOR (Directed Acyclic Graph CBOR) Operations
|
|
74
|
+
- **`decode_dag_cbor(data: bytes) -> Any`** - Decode DAG-CBOR binary data into Python objects (dicts, lists, primitives)
|
|
75
|
+
- **`decode_dag_cbor_multi(data: bytes) -> list[Any]`** - Decode multiple concatenated DAG-CBOR objects from a single byte stream
|
|
76
|
+
- **`encode_dag_cbor(data: Any) -> bytes`** - Encode Python objects into DAG-CBOR binary format
|
|
77
|
+
|
|
78
|
+
#### 🌐 Multibase Operations
|
|
79
|
+
- **`decode_multibase(data: str) -> tuple[str, bytes]`** - Decode multibase-encoded strings, returning the base identifier and decoded data
|
|
80
|
+
- **`encode_multibase(code: str, data: str | bytes) -> str`** - Encode data using specified multibase encoding (e.g. `'u'` for base64url)
|
|
81
|
+
|
|
82
|
+
#### 🚗 CAR (Content Addressable Archives) Operations
|
|
83
|
+
- **`decode_car(data: bytes) -> tuple[dict[str, Any], dict[bytes, dict[str, Any]]]`** - Decode CAR files into header metadata and a mapping of CID bytes to block data
|
|
84
|
+
|
|
85
|
+
### Error handling
|
|
86
|
+
|
|
87
|
+
Every function raises `ValueError` for input it cannot decode or encode. The message starts with the failing operation (for example `Failed to read CAR block.`) followed by the reason.
|
|
88
|
+
|
|
89
|
+
The DAG-CBOR and CAR functions additionally raise `RecursionError` when the data is nested deeper than `sys.getrecursionlimit()`.
|
|
90
|
+
|
|
91
|
+
Inputs are validated strictly against the specifications. There is no option to skip validation or accept partially broken data. Data produced by third-party encoders is not always valid, so consumers of untrusted input (for example the AT Protocol firehose) should be prepared to catch `ValueError` per message and skip it.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import libipld
|
|
95
|
+
|
|
96
|
+
try:
|
|
97
|
+
header, blocks = libipld.decode_car(data)
|
|
98
|
+
except ValueError as e:
|
|
99
|
+
print(f'skipping malformed CAR: {e}')
|
|
100
|
+
except RecursionError:
|
|
101
|
+
print('skipping CAR with excessively nested block')
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Passing a value of the wrong type, such as a `str` where `bytes` is expected, raises `TypeError`.
|
|
105
|
+
|
|
106
|
+
### Requirements
|
|
107
|
+
|
|
108
|
+
- Python 3.8 or higher.
|
|
109
|
+
|
|
110
|
+
Prebuilt wheels are published for CPython 3.8-3.15, free-threaded CPython 3.14t and 3.15t, and PyPy 3.11.
|
|
111
|
+
|
|
112
|
+
### Installing
|
|
113
|
+
|
|
114
|
+
You can install or upgrade `libipld` via
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install -U libipld
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Performance
|
|
121
|
+
|
|
122
|
+
Benchmarks against [`cbrrr`](https://github.com/DavidBuchanan314/dag-cbrrr) (C), [`py-ipld-dag`](https://github.com/ipld/py-ipld-dag) (Python wrapper over Rust-backed [`cbor2`](https://github.com/agronholm/cbor2)) and [`dag_cbor`](https://github.com/hashberg-io/dag-cbor) (pure Python), measured on the four classic [nativejson-benchmark](https://github.com/miloyip/nativejson-benchmark) fixtures (round-tripped through DAG-CBOR). Bars are operations/second relative to pure-Python `dag_cbor`; higher is better.
|
|
123
|
+
|
|
124
|
+
Measured on Apple M1, macOS 27, CPython 3.14.0, `libipld` installed from PyPI (PGO + LTO wheel).
|
|
125
|
+
|
|
126
|
+
#### Deserialization
|
|
127
|
+
|
|
128
|
+

|
|
129
|
+
|
|
130
|
+
#### Serialization
|
|
131
|
+
|
|
132
|
+

|
|
133
|
+
|
|
134
|
+
Reproduce locally:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
cd benchmark && ./run.sh
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
See [`benchmark/README.md`](./benchmark/README.md) for details.
|
|
141
|
+
|
|
142
|
+
### Changelog
|
|
143
|
+
|
|
144
|
+
See [`CHANGES.md`](./CHANGES.md) for release notes.
|
|
145
|
+
|
|
146
|
+
### Contributing
|
|
147
|
+
|
|
148
|
+
Contributions of all sizes are welcome. See [`CONTRIBUTING.md`](./CONTRIBUTING.md) for setup, build, test, and benchmarking workflow.
|
|
149
|
+
|
|
150
|
+
### License
|
|
151
|
+
|
|
152
|
+
MIT – see [LICENSE](./LICENSE).
|
|
153
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
libipld/__init__.py,sha256=9bQr-7COJVsv8YJuw04SMqjMLWzGi30tLjmBs6JLs-I,379
|
|
2
|
+
libipld/_libipld.cp315-win_amd64.pyd,sha256=i5_15uG6FwuxJ3WB25ZzCtEcvGcLwR061xpYF6ttgg8,347648
|
|
3
|
+
libipld/_libipld.pyi,sha256=kfcidGl4ec86SdOLmngmjX3kg8b8sadWfEp_yecoaoc,3807
|
|
4
|
+
libipld/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
libipld-3.5.0.dist-info/METADATA,sha256=4WykNJxUhw_Ma8W0zjlKVUSc4LvfWk5n9_H-KqIxW9o,6807
|
|
6
|
+
libipld-3.5.0.dist-info/WHEEL,sha256=1_h6kx0k2_JFDbRzyfVOsGEcPlSNf1uBTnmW3MNufiU,97
|
|
7
|
+
libipld-3.5.0.dist-info/licenses/LICENSE,sha256=1rHe5-laS4bIzHm75nc104M2gyaxupSE72S334N-e0A,1076
|
|
8
|
+
libipld-3.5.0.dist-info/sboms/libipld.cyclonedx.json,sha256=s4wGF966SvLgu85ha2VVdx5QzjhAzMTf55xRG4Lb6yY,33468
|
|
9
|
+
libipld-3.5.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-2026 Ilya Siamionau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|