ipfs-node 0.1.12rc2__py3-none-android_28_arm64_v8a.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.
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.1
2
+ Name: ipfs_node
3
+ Version: 0.1.12rc2
4
+ Summary: Run an IPFS node inside of python using kubo as a library.
5
+ Author: Emendir
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/emendir/py_ipfs_node
8
+ Project-URL: Repository, https://github.com/emendir/py_ipfs_node
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ License-File: LICENSE-CC0
15
+ Dynamic: license-file
16
+ Requires-Dist: cffi >=1.15.0
17
+ Requires-Dist: ipfs-tk
18
+
19
+ # Kubo Python Library
20
+
21
+ A Python wrapper for the Kubo (Go-IPFS) library.
22
+
23
+ ## Overview
24
+
25
+ This library provides Python bindings for [Kubo](https://github.com/ipfs/kubo), the Go implementation of IPFS, allowing you to:
26
+
27
+ - Spawn an in-process IPFS node
28
+ - Add and retrieve files/directories from IPFS
29
+ - Connect to the IPFS network
30
+ - Manage IPFS repositories
31
+ - Publish and subscribe to IPFS PubSub topics
32
+ - Mount and connect to remote TCP services via libp2p
33
+
34
+ ## Project Status **EXPERIMENTAL**
35
+
36
+ This library is very early in its development, and is published as a proof-of-concept that it is feasible to write a python wrapper around kubo (Go-IPFS) to run IPFS nodes from within python.
37
+ Much of the code is LLM-generated, and code coverage is poor.
38
+
39
+ The API of this library WILL CHANGE in the near future!
40
+
41
+ So far this library has been tested on Linux x86 64-bit and Android ARM 64-bit (in Termux & in Kivy).
42
+ Assuming that it proves to be a reliable way of working in python, this library will be developed to maturity and maintained.
43
+
44
+ ## Compatibility
45
+
46
+ - linux x86-64 (tested on Ubuntu)
47
+ - linux arm-64 (tested on Ubuntu on a raspberry pi 5)
48
+
49
+ ## Roadmap
50
+
51
+ [py_ipfs_node](https://github.com/emendir/py_ipfs_node), will be incorporated into [ipfs_toolkit](https://github.com/emendir/IPFS-Toolkit-Python) [when py_ipfs_node's API has stabilised](https://github.com/emendir/py_ipfs_node/issues/1).
52
+
53
+ [ipfs_toolkit](https://github.com/emendir/IPFS-Toolkit-Python) will become a multimodal IPFS library with a unified API for alternative modes of using IPFS:
54
+ - running an embedded IPFS node
55
+ - interacting with a separate IPFS node via its HTTP RPC
56
+
57
+ You can check out a prototype version of the combination of these two libraries under the `kubo_python` branch of the IPFS-Toolkit repo:
58
+ https://github.com/emendir/IPFS-Toolkit-Python/tree/kubo_python
59
+
60
+ ## Installation
61
+
62
+ ```bash
63
+ pip install ipfs_node
64
+ ```
65
+
66
+ ## Dev Requirements
67
+
68
+ - Go 1.19
69
+ - Python 3.7+
70
+ - IPFS Kubo dependencies
71
+
72
+ ## Basic Usage
73
+
74
+ ### Working with Files
75
+
76
+ ```python
77
+ from ipfs_node import IpfsNode
78
+
79
+ # Create a new node with a temporary repository
80
+ with IpfsNode.ephemeral() as node:
81
+ # Add a file to IPFS
82
+ cid = node.files.publish("README.md")
83
+ print(f"Added file with CID: {cid}")
84
+
85
+ # Retrieve a file from IPFS
86
+ node.files.download(cid, "download.md")
87
+ ```
88
+
89
+ ### Using PubSub
90
+
91
+ ```python
92
+ from ipfs_node import IpfsNode
93
+
94
+ with IpfsNode.ephemeral() as node:
95
+ # Subscribe to a topic
96
+ with node.pubsub.subscribe("my-topic") as subscription:
97
+ # Publish a message
98
+ node.pubsub.publish("my-topic", "Hello, IPFS world!")
99
+
100
+ # Receive messages
101
+ message = subscription.next_message(timeout=2.0)
102
+ if message:
103
+ print(f"Received: {message.data.decode('utf-8')}")
104
+
105
+ # Or use a callback
106
+ def on_message(msg):
107
+ print(f"Received via callback: {msg.data.decode('utf-8')}")
108
+
109
+ subscription.subscribe(on_message)
110
+ ```
111
+
112
+ ### Using TCP Tunnels (LibP2P Stream Mounting)
113
+
114
+ ```python
115
+ from ipfs_node import IpfsNode
116
+
117
+ # Create an IPFS node
118
+ with IpfsNode.ephemeral() as node:
119
+
120
+ # Example 1: Listen for connections on a protocol and forward them to a local service
121
+ node.tunnels.open_listener("my-service", 8888)
122
+
123
+ # Example 2: Forward local connections to a remote peer
124
+ node.tunnels.open_sender("their-service", 8889, node.peer_id)
125
+
126
+ # List active listeners and streams
127
+ tunnels = node.tunnels.get_tunnels()
128
+ print(tunnels.listeners)
129
+ print(tunnels.senders)
130
+
131
+ # Close specific connections when done
132
+ node.tunnels.close_listener("my-service")
133
+ node.tunnels.close_sender("their-service")
134
+ ```
135
+
136
+ ## Documentation
137
+
138
+ - [Installation Instructions](INSTALL.md)
139
+ - [PubSub Documentation](docs/pubsub.md)
140
+ - [P2P Stream Mounting](docs/p2p.md)
141
+
142
+ ## Examples
143
+
144
+ - [Basic Usage](examples/basic_usage.py)
145
+ - [File Sharing](examples/file_sharing.py)
146
+ - [PubSub Example](examples/pubsub_example.py)
147
+ - [Chat Application](examples/chat_app.py)
148
+ - [P2P Stream Mounting](examples/p2p_example.py)
149
+ - [P2P Socket Communication](examples/p2p_socket_example.py)
150
+
151
+ ## Contributing
152
+
153
+ ### Get Involved
154
+
155
+ - GitHub Discussions: if you want to share ideas
156
+ - GitHub Issues: if you find bugs, other issues, or would like to submit feature requests
157
+ - GitHub Merge Requests: if you think you know what you're doing, you're very welcome!
158
+
159
+ ### Donations
160
+
161
+ To support me in my work on this and other projects, you can make donations with the following currencies:
162
+
163
+ - **Bitcoin:** `BC1Q45QEE6YTNGRC5TSZ42ZL3MWV8798ZEF70H2DG0`
164
+ - **Ethereum:** `0xA32C3bBC2106C986317f202B3aa8eBc3063323D4`
165
+ - [**Fiat** (via Credit or Debit Card, Apple Pay, Google Pay, Revolut Pay)](https://checkout.revolut.com/pay/4e4d24de-26cf-4e7d-9e84-ede89ec67f32)
166
+
167
+ Donations help me:
168
+ - dedicate more time to developing and maintaining open-source projects
169
+ - cover costs for IT infrastructure
170
+ - finance projects requiring additional hardware & compute
171
+
172
+ ## About the Developer
173
+
174
+ This project is developed by a human one-man team, publishing under the name _Emendir_.
175
+ I build open technologies trying to improve our world;
176
+ learning, working and sharing under the principle:
177
+
178
+ > _Freely I have received, freely I give._
179
+
180
+ Feel welcome to join in with code contributions, discussions, ideas and more!
181
+
182
+ ## Open-Source in the Public Domain
183
+
184
+ I dedicate this project to the public domain.
185
+ It is open source and free to use, share, modify, and build upon without restrictions or conditions.
186
+
187
+ I make no patent or trademark claims over this project.
188
+
189
+ Formally, you may use this project under either the:
190
+ - [MIT No Attribution (MIT-0)](https://choosealicense.com/licenses/mit-0/) or
191
+ - [Creative Commons Zero (CC0)](https://choosealicense.com/licenses/cc0-1.0/)
192
+ licence at your choice.
193
+
194
+
@@ -0,0 +1,19 @@
1
+ ipfs_node/__init__.py,sha256=hYyXSpnmMQLeaX2ssUVZl5ghbiVp-W2Ri_Dbdu9e1Jo,197
2
+ ipfs_node/ipfs_files.py,sha256=uM2u74VBRWwGGlSJNq_3A4_bYb7RdfIHXP5YVDDL43I,7985
3
+ ipfs_node/ipfs_node.py,sha256=E88bXvUjycwlPXAAa2pvRpQCANHGSFBWx9GQTIxRqsg,7287
4
+ ipfs_node/ipfs_peers.py,sha256=yp56fI9OpyzGg8JHt9o89lT2nWI4YpzMrRvUfETlPZc,2216
5
+ ipfs_node/ipfs_pubsub.py,sha256=g3mSV45BonYXZASgtWVGsi3VVSkZmOkBRldSRys6mlI,14439
6
+ ipfs_node/ipfs_tunnels.py,sha256=__681B9UzHXi7r1CP32uVEeMYlV8-O4JPc6yUKZwQ4M,9018
7
+ ipfs_node/utils/__init__.py,sha256=gskzZJEh_l3vsWbpgQII732lYNfqA835YXvMlxKiDkA,91
8
+ ipfs_node/utils/cid_utils.py,sha256=K5g8VIueJDS0zsbkJV8ZccFa6rdOA9ShwsYJlyX-REU,1457
9
+ ipfs_node/utils/peer_utils.py,sha256=ynZKbg2L26r0DfRUNYcVQQP_eguK6xENTFUhxHpHGmE,1848
10
+ libkubo/__init__.py,sha256=vg0PGjCRNyMadI3bRYtTjfxoaA6XMO7klgZuR2vQ2nU,67
11
+ libkubo/libkubo_android_28_arm64_v8a.h,sha256=h0wwA61bl-7youyYsLcCI_0dMiGzEFv0ato8j-x45uQ,5731
12
+ libkubo/libkubo_android_28_arm64_v8a.so,sha256=fXK8ghw9gncfp5ZDleqGj65T-afYFduuTmhUlUcHvX4,86189592
13
+ libkubo/libkubo_loader.py,sha256=kw1JoXpUxVRdtuhV9XqokSlzN2eiPA-7mzKqjX96lUE,2681
14
+ ipfs_node-0.1.12rc2.dist-info/LICENSE,sha256=i720OgyQLs68DSskm7ZLzaGKMnfskBIIHOuPWfwT2q4,907
15
+ ipfs_node-0.1.12rc2.dist-info/LICENSE-CC0,sha256=kXBMw0w0VVXQAbLjqMKmis4OngrPaK4HY9ScH6MdtxM,7038
16
+ ipfs_node-0.1.12rc2.dist-info/METADATA,sha256=R2Y_uF5hOjHVr5-wR-Q3ibV2_T3FKo6YIw4k0zNd76Q,6351
17
+ ipfs_node-0.1.12rc2.dist-info/WHEEL,sha256=KwHuuB9H22nvIAOyiKztrgMM-QBniZGqMjE6jssEJEA,110
18
+ ipfs_node-0.1.12rc2.dist-info/top_level.txt,sha256=JqYMx6doRQgowycGRhKqc0zfikahqizuG9128CZcF3Y,18
19
+ ipfs_node-0.1.12rc2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-android_28_arm64_v8a
5
+
@@ -0,0 +1,2 @@
1
+ ipfs_node
2
+ libkubo
libkubo/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from .libkubo_loader import libkubo, c_str, from_c_str, ffi, c_bool
@@ -0,0 +1,237 @@
1
+ /* Code generated by cmd/cgo; DO NOT EDIT. */
2
+
3
+ /* package github.com/emendir/py_ipfs_node/libkubo */
4
+
5
+
6
+ #line 1 "cgo-builtin-export-prolog"
7
+
8
+ #include <stddef.h>
9
+
10
+ #ifndef GO_CGO_EXPORT_PROLOGUE_H
11
+ #define GO_CGO_EXPORT_PROLOGUE_H
12
+
13
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
14
+ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15
+ #endif
16
+
17
+ #endif
18
+
19
+ /* Start of preamble from import "C" comments. */
20
+
21
+
22
+ #line 3 "files.go"
23
+ #include <stdlib.h>
24
+ #include <stdbool.h>
25
+
26
+ #line 1 "cgo-generated-wrapper"
27
+
28
+ #line 3 "p2p.go"
29
+
30
+ #include <stdlib.h>
31
+ #include <stdbool.h>
32
+
33
+ #line 1 "cgo-generated-wrapper"
34
+
35
+ #line 3 "peers.go"
36
+ #include <stdlib.h>
37
+
38
+ #line 1 "cgo-generated-wrapper"
39
+
40
+ #line 3 "pubsub.go"
41
+ #include <stdlib.h>
42
+
43
+ #line 1 "cgo-generated-wrapper"
44
+
45
+ #line 3 "repo.go"
46
+ #include <stdlib.h>
47
+
48
+ #line 1 "cgo-generated-wrapper"
49
+
50
+
51
+ /* End of preamble from import "C" comments. */
52
+
53
+
54
+ /* Start of boilerplate cgo prologue. */
55
+ #line 1 "cgo-gcc-export-header-prolog"
56
+
57
+ #ifndef GO_CGO_PROLOGUE_H
58
+ #define GO_CGO_PROLOGUE_H
59
+
60
+ typedef signed char GoInt8;
61
+ typedef unsigned char GoUint8;
62
+ typedef short GoInt16;
63
+ typedef unsigned short GoUint16;
64
+ typedef int GoInt32;
65
+ typedef unsigned int GoUint32;
66
+ typedef long long GoInt64;
67
+ typedef unsigned long long GoUint64;
68
+ typedef GoInt64 GoInt;
69
+ typedef GoUint64 GoUint;
70
+ typedef size_t GoUintptr;
71
+ typedef float GoFloat32;
72
+ typedef double GoFloat64;
73
+ #ifdef _MSC_VER
74
+ #include <complex.h>
75
+ typedef _Fcomplex GoComplex64;
76
+ typedef _Dcomplex GoComplex128;
77
+ #else
78
+ typedef float _Complex GoComplex64;
79
+ typedef double _Complex GoComplex128;
80
+ #endif
81
+
82
+ /*
83
+ static assertion to make sure the file is being used on architecture
84
+ at least with matching size of GoInt.
85
+ */
86
+ typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
87
+
88
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
89
+ typedef _GoString_ GoString;
90
+ #endif
91
+ typedef void *GoMap;
92
+ typedef void *GoChan;
93
+ typedef struct { void *t; void *v; } GoInterface;
94
+ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
95
+
96
+ #endif
97
+
98
+ /* End of boilerplate cgo prologue. */
99
+
100
+ #ifdef __cplusplus
101
+ extern "C" {
102
+ #endif
103
+
104
+
105
+ // AddFile adds a file to IPFS
106
+ //
107
+ extern char* AddFile(char* repoPath, char* filePath, _Bool onlyHash);
108
+
109
+ // FreeString is a no-op for now - we'll let Go's garbage collection handle the memory
110
+ //
111
+ extern void FreeString(char* str);
112
+
113
+ // Download retrieves a file or directory from IPFS
114
+ //
115
+ extern int Download(char* repoPath, char* cidStr, char* destPath);
116
+
117
+ // PinCID pins a CID to the IPFS node
118
+ //
119
+ extern int PinCID(char* repoPath, char* cidStr);
120
+
121
+ // UnpinCID unpins a CID from the IPFS node
122
+ //
123
+ extern int UnpinCID(char* repoPath, char* cidStr);
124
+
125
+ // ListPins returns a list of pinned CIDs
126
+ //
127
+ extern char* ListPins(char* repoPath);
128
+
129
+ // RemoveCID removes a pinned CID from IPFS (alias for UnpinCID for clarity)
130
+ //
131
+ extern int RemoveCID(char* repoPath, char* cidStr);
132
+
133
+ // P2PForward creates a libp2p stream mounting forwarding connection
134
+ //
135
+ extern int P2PForward(char* repoPath, char* proto, char* listenAddr, char* targetPeerID);
136
+
137
+ // P2PListen creates a libp2p service that listens for connections on the given protocol
138
+ //
139
+ extern int P2PListen(char* repoPath, char* proto, char* targetAddr);
140
+
141
+ // P2PClose closes p2p listener or stream
142
+ //
143
+ extern int P2PClose(char* repoPath, char* proto, char* listenAddr, char* targetAddr, _Bool _all, _Bool listeners, _Bool forwarders);
144
+
145
+ // P2PListListeners lists active p2p listeners
146
+ //
147
+ extern char* P2PListListeners(char* repoPath);
148
+
149
+ // P2PEnable ensures p2p functionality is enabled in the config
150
+ //
151
+ extern int P2PEnable(char* repoPath);
152
+
153
+ // P2PListForwards lists active p2p forwarding connections
154
+ //
155
+ extern char* P2PListForwards(char* repoPath);
156
+
157
+ // P2PCloseAllListeners closes all p2p listeners
158
+ //
159
+ extern int P2PCloseAllListeners(char* repoPath);
160
+
161
+ // P2PCloseAllForwards closes all p2p forwards
162
+ //
163
+ extern int P2PCloseAllForwards(char* repoPath);
164
+
165
+ // ConnectToPeer connects to a peer
166
+ //
167
+ extern int ConnectToPeer(char* repoPath, char* peerAddr);
168
+
169
+ // ListPeers connects to a peer
170
+ //
171
+ extern char* ListPeers(char* repoPath);
172
+
173
+ // ListPeers connects to a peer
174
+ //
175
+ extern char* ListPeersIDs(char* repoPath);
176
+
177
+ // FindPeer connects to a peer
178
+ //
179
+ extern char* FindPeer(char* repoPath, char* peerAddr, int timeOut);
180
+
181
+ // PubSubListTopics lists the topics the node is subscribed to
182
+ //
183
+ extern char* PubSubListTopics(char* repoPath);
184
+
185
+ // PubSubPublish publishes a message to a topic
186
+ //
187
+ extern int PubSubPublish(char* repoPath, char* topic, void* data, int dataLen);
188
+
189
+ // PubSubSubscribe subscribes to a topic
190
+ //
191
+ extern long long PubSubSubscribe(char* repoPath, char* topic);
192
+
193
+ // PubSubNextMessage gets the next message from a subscription
194
+ //
195
+ extern char* PubSubNextMessage(long long subID);
196
+
197
+ // PubSubUnsubscribe unsubscribes from a topic
198
+ //
199
+ extern int PubSubUnsubscribe(long long subID);
200
+
201
+ // PubSubPeers lists peers participating in a topic
202
+ //
203
+ extern char* PubSubPeers(char* repoPath, char* topic);
204
+
205
+ // PubSubCloseRepoSubscriptions closes all active pubsub subscriptions for a specific repository
206
+ //
207
+ extern int PubSubCloseRepoSubscriptions(char* repoPath);
208
+
209
+ // PubSubCloseAllSubscriptions closes all active pubsub subscriptions across all repositories
210
+ //
211
+ extern int PubSubCloseAllSubscriptions();
212
+
213
+ // CreateRepo initializes a new IPFS repository
214
+ //
215
+ extern int CreateRepo(char* repoPath);
216
+ extern int RunNode(char* repoPath);
217
+
218
+ // PubSubEnable enables pubsub on an IPFS node configuration
219
+ //
220
+ extern int PubSubEnable(char* repoPath);
221
+ extern char* TestGetString();
222
+
223
+ // GetNodeID gets the ID of the IPFS node
224
+ //
225
+ extern char* GetNodeID(char* repoPath);
226
+
227
+ // GetNodeMultiAddrs gets the ID of the IPFS node
228
+ //
229
+ extern char* GetNodeMultiAddrs(char* repoPath);
230
+
231
+ // CleanupNode explicitly releases a node by path
232
+ //
233
+ extern int CleanupNode(char* repoPath);
234
+
235
+ #ifdef __cplusplus
236
+ }
237
+ #endif
Binary file
@@ -0,0 +1,88 @@
1
+ import os
2
+ from cffi import FFI
3
+ import platform
4
+ from pathlib import Path
5
+
6
+ ffi = FFI()
7
+
8
+
9
+ def is_android() -> bool:
10
+ """Check if OS is android."""
11
+ if "ANDROID_ROOT" in os.environ and "ANDROID_DATA" in os.environ:
12
+ return True
13
+ return (
14
+ "android" in platform.release().lower()
15
+ or "android" in platform.version().lower()
16
+ )
17
+
18
+
19
+ system = platform.system()
20
+ machine = platform.machine().lower()
21
+
22
+ if system == "Windows":
23
+ if machine in ("x86_64", "amd64"):
24
+ lib_name = "libkubo_windows_x86_64.dll"
25
+ # header_name = "libkubo_windows_x86_64.h"
26
+ # windows header causes problems, so parse linux header instead
27
+ header_name = "libkubo_linux_x86_64.h"
28
+ # elif machine in ("aarch64", "arm64"):
29
+ # lib_name = "libkubo_windows_arm64.dll"
30
+ # header_name = "libkubo_windows_arm64.h"
31
+ else:
32
+ raise RuntimeError(f"Unsupported Windows architecture: {machine}")
33
+
34
+ elif system == "Darwin":
35
+ lib_name = "libkubo.dylib"
36
+ header_name = "libkubo.h"
37
+
38
+ elif system == "Linux":
39
+ if is_android():
40
+ if machine in ("aarch64", "arm64"):
41
+ lib_name = "libkubo_android_28_arm64_v8a.so"
42
+ header_name = "libkubo_android_28_arm64_v8a.h"
43
+ else:
44
+ raise RuntimeError(f"Unsupported Android arch: {machine}")
45
+ else:
46
+ if machine in ("x86_64", "amd64"):
47
+ lib_name = "libkubo_linux_x86_64.so"
48
+ header_name = "libkubo_linux_x86_64.h"
49
+ elif machine in ("aarch64", "arm64"):
50
+ lib_name = "libkubo_linux_arm64.so"
51
+ header_name = "libkubo_linux_arm64.h"
52
+ elif machine.startswith("armv7") or machine == "armv7l":
53
+ lib_name = "libkubo_linux_armhf.so"
54
+ header_name = "libkubo_linux_armhf.h"
55
+ else:
56
+ raise RuntimeError(f"Unsupported Linux architecture: {machine}")
57
+ else:
58
+ raise RuntimeError(f"Unsupported platform: {system} {machine}")
59
+
60
+ print(lib_name)
61
+ print(header_name)
62
+
63
+ # Get the absolute path to the library
64
+ lib_path = str(Path(__file__).parent / lib_name)
65
+ header_path = str(Path(__file__).parent / header_name)
66
+
67
+ with open(header_path) as file:
68
+ lines = [line.strip() for line in file.readlines()]
69
+ func_declarations = [
70
+ line for line in lines if line.startswith("extern ") and line.endswith(";")
71
+ ]
72
+ ffi.cdef("\n".join(func_declarations))
73
+ ffi.set_source("libkubo", None)
74
+ libkubo = ffi.dlopen(lib_path)
75
+
76
+
77
+ def c_str(data: str | bytes):
78
+ if isinstance(data, str):
79
+ data = data.encode()
80
+ return ffi.new("char[]", data)
81
+
82
+
83
+ def from_c_str(string_ptr):
84
+ return ffi.string(string_ptr).decode("utf-8")
85
+
86
+
87
+ def c_bool(value: bool):
88
+ return ffi.new("bool *", value)[0]