aleph-cid 0.1.0__tar.gz

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.
@@ -0,0 +1,82 @@
1
+ Metadata-Version: 2.4
2
+ Name: aleph-cid
3
+ Version: 0.1.0
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: Operating System :: OS Independent
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Rust
9
+ Classifier: Topic :: System :: Filesystems
10
+ Summary: kubo-compatible IPFS CID computation for Aleph Cloud, backed by the aleph-cid Rust crate
11
+ Keywords: ipfs,cid,unixfs,car,aleph
12
+ Author: Aleph Cloud
13
+ License-Expression: MIT
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
16
+ Project-URL: Issues, https://github.com/aleph-im/aleph-rs/issues
17
+ Project-URL: Repository, https://github.com/aleph-im/aleph-rs
18
+
19
+ # aleph-cid (Python)
20
+
21
+ kubo-compatible IPFS CID computation for [Aleph Cloud](https://aleph.cloud), backed by the
22
+ [`aleph-cid`](https://crates.io/crates/aleph-cid) Rust crate. Computes the exact CIDs that
23
+ kubo would assign, without running an IPFS node: streaming file hashing (CIDv0 and CIDv1),
24
+ UnixFS folder DAGs (plain and HAMT-sharded directories), and CARv1 packing.
25
+
26
+ All hashing releases the GIL, so it can run on worker threads without blocking the
27
+ interpreter.
28
+
29
+ ## Install
30
+
31
+ ```sh
32
+ pip install aleph-cid
33
+ ```
34
+
35
+ Prebuilt abi3 wheels cover CPython 3.10+ on Linux (x86_64, aarch64), macOS, and Windows.
36
+
37
+ ## Usage
38
+
39
+ ```python
40
+ import aleph_cid
41
+
42
+ # One-shot CIDv0 (kubo `ipfs add` default)
43
+ aleph_cid.compute_cid(b"hello\n")
44
+
45
+ # Streaming, for large files
46
+ hasher = aleph_cid.CidHasher.for_ipfs_v1_raw_leaves()
47
+ with open("video.mp4", "rb") as f:
48
+ while chunk := f.read(1 << 20):
49
+ hasher.update(chunk)
50
+ cid = hasher.finalize()
51
+
52
+ # Verify data against an existing CID of any supported flavor
53
+ hasher = aleph_cid.CidHasher.for_expected(cid)
54
+ hasher.update(data)
55
+ assert hasher.finalize() == cid
56
+
57
+ # Folder root CID, matching kubo `/api/v0/add?wrap-with-directory=true`
58
+ root = aleph_cid.hash_folder("./site", cid_version=1)
59
+
60
+ # Pack a folder into a CARv1 file (for `/api/v0/ipfs/add_car` uploads)
61
+ root = aleph_cid.write_folder_car("./site", "site.car")
62
+ assert aleph_cid.read_carv1_root("site.car") == root
63
+ ```
64
+
65
+ ## Compatibility
66
+
67
+ CIDs match kubo defaults: sha2-256, 256 KiB chunks, balanced DAGs with 174 links per node,
68
+ dag-pb leaves for CIDv0 and raw leaves for CIDv1, directories HAMT-sharded above 256 KiB
69
+ of link data. Golden tests pin the output against real kubo.
70
+
71
+ ## Development
72
+
73
+ Built with [maturin](https://www.maturin.rs):
74
+
75
+ ```sh
76
+ cd crates/aleph-cid-python
77
+ python -m venv .venv && . .venv/bin/activate
78
+ pip install maturin pytest
79
+ maturin develop
80
+ pytest
81
+ ```
82
+
@@ -0,0 +1,63 @@
1
+ # aleph-cid (Python)
2
+
3
+ kubo-compatible IPFS CID computation for [Aleph Cloud](https://aleph.cloud), backed by the
4
+ [`aleph-cid`](https://crates.io/crates/aleph-cid) Rust crate. Computes the exact CIDs that
5
+ kubo would assign, without running an IPFS node: streaming file hashing (CIDv0 and CIDv1),
6
+ UnixFS folder DAGs (plain and HAMT-sharded directories), and CARv1 packing.
7
+
8
+ All hashing releases the GIL, so it can run on worker threads without blocking the
9
+ interpreter.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ pip install aleph-cid
15
+ ```
16
+
17
+ Prebuilt abi3 wheels cover CPython 3.10+ on Linux (x86_64, aarch64), macOS, and Windows.
18
+
19
+ ## Usage
20
+
21
+ ```python
22
+ import aleph_cid
23
+
24
+ # One-shot CIDv0 (kubo `ipfs add` default)
25
+ aleph_cid.compute_cid(b"hello\n")
26
+
27
+ # Streaming, for large files
28
+ hasher = aleph_cid.CidHasher.for_ipfs_v1_raw_leaves()
29
+ with open("video.mp4", "rb") as f:
30
+ while chunk := f.read(1 << 20):
31
+ hasher.update(chunk)
32
+ cid = hasher.finalize()
33
+
34
+ # Verify data against an existing CID of any supported flavor
35
+ hasher = aleph_cid.CidHasher.for_expected(cid)
36
+ hasher.update(data)
37
+ assert hasher.finalize() == cid
38
+
39
+ # Folder root CID, matching kubo `/api/v0/add?wrap-with-directory=true`
40
+ root = aleph_cid.hash_folder("./site", cid_version=1)
41
+
42
+ # Pack a folder into a CARv1 file (for `/api/v0/ipfs/add_car` uploads)
43
+ root = aleph_cid.write_folder_car("./site", "site.car")
44
+ assert aleph_cid.read_carv1_root("site.car") == root
45
+ ```
46
+
47
+ ## Compatibility
48
+
49
+ CIDs match kubo defaults: sha2-256, 256 KiB chunks, balanced DAGs with 174 links per node,
50
+ dag-pb leaves for CIDv0 and raw leaves for CIDv1, directories HAMT-sharded above 256 KiB
51
+ of link data. Golden tests pin the output against real kubo.
52
+
53
+ ## Development
54
+
55
+ Built with [maturin](https://www.maturin.rs):
56
+
57
+ ```sh
58
+ cd crates/aleph-cid-python
59
+ python -m venv .venv && . .venv/bin/activate
60
+ pip install maturin pytest
61
+ maturin develop
62
+ pytest
63
+ ```
@@ -0,0 +1,31 @@
1
+ [package]
2
+ name = "aleph-cid"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+ description = "kubo-compatible IPFS CID computation for Aleph Cloud: UnixFS dag-pb hashing, HAMT-sharded directories and CARv1 framing."
6
+ license = "MIT"
7
+ repository = "https://github.com/aleph-im/aleph-rs"
8
+ homepage = "https://github.com/aleph-im/aleph-rs"
9
+
10
+ [dependencies]
11
+ bs58 = "^0.5"
12
+ cid = "^0.11"
13
+ multihash = "^0.19"
14
+ murmur3 = "^0.5"
15
+ prost = "^0.13"
16
+ serde = { version = "^1.0.228", optional = true, features = ["derive"] }
17
+ sha2 = "^0.10.9"
18
+ thiserror = "^2.0.17"
19
+ walkdir = "^2"
20
+
21
+ [features]
22
+ default = []
23
+ # serde impls for `cid::Cid` (string round-trip). Enabled by aleph-types.
24
+ serde = ["dep:serde"]
25
+
26
+ [dev-dependencies]
27
+ multihash-codetable = { version = "^0.1", features = ["sha2"] }
28
+ reqwest = { version = "^0.13.2", features = ["json", "stream", "multipart"] }
29
+ serde_json = "^1.0.145"
30
+ tempfile = "^3"
31
+ tokio = { version = "^1.48.0", features = ["rt", "rt-multi-thread", "macros", "fs", "sync", "time"] }
@@ -0,0 +1,13 @@
1
+ syntax = "proto2";
2
+ package merkledag;
3
+
4
+ message PBLink {
5
+ optional bytes Hash = 1;
6
+ optional string Name = 2;
7
+ optional uint64 Tsize = 3;
8
+ }
9
+
10
+ message PBNode {
11
+ repeated PBLink Links = 2;
12
+ optional bytes Data = 1;
13
+ }
@@ -0,0 +1,20 @@
1
+ syntax = "proto2";
2
+ package unixfs;
3
+
4
+ enum DataType {
5
+ Raw = 0;
6
+ Directory = 1;
7
+ File = 2;
8
+ Metadata = 3;
9
+ Symlink = 4;
10
+ HAMTShard = 5;
11
+ }
12
+
13
+ message Data {
14
+ required DataType Type = 1;
15
+ optional bytes Data = 2;
16
+ optional uint64 filesize = 3;
17
+ repeated uint64 blocksizes = 4;
18
+ optional uint64 hashType = 5;
19
+ optional uint64 fanout = 6;
20
+ }