ipfs-node 0.1.12rc1__py3-none-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.
- ipfs_node/__init__.py +4 -0
- ipfs_node/ipfs_files.py +233 -0
- ipfs_node/ipfs_node.py +230 -0
- ipfs_node/ipfs_peers.py +71 -0
- ipfs_node/ipfs_pubsub.py +474 -0
- ipfs_node/ipfs_tunnels.py +263 -0
- ipfs_node/utils/__init__.py +3 -0
- ipfs_node/utils/cid_utils.py +55 -0
- ipfs_node/utils/peer_utils.py +62 -0
- ipfs_node-0.1.12rc1.dist-info/METADATA +194 -0
- ipfs_node-0.1.12rc1.dist-info/RECORD +20 -0
- ipfs_node-0.1.12rc1.dist-info/WHEEL +5 -0
- ipfs_node-0.1.12rc1.dist-info/licenses/LICENSE +18 -0
- ipfs_node-0.1.12rc1.dist-info/licenses/LICENSE-CC0 +121 -0
- ipfs_node-0.1.12rc1.dist-info/top_level.txt +2 -0
- libkubo/__init__.py +1 -0
- libkubo/libkubo_linux_x86_64.h +237 -0
- libkubo/libkubo_loader.py +88 -0
- libkubo/libkubo_windows_x86_64.dll +0 -0
- libkubo/libkubo_windows_x86_64.h +237 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import ctypes
|
|
2
|
+
import json
|
|
3
|
+
from typing import List, Dict, Optional, Tuple, Any, Union
|
|
4
|
+
from ipfs_tk_generics.tunnels import SenderTunnel, ListenerTunnel, TunnelsList, BaseTunnels
|
|
5
|
+
from libkubo import libkubo, c_str, from_c_str, ffi, c_bool
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class NodeTunnels(BaseTunnels):
|
|
12
|
+
"""
|
|
13
|
+
Provides P2P stream mounting functionality for IPFS nodes.
|
|
14
|
+
|
|
15
|
+
Stream mounting allows you to expose local TCP services to the libp2p network
|
|
16
|
+
and connect to remote TCP services exposed by other nodes.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, node):
|
|
20
|
+
self._node = node
|
|
21
|
+
self._repo_path = self._node._repo_path
|
|
22
|
+
BaseTunnels.__init__(self)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _enable_p2p(self) -> bool:
|
|
26
|
+
"""Enable p2p functionality in the IPFS configuration."""
|
|
27
|
+
|
|
28
|
+
repo_path = c_str(self._repo_path.encode('utf-8'))
|
|
29
|
+
result = libkubo.P2PEnable(repo_path)
|
|
30
|
+
|
|
31
|
+
if result <= 0:
|
|
32
|
+
print(f"Warning: Could not enable p2p functionality ({result})")
|
|
33
|
+
return False
|
|
34
|
+
return True
|
|
35
|
+
|
|
36
|
+
def open_sender(self, name: str, listen_addr: int | str, target_peer_id: str):
|
|
37
|
+
"""
|
|
38
|
+
Forward local connections to a remote peer.
|
|
39
|
+
|
|
40
|
+
This creates a new listener that forwards connections to the specified
|
|
41
|
+
peer over the libp2p network.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
name: The protocol name to use for the forwarding.
|
|
45
|
+
listen_addr: The local address to listen on (e.g. "127.0.0.1:8080").
|
|
46
|
+
target_peer_id: The peer ID to forward connections to.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
bool: True if the forwarding was set up successfully, False otherwise.
|
|
50
|
+
"""
|
|
51
|
+
# if not target_peer_id.startswith("/p2p/"):
|
|
52
|
+
# target_peer_id = f"/p2p/{target_peer_id}"
|
|
53
|
+
result = libkubo.P2PForward(
|
|
54
|
+
c_str(self._repo_path.encode('utf-8')),
|
|
55
|
+
c_str(name.encode('utf-8')),
|
|
56
|
+
c_str(self._port_to_addr(listen_addr).encode('utf-8')),
|
|
57
|
+
c_str(target_peer_id.encode('utf-8'))
|
|
58
|
+
)
|
|
59
|
+
if result > 0:
|
|
60
|
+
return
|
|
61
|
+
if result == -2:
|
|
62
|
+
print(f"Can't create sender {name} {listen_addr} {target_peer_id}")
|
|
63
|
+
raise Exception("IpfsNode.tunnels.open_sender: failed to open sender: bind: address already in use")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
raise Exception("IpfsNode.tunnels.open_sender: failed to open sender")
|
|
67
|
+
|
|
68
|
+
def open_listener(self, name: str, target_addr: int | str):
|
|
69
|
+
"""
|
|
70
|
+
Listen for libp2p connections and forward them to a local TCP service.
|
|
71
|
+
|
|
72
|
+
This exposes a local TCP service to the libp2p network.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
name: The protocol name to use for the listener.
|
|
76
|
+
target_addr: The local address to forward connections to (e.g. "127.0.0.1:8080").
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
bool: True if the listener was set up successfully, False otherwise.
|
|
80
|
+
"""
|
|
81
|
+
result = libkubo.P2PListen(
|
|
82
|
+
c_str(self._repo_path.encode('utf-8')),
|
|
83
|
+
c_str(name.encode('utf-8')),
|
|
84
|
+
c_str(self._port_to_addr(target_addr)))
|
|
85
|
+
if result > 0:
|
|
86
|
+
return
|
|
87
|
+
if result == -2:
|
|
88
|
+
print(f"Can't open listener {name} {target_addr}")
|
|
89
|
+
raise Exception("IpfsNode.tunnels.open_sender: failed to open listener")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
raise Exception("IpfsNode.tunnels.open_sender: failed to open listener")
|
|
93
|
+
|
|
94
|
+
def close_sender(self, name: str = None, port: int = None, peer_id: str = None) -> int:
|
|
95
|
+
"""
|
|
96
|
+
Close a specific TCP forwarding connection, optionally filtered by protocol, port, or peer ID.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
name: Optional protocol filter
|
|
100
|
+
port: Optional port filter
|
|
101
|
+
peer_id: Optional peer ID filter
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
int: Number of forwarding connections closed
|
|
105
|
+
"""
|
|
106
|
+
if peer_id and not peer_id.startswith("/p2p/"):
|
|
107
|
+
peer_id = f"/p2p/{peer_id}"
|
|
108
|
+
return self.close_tcp_connections(name, port, peer_id, senders=True, listeners=False)
|
|
109
|
+
|
|
110
|
+
def close_listener(self, name: str = None, port: int = None) -> int:
|
|
111
|
+
"""
|
|
112
|
+
Close a specific TCP listening connection, optionally filtered by protocol name or port.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
name: Optional protocol name filter
|
|
116
|
+
port: Optional port filter
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
int: Number of listening connections closed
|
|
120
|
+
"""
|
|
121
|
+
return self.close_tcp_connections(name, target_addr=port, listeners=True, senders=False)
|
|
122
|
+
|
|
123
|
+
def close_streams(self, name: str, port: int | None = None, target_peer_id: str = "") -> bool:
|
|
124
|
+
"""
|
|
125
|
+
Close a P2P listener or stream.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
name: The protocol name of the listener or stream to close.
|
|
129
|
+
listen_addr: For streams, the local address that the stream listens on.
|
|
130
|
+
target_peer_id: For streams, the peer ID that the stream connects to.
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
bool: True if the listener or stream was closed successfully, False otherwise.
|
|
134
|
+
"""
|
|
135
|
+
result = libkubo.P2PClose(
|
|
136
|
+
c_str(self._repo_path.encode('utf-8')),
|
|
137
|
+
c_str(name.encode('utf-8')),
|
|
138
|
+
c_str(self._port_to_addr(port)) if port else c_str(""),
|
|
139
|
+
c_str(target_peer_id.encode('utf-8'))
|
|
140
|
+
)
|
|
141
|
+
return result > 0
|
|
142
|
+
|
|
143
|
+
def close_tcp_connections(
|
|
144
|
+
self,
|
|
145
|
+
name: str = "", listen_addr: str | int | None = None, target_addr: str | int | None = None, all: bool = False,
|
|
146
|
+
listeners: bool = True, senders: bool = True
|
|
147
|
+
) -> int:
|
|
148
|
+
"""
|
|
149
|
+
Close specific TCP p2p connections, optionally filtered by protocol name, port, or peer ID.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
name: Optional protocol name filter
|
|
153
|
+
port: Optional port filter
|
|
154
|
+
peer_id: Optional peer ID filter
|
|
155
|
+
|
|
156
|
+
Returns:
|
|
157
|
+
int: Number of connections closed
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
repo_path = c_str(self._repo_path.encode('utf-8'))
|
|
161
|
+
|
|
162
|
+
result = libkubo.P2PClose(
|
|
163
|
+
repo_path, c_str(name),
|
|
164
|
+
c_str(self._port_to_addr(listen_addr)),
|
|
165
|
+
c_str(self._port_to_addr(target_addr)),
|
|
166
|
+
c_bool(all), c_bool(listeners), c_bool(senders)
|
|
167
|
+
)
|
|
168
|
+
return result
|
|
169
|
+
|
|
170
|
+
def close_all_senders(self) -> int:
|
|
171
|
+
"""
|
|
172
|
+
Close all TCP forwarding connections.
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
int: Number of forwarding connections closed
|
|
176
|
+
"""
|
|
177
|
+
return self.close_tcp_connections(all=True, listeners=False, senders=True)
|
|
178
|
+
|
|
179
|
+
def close_all_listeners(self) -> int:
|
|
180
|
+
"""
|
|
181
|
+
Close all TCP listening connections.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
int: Number of listening connections closed
|
|
185
|
+
"""
|
|
186
|
+
return self.close_tcp_connections(all=True, listeners=True, senders=False)
|
|
187
|
+
def close_all(self) -> int:
|
|
188
|
+
"""
|
|
189
|
+
Close all TCP connections.
|
|
190
|
+
|
|
191
|
+
Returns:
|
|
192
|
+
int: Number of listening connections closed
|
|
193
|
+
"""
|
|
194
|
+
return self.close_tcp_connections(all=True, listeners=True, senders=True)
|
|
195
|
+
|
|
196
|
+
def get_tunnels(self) ->TunnelsList:
|
|
197
|
+
"""
|
|
198
|
+
List all active P2P tunnels.
|
|
199
|
+
"""
|
|
200
|
+
result_ptr = libkubo.P2PListListeners(
|
|
201
|
+
c_str(self._repo_path.encode('utf-8'))
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
if not result_ptr:
|
|
205
|
+
return [], []
|
|
206
|
+
|
|
207
|
+
# Convert the C string to a Python string and release memory
|
|
208
|
+
result_str = from_c_str(result_ptr)
|
|
209
|
+
# libkubo.free(result_ptr)
|
|
210
|
+
|
|
211
|
+
if not result_str:
|
|
212
|
+
return [], []
|
|
213
|
+
|
|
214
|
+
# Parse the JSON
|
|
215
|
+
try:
|
|
216
|
+
result = json.loads(result_str)
|
|
217
|
+
except json.JSONDecodeError:
|
|
218
|
+
return [], []
|
|
219
|
+
|
|
220
|
+
# Add local listeners
|
|
221
|
+
listeners = []
|
|
222
|
+
for item in result.get('Listens', []):
|
|
223
|
+
listener = ListenerTunnel(
|
|
224
|
+
name=item.get('Protocol', ''),
|
|
225
|
+
# listen_address=item.get('ListenAddress', ''),
|
|
226
|
+
target_address=item.get('TargetAddress', '')
|
|
227
|
+
)
|
|
228
|
+
listeners.append(listener)
|
|
229
|
+
|
|
230
|
+
# Add remote listeners
|
|
231
|
+
forwarders = []
|
|
232
|
+
for item in result.get('Forwards', []):
|
|
233
|
+
listener = SenderTunnel(
|
|
234
|
+
name=item.get('Protocol', ''),
|
|
235
|
+
listen_address=item.get('ListenAddress', ''),
|
|
236
|
+
target_address=item.get('TargetAddress', '')
|
|
237
|
+
)
|
|
238
|
+
forwarders.append(listener)
|
|
239
|
+
|
|
240
|
+
# # Extract active streams
|
|
241
|
+
# streams = []
|
|
242
|
+
# for item in result.get('Streams', []):
|
|
243
|
+
# stream = P2PStream(
|
|
244
|
+
# name=item.get('Protocol', ''),
|
|
245
|
+
# origin_address=item.get('LocalAddr', ''),
|
|
246
|
+
# target_address=item.get('RemoteAddr', '')
|
|
247
|
+
# )
|
|
248
|
+
# streams.append(stream)
|
|
249
|
+
|
|
250
|
+
return TunnelsList(senders=forwarders, listeners=listeners)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _port_to_addr(self, addr: int | str | None) -> str:
|
|
254
|
+
if not addr:
|
|
255
|
+
return ""
|
|
256
|
+
if isinstance(addr, int):
|
|
257
|
+
return f"/ip4/{self._node._ipfs_host_ip()}/tcp/{addr}"
|
|
258
|
+
else:
|
|
259
|
+
return addr
|
|
260
|
+
def terminate(self):
|
|
261
|
+
pass
|
|
262
|
+
def __del__(self):
|
|
263
|
+
self.terminate()
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Utilities for working with IPFS Content Identifiers (CIDs).
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
# Regular expression for matching CID v0 (Qm...)
|
|
8
|
+
CID_V0_REGEX = re.compile(r"^Qm[1-9A-Za-z]{44}$")
|
|
9
|
+
|
|
10
|
+
# Regular expression for matching CID v1
|
|
11
|
+
CID_V1_REGEX = re.compile(r"^ba[a-zA-Z2-7]{57}$")
|
|
12
|
+
|
|
13
|
+
def is_valid_cid(cid: str) -> bool:
|
|
14
|
+
"""
|
|
15
|
+
Check if a string is a valid IPFS CID.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
cid: The Content Identifier to check.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
bool: True if the CID is valid, False otherwise.
|
|
22
|
+
"""
|
|
23
|
+
if not cid or not isinstance(cid, str):
|
|
24
|
+
return False
|
|
25
|
+
|
|
26
|
+
# Check for CID v0 (starts with "Qm" and is 46 characters long)
|
|
27
|
+
if CID_V0_REGEX.match(cid):
|
|
28
|
+
return True
|
|
29
|
+
|
|
30
|
+
# Check for CID v1 (starts with "ba" and is 59 characters long)
|
|
31
|
+
if CID_V1_REGEX.match(cid):
|
|
32
|
+
return True
|
|
33
|
+
|
|
34
|
+
# Could add more sophisticated validation here
|
|
35
|
+
return False
|
|
36
|
+
|
|
37
|
+
def format_cid_link(cid: str, gateway: str = "https://ipfs.io/ipfs/") -> str:
|
|
38
|
+
"""
|
|
39
|
+
Format a CID as a link through an IPFS gateway.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
cid: The Content Identifier.
|
|
43
|
+
gateway: The IPFS gateway URL. Defaults to the public ipfs.io gateway.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
str: The gateway URL for the CID.
|
|
47
|
+
"""
|
|
48
|
+
if not is_valid_cid(cid):
|
|
49
|
+
raise ValueError(f"Invalid CID: {cid}")
|
|
50
|
+
|
|
51
|
+
# Ensure the gateway URL ends with a slash
|
|
52
|
+
if not gateway.endswith("/"):
|
|
53
|
+
gateway += "/"
|
|
54
|
+
|
|
55
|
+
return f"{gateway}{cid}"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Utilities for working with IPFS peer addresses and connections.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
# Regular expression for matching multiaddress format
|
|
8
|
+
MULTIADDR_REGEX = re.compile(r"^(/[^/]+)+$")
|
|
9
|
+
|
|
10
|
+
# Regular expression for matching peer ID format (with multiaddress)
|
|
11
|
+
PEER_ID_REGEX = re.compile(r"/p2p/([a-zA-Z0-9]+)$")
|
|
12
|
+
|
|
13
|
+
def is_valid_multiaddr(addr: str) -> bool:
|
|
14
|
+
"""
|
|
15
|
+
Check if a string is a valid IPFS multiaddress.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
addr: The multiaddress to check.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
bool: True if the multiaddress is valid, False otherwise.
|
|
22
|
+
"""
|
|
23
|
+
if not addr or not isinstance(addr, str):
|
|
24
|
+
return False
|
|
25
|
+
|
|
26
|
+
# Basic check for multiaddress format
|
|
27
|
+
return bool(MULTIADDR_REGEX.match(addr))
|
|
28
|
+
|
|
29
|
+
def extract_peer_id(multiaddr: str) -> str:
|
|
30
|
+
"""
|
|
31
|
+
Extract the peer ID from a multiaddress.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
multiaddr: The multiaddress containing a peer ID.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
str: The peer ID, or an empty string if not found.
|
|
38
|
+
"""
|
|
39
|
+
if not is_valid_multiaddr(multiaddr):
|
|
40
|
+
return ""
|
|
41
|
+
|
|
42
|
+
# Find the peer ID component
|
|
43
|
+
match = PEER_ID_REGEX.search(multiaddr)
|
|
44
|
+
if match:
|
|
45
|
+
return match.group(1)
|
|
46
|
+
|
|
47
|
+
return ""
|
|
48
|
+
|
|
49
|
+
def get_bootstrap_peers() -> list:
|
|
50
|
+
"""
|
|
51
|
+
Get a list of default IPFS bootstrap peers.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
list: A list of multiaddresses for the default bootstrap peers.
|
|
55
|
+
"""
|
|
56
|
+
return [
|
|
57
|
+
"/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
|
|
58
|
+
"/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
|
|
59
|
+
"/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
|
|
60
|
+
"/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
|
|
61
|
+
"/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
|
|
62
|
+
]
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ipfs_node
|
|
3
|
+
Version: 0.1.12rc1
|
|
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
|
+
Requires-Dist: cffi>=1.15.0
|
|
16
|
+
Requires-Dist: ipfs_tk
|
|
17
|
+
Dynamic: license-file
|
|
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,20 @@
|
|
|
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
|
+
ipfs_node-0.1.12rc1.dist-info/licenses/LICENSE,sha256=i720OgyQLs68DSskm7ZLzaGKMnfskBIIHOuPWfwT2q4,907
|
|
11
|
+
ipfs_node-0.1.12rc1.dist-info/licenses/LICENSE-CC0,sha256=kXBMw0w0VVXQAbLjqMKmis4OngrPaK4HY9ScH6MdtxM,7038
|
|
12
|
+
libkubo/__init__.py,sha256=vg0PGjCRNyMadI3bRYtTjfxoaA6XMO7klgZuR2vQ2nU,67
|
|
13
|
+
libkubo/libkubo_linux_x86_64.h,sha256=OVfQ74CEPn8M6nDWkDQluwDgSeRJOV0wOyBAvBMGJqM,5743
|
|
14
|
+
libkubo/libkubo_loader.py,sha256=mkZkjZzqYw95jawRnc3DYyMRLZxBMOPzNrxfEP62aeg,2667
|
|
15
|
+
libkubo/libkubo_windows_x86_64.dll,sha256=D50h0KoLL5A03WYncWIBMithzW94GFQQAGoFmaO9EDw,28926981
|
|
16
|
+
libkubo/libkubo_windows_x86_64.h,sha256=sN7g_DZZHQavzjRqsIxepZaCrRJbLhGXOT9DQMZ18b0,6491
|
|
17
|
+
ipfs_node-0.1.12rc1.dist-info/METADATA,sha256=cEPbGklEOvUpGRSvcEZX6_3xEhXP4B9kHeDqgOfSY4c,6350
|
|
18
|
+
ipfs_node-0.1.12rc1.dist-info/WHEEL,sha256=ZjXRCNaQ9YSypEK2TE0LRB0sy2OVXSszb4Sx1XjM99k,97
|
|
19
|
+
ipfs_node-0.1.12rc1.dist-info/top_level.txt,sha256=JqYMx6doRQgowycGRhKqc0zfikahqizuG9128CZcF3Y,18
|
|
20
|
+
ipfs_node-0.1.12rc1.dist-info/RECORD,,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT No Attribution
|
|
2
|
+
|
|
3
|
+
Copyright [year] [fullname]
|
|
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.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
13
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
14
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
15
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
16
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
17
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
18
|
+
SOFTWARE.
|