libipld 3.2.0__cp314-cp314-win32.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.cp314-win32.pyd +0 -0
- libipld/_libipld.pyi +101 -0
- libipld-3.2.0.dist-info/METADATA +101 -0
- libipld-3.2.0.dist-info/RECORD +7 -0
- libipld-3.2.0.dist-info/WHEEL +4 -0
- libipld-3.2.0.dist-info/licenses/LICENSE +21 -0
libipld/__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from ._libipld import (
|
|
2
|
+
decode_cid,
|
|
3
|
+
encode_cid,
|
|
4
|
+
encode_dag_cbor,
|
|
5
|
+
decode_car,
|
|
6
|
+
decode_dag_cbor,
|
|
7
|
+
decode_dag_cbor_multi,
|
|
8
|
+
decode_multibase,
|
|
9
|
+
encode_multibase,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"decode_cid",
|
|
14
|
+
"encode_cid",
|
|
15
|
+
"encode_dag_cbor",
|
|
16
|
+
"decode_car",
|
|
17
|
+
"decode_dag_cbor",
|
|
18
|
+
"decode_dag_cbor_multi",
|
|
19
|
+
"decode_multibase",
|
|
20
|
+
"encode_multibase",
|
|
21
|
+
]
|
|
Binary file
|
libipld/_libipld.pyi
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def decode_cid(data: str | bytes) -> dict[str, Any]:
|
|
6
|
+
"""Decode a CID from either its string representation or raw bytes.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
data: Either a CID string (e.g. 'bafy...') or raw CID bytes
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
A dict containing:
|
|
13
|
+
- version: int (0 or 1)
|
|
14
|
+
- codec: int (e.g. 113 for DAG-CBOR)
|
|
15
|
+
- hash: dict containing:
|
|
16
|
+
- code: int (hash algorithm code)
|
|
17
|
+
- size: int (hash size in bytes)
|
|
18
|
+
- digest: bytes (hash digest)
|
|
19
|
+
"""
|
|
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
|
+
|
|
32
|
+
|
|
33
|
+
def decode_car(data: bytes) -> tuple[dict[str, Any], dict[bytes, dict[str, Any]]]:
|
|
34
|
+
"""Decode a CAR file.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
data: Raw CAR file bytes
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
A tuple containing:
|
|
41
|
+
- header: dict (CAR header)
|
|
42
|
+
- blocks: dict mapping CID bytes to block data
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def decode_dag_cbor(data: bytes) -> Any:
|
|
47
|
+
"""Decode DAG-CBOR data to Python objects.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
data: Raw DAG-CBOR bytes
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
A Python object
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def decode_dag_cbor_multi(data: bytes) -> list[Any]:
|
|
58
|
+
"""Decode multiple DAG-CBOR objects from bytes.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
data: Raw DAG-CBOR bytes containing multiple objects
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
A list of Python objects
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def encode_dag_cbor(data: Any) -> bytes:
|
|
69
|
+
"""Encode Python objects to DAG-CBOR.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
data: Any Python object that can be encoded to DAG-CBOR
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Raw DAG-CBOR bytes
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def decode_multibase(data: str) -> tuple[str, bytes]:
|
|
80
|
+
"""Decode multibase-encoded data.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
data: Multibase-encoded string (e.g. 'ueWVzIG1hbmkgIQ')
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
A tuple containing:
|
|
87
|
+
- base: str (the base code, e.g. 'u')
|
|
88
|
+
- data: bytes (the decoded data)
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def encode_multibase(code: str, data: str | bytes) -> str:
|
|
93
|
+
"""Encode data using multibase.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
code: Base code (e.g. 'u' for base58btc)
|
|
97
|
+
data: Data to encode (bytes or string that can be converted to bytes)
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
Multibase-encoded string
|
|
101
|
+
"""
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: libipld
|
|
3
|
+
Version: 3.2.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: Topic :: Software Development
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Software Development :: Pre-processors
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Summary: Python binding to the Rust IPLD library
|
|
26
|
+
Keywords: library,lib,ipld,cid,multibase,multihash,dag,cbor,dag-cbor
|
|
27
|
+
Author-email: "Ilya (Marshal)" <ilya@marshal.dev>
|
|
28
|
+
License-Expression: MIT
|
|
29
|
+
Requires-Python: >=3.8
|
|
30
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
31
|
+
Project-URL: Homepage, https://github.com/MarshalX/python-libipld
|
|
32
|
+
Project-URL: Repository, https://github.com/MarshalX/python-libipld
|
|
33
|
+
Project-URL: Tracker, https://github.com/MarshalX/python-libipld/issues
|
|
34
|
+
Project-URL: Author, https://github.com/MarshalX
|
|
35
|
+
|
|
36
|
+
## Python IPLD
|
|
37
|
+
|
|
38
|
+
> 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.
|
|
39
|
+
|
|
40
|
+
Code snippet:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import libipld
|
|
44
|
+
|
|
45
|
+
# CID
|
|
46
|
+
print(libipld.decode_cid('bafyreig7jbijxpn4lfhvnvyuwf5u5jyhd7begxwyiqe7ingwxycjdqjjoa'))
|
|
47
|
+
# 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}
|
|
48
|
+
print(libipld.encode_cid(b'\x01q\x12 \xb6\x81\x1a\x1d\x7f\x8c\x17\x91\xdam\x1bO\x13m\xc0\xe2&y\xea\xfe\xaaX\xd6M~/\xaa\xd5\x89\x0e\x9d\x9c'))
|
|
49
|
+
# Output: bafyreifwqenb274mc6i5u3i3j4jw3qhcez46v7vkldle27rpvlkysdu5tq
|
|
50
|
+
|
|
51
|
+
# DAG-CBOR
|
|
52
|
+
print(libipld.decode_dag_cbor(b'\xa2aa\x0cabfhello!'))
|
|
53
|
+
# Output: {'a': 12, 'b': 'hello!'}
|
|
54
|
+
print(libipld.encode_dag_cbor({'a': 12, 'b': 'hello!'}))
|
|
55
|
+
# Output: b'\xa2aa\x0cabfhello!'
|
|
56
|
+
|
|
57
|
+
# multibase
|
|
58
|
+
print(libipld.decode_multibase('ueWVzIG1hbmkgIQ'))
|
|
59
|
+
# Output: ('u', b'yes mani !')
|
|
60
|
+
print(libipld.encode_multibase('u', b'yes mani !'))
|
|
61
|
+
# Output: ueWVzIG1hbmkgIQ
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Features
|
|
65
|
+
|
|
66
|
+
#### 🔗 CID (Content Identifier) Operations
|
|
67
|
+
- **`decode_cid(data: str | bytes) -> dict`** - Decode CIDs from string representation (e.g., `'bafy...'`) or raw bytes into structured data containing version, codec, and hash information
|
|
68
|
+
- **`encode_cid(data: str | bytes) -> str`** - Encode CID raw bytes to string representation, or return string CIDs as-is
|
|
69
|
+
|
|
70
|
+
#### 📦 DAG-CBOR (Directed Acyclic Graph CBOR) Operations
|
|
71
|
+
- **`decode_dag_cbor(data: bytes) -> Any`** - Decode DAG-CBOR binary data into Python objects (dicts, lists, primitives)
|
|
72
|
+
- **`decode_dag_cbor_multi(data: bytes) -> list[Any]`** - Decode multiple concatenated DAG-CBOR objects from a single byte stream
|
|
73
|
+
- **`encode_dag_cbor(data: Any) -> bytes`** - Encode Python objects into DAG-CBOR binary format
|
|
74
|
+
|
|
75
|
+
#### 🌐 Multibase Operations
|
|
76
|
+
- **`decode_multibase(data: str) -> tuple[str, bytes]`** - Decode multibase-encoded strings, returning the base identifier and decoded data
|
|
77
|
+
- **`encode_multibase(code: str, data: str | bytes) -> str`** - Encode data using specified multibase encoding (e.g., base58btc with code `'u'`)
|
|
78
|
+
|
|
79
|
+
#### 🚗 CAR (Content Addressable Archives) Operations
|
|
80
|
+
- **`decode_car(data: bytes) -> tuple[dict, dict[bytes, dict]]`** - Decode CAR files into header metadata and a mapping of CID bytes to block data
|
|
81
|
+
|
|
82
|
+
### Requirements
|
|
83
|
+
|
|
84
|
+
- Python 3.8 or higher.
|
|
85
|
+
|
|
86
|
+
### Installing
|
|
87
|
+
|
|
88
|
+
You can install or upgrade `libipld` via
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install -U libipld
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Contributing
|
|
95
|
+
|
|
96
|
+
Contributions of all sizes are welcome.
|
|
97
|
+
|
|
98
|
+
### License
|
|
99
|
+
|
|
100
|
+
MIT
|
|
101
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
libipld-3.2.0.dist-info/METADATA,sha256=45OrJM5sEBwrgh4mQn_oxTwYVk5SrKVwDPRSq836OUI,4344
|
|
2
|
+
libipld-3.2.0.dist-info/WHEEL,sha256=jjLk7AkOzjZGXfuKORLFExurHA-15F78Q65HbI_nDWE,92
|
|
3
|
+
libipld-3.2.0.dist-info/licenses/LICENSE,sha256=lbdJLFPnyIAYGzNS4yCvrJIztvI4FI5Zx5V1ZwH9oY0,1092
|
|
4
|
+
libipld/__init__.py,sha256=DAod-xoNrEZ8iUEmPlNBK3pCROoZL0v7plOS2GbgoAs,400
|
|
5
|
+
libipld/_libipld.cp314-win32.pyd,sha256=efk_xUsGuLusWGuMHpZrw1a_VTytnqOKY1KLYTm-b-A,361984
|
|
6
|
+
libipld/_libipld.pyi,sha256=He26syIZz_724I4kl7Y1YDubHPgFX57cRzfqslB2Yvg,2413
|
|
7
|
+
libipld-3.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 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.
|