ipfs-node 0.1.6__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.
- ipfs_node-0.1.6/INSTALL.md +63 -0
- ipfs_node-0.1.6/LICENSE +21 -0
- ipfs_node-0.1.6/MANIFEST.in +8 -0
- ipfs_node-0.1.6/PKG-INFO +134 -0
- ipfs_node-0.1.6/README.md +119 -0
- ipfs_node-0.1.6/examples/basic_usage.py +64 -0
- ipfs_node-0.1.6/examples/chat_app.py +413 -0
- ipfs_node-0.1.6/examples/file_sharing.py +83 -0
- ipfs_node-0.1.6/examples/p2p_example.py +132 -0
- ipfs_node-0.1.6/examples/p2p_socket_example.py +216 -0
- ipfs_node-0.1.6/examples/pubsub_example.py +114 -0
- ipfs_node-0.1.6/examples/pubsub_simple_test.py +79 -0
- ipfs_node-0.1.6/setup.cfg +4 -0
- ipfs_node-0.1.6/setup.py +130 -0
- ipfs_node-0.1.6/src/ipfs_node/__init__.py +4 -0
- ipfs_node-0.1.6/src/ipfs_node/ipfs_files.py +233 -0
- ipfs_node-0.1.6/src/ipfs_node/ipfs_node.py +230 -0
- ipfs_node-0.1.6/src/ipfs_node/ipfs_peers.py +71 -0
- ipfs_node-0.1.6/src/ipfs_node/ipfs_pubsub.py +474 -0
- ipfs_node-0.1.6/src/ipfs_node/ipfs_tunnels.py +263 -0
- ipfs_node-0.1.6/src/ipfs_node/libkubo/libkubo_linux_x86_64.h +237 -0
- ipfs_node-0.1.6/src/ipfs_node/libkubo/libkubo_linux_x86_64.so +0 -0
- ipfs_node-0.1.6/src/ipfs_node/utils/__init__.py +3 -0
- ipfs_node-0.1.6/src/ipfs_node/utils/cid_utils.py +55 -0
- ipfs_node-0.1.6/src/ipfs_node/utils/peer_utils.py +62 -0
- ipfs_node-0.1.6/src/ipfs_node.egg-info/PKG-INFO +134 -0
- ipfs_node-0.1.6/src/ipfs_node.egg-info/SOURCES.txt +35 -0
- ipfs_node-0.1.6/src/ipfs_node.egg-info/dependency_links.txt +1 -0
- ipfs_node-0.1.6/src/ipfs_node.egg-info/requires.txt +1 -0
- ipfs_node-0.1.6/src/ipfs_node.egg-info/top_level.txt +2 -0
- ipfs_node-0.1.6/src/libkubo/__init__.py +1 -0
- ipfs_node-0.1.6/src/libkubo/libkubo_loader.py +45 -0
- ipfs_node-0.1.6/tests/test_all.py +11 -0
- ipfs_node-0.1.6/tests/test_peers.py +48 -0
- ipfs_node-0.1.6/tests/test_pubsub.py +149 -0
- ipfs_node-0.1.6/tests/test_tunnels.py +91 -0
- ipfs_node-0.1.6/tests/test_utils.py +94 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Installation Instructions
|
|
2
|
+
|
|
3
|
+
## Prerequisites
|
|
4
|
+
|
|
5
|
+
Before installing the Kubo Python library, ensure you have the following prerequisites:
|
|
6
|
+
|
|
7
|
+
1. **Go**: Version 1.19 is required to compile the Go IPFS bindings.
|
|
8
|
+
- Install from [golang.org](https://golang.org/doc/install)
|
|
9
|
+
- Verify with `go version`
|
|
10
|
+
|
|
11
|
+
2. **Python**: Version 3.7 or later.
|
|
12
|
+
- Verify with `python --version` or `python3 --version`
|
|
13
|
+
|
|
14
|
+
3. **C Compiler**: Required for building the shared library.
|
|
15
|
+
- Linux: GCC (`sudo apt install build-essential`)
|
|
16
|
+
- macOS: Xcode Command Line Tools (`xcode-select --install`)
|
|
17
|
+
- Windows: MinGW or Visual C++ Build Tools
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
### Option 1: Install from PyPI (Not available yet)
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install ipfs_node
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Option 2: Install from Source
|
|
28
|
+
|
|
29
|
+
1. Clone the repository:
|
|
30
|
+
```bash
|
|
31
|
+
git clone https://github.com/emendir/py_ipfs_node.git
|
|
32
|
+
cd ipfs_node
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. Install the package:
|
|
36
|
+
```bash
|
|
37
|
+
pip install -e .
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
This will:
|
|
41
|
+
- Download the Kubo Go dependencies
|
|
42
|
+
- Compile the shared library
|
|
43
|
+
- Install the Python package in development mode
|
|
44
|
+
|
|
45
|
+
3. If installation fails because of Go compilation errors, you can manually build the Go library:
|
|
46
|
+
```bash
|
|
47
|
+
rm -f src/ipfs_node/lib/libkubo* # OPTIONAL: Remove the compiled library
|
|
48
|
+
|
|
49
|
+
./src/libkubo/compile_linux.sh # Linux
|
|
50
|
+
./src/libkubo/compile_android.sh # Android
|
|
51
|
+
pip install -e .
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## Verifying Installation
|
|
57
|
+
|
|
58
|
+
Run the example script to verify your installation:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python examples/basic_usage.py
|
|
62
|
+
```
|
|
63
|
+
|
ipfs_node-0.1.6/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
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.
|
ipfs_node-0.1.6/PKG-INFO
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ipfs_node
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: Run an IPFS node inside of python using kubo as a library.
|
|
5
|
+
Home-page: https://github.com/emendir/py_ipfs_node
|
|
6
|
+
Author: Emendir
|
|
7
|
+
Author-email:
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: cffi>=1.15.0
|
|
15
|
+
|
|
16
|
+
# Kubo Python Library
|
|
17
|
+
|
|
18
|
+
A Python wrapper for the Kubo (Go-IPFS) library.
|
|
19
|
+
|
|
20
|
+
## Overview
|
|
21
|
+
|
|
22
|
+
This library provides Python bindings for [Kubo](https://github.com/ipfs/kubo), the Go implementation of IPFS, allowing you to:
|
|
23
|
+
|
|
24
|
+
- Spawn an in-process IPFS node
|
|
25
|
+
- Add and retrieve files/directories from IPFS
|
|
26
|
+
- Connect to the IPFS network
|
|
27
|
+
- Manage IPFS repositories
|
|
28
|
+
- Publish and subscribe to IPFS PubSub topics
|
|
29
|
+
- Mount and connect to remote TCP services via libp2p
|
|
30
|
+
|
|
31
|
+
## Project Status
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
Much of the code is LLM-generated, and code coverage is poor.
|
|
35
|
+
|
|
36
|
+
The API structure of this library WILL CHANGE in the near future!
|
|
37
|
+
|
|
38
|
+
So far this library has been tested on Linux x86 64-bit and Android ARM 64-bit (in Termux & in Kivy).
|
|
39
|
+
Assuming that it proves to be a reliable way of working in python, this library will be developed to maturity and maintained.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install ipfs_node
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Dev Requirements
|
|
48
|
+
|
|
49
|
+
- Go 1.19
|
|
50
|
+
- Python 3.7+
|
|
51
|
+
- IPFS Kubo dependencies
|
|
52
|
+
|
|
53
|
+
## Basic Usage
|
|
54
|
+
|
|
55
|
+
### Working with Files
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from ipfs_node import IpfsNode
|
|
59
|
+
|
|
60
|
+
# Create a new node with a temporary repository
|
|
61
|
+
with IpfsNode.ephemeral() as node:
|
|
62
|
+
# Add a file to IPFS
|
|
63
|
+
cid = node.files.publish("README.md")
|
|
64
|
+
print(f"Added file with CID: {cid}")
|
|
65
|
+
|
|
66
|
+
# Retrieve a file from IPFS
|
|
67
|
+
node.files.download(cid, "download.md")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Using PubSub
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from ipfs_node import IpfsNode
|
|
74
|
+
|
|
75
|
+
with IpfsNode.ephemeral() as node:
|
|
76
|
+
# Subscribe to a topic
|
|
77
|
+
with node.pubsub.subscribe("my-topic") as subscription:
|
|
78
|
+
# Publish a message
|
|
79
|
+
node.pubsub.publish("my-topic", "Hello, IPFS world!")
|
|
80
|
+
|
|
81
|
+
# Receive messages
|
|
82
|
+
message = subscription.next_message(timeout=2.0)
|
|
83
|
+
if message:
|
|
84
|
+
print(f"Received: {message.data.decode('utf-8')}")
|
|
85
|
+
|
|
86
|
+
# Or use a callback
|
|
87
|
+
def on_message(msg):
|
|
88
|
+
print(f"Received via callback: {msg.data.decode('utf-8')}")
|
|
89
|
+
|
|
90
|
+
subscription.subscribe(on_message)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Using TCP Tunnels (LibP2P Stream Mounting)
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from ipfs_node import IpfsNode
|
|
97
|
+
|
|
98
|
+
# Create an IPFS node
|
|
99
|
+
with IpfsNode.ephemeral() as node:
|
|
100
|
+
|
|
101
|
+
# Example 1: Listen for connections on a protocol and forward them to a local service
|
|
102
|
+
node.tunnels.open_listener("my-service", 8888)
|
|
103
|
+
|
|
104
|
+
# Example 2: Forward local connections to a remote peer
|
|
105
|
+
node.tunnels.open_sender("their-service", 8889, node.peer_id)
|
|
106
|
+
|
|
107
|
+
# List active listeners and streams
|
|
108
|
+
tunnels = node.tunnels.get_tunnels()
|
|
109
|
+
print(tunnels.listeners)
|
|
110
|
+
print(tunnels.senders)
|
|
111
|
+
|
|
112
|
+
# Close specific connections when done
|
|
113
|
+
node.tunnels.close_listener("my-service")
|
|
114
|
+
node.tunnels.close_sender("their-service")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Documentation
|
|
118
|
+
|
|
119
|
+
- [Installation Instructions](INSTALL.md)
|
|
120
|
+
- [PubSub Documentation](docs/pubsub.md)
|
|
121
|
+
- [P2P Stream Mounting](docs/p2p.md)
|
|
122
|
+
|
|
123
|
+
## Examples
|
|
124
|
+
|
|
125
|
+
- [Basic Usage](examples/basic_usage.py)
|
|
126
|
+
- [File Sharing](examples/file_sharing.py)
|
|
127
|
+
- [PubSub Example](examples/pubsub_example.py)
|
|
128
|
+
- [Chat Application](examples/chat_app.py)
|
|
129
|
+
- [P2P Stream Mounting](examples/p2p_example.py)
|
|
130
|
+
- [P2P Socket Communication](examples/p2p_socket_example.py)
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT License
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Kubo Python Library
|
|
2
|
+
|
|
3
|
+
A Python wrapper for the Kubo (Go-IPFS) library.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This library provides Python bindings for [Kubo](https://github.com/ipfs/kubo), the Go implementation of IPFS, allowing you to:
|
|
8
|
+
|
|
9
|
+
- Spawn an in-process IPFS node
|
|
10
|
+
- Add and retrieve files/directories from IPFS
|
|
11
|
+
- Connect to the IPFS network
|
|
12
|
+
- Manage IPFS repositories
|
|
13
|
+
- Publish and subscribe to IPFS PubSub topics
|
|
14
|
+
- Mount and connect to remote TCP services via libp2p
|
|
15
|
+
|
|
16
|
+
## Project Status
|
|
17
|
+
|
|
18
|
+
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.
|
|
19
|
+
Much of the code is LLM-generated, and code coverage is poor.
|
|
20
|
+
|
|
21
|
+
The API structure of this library WILL CHANGE in the near future!
|
|
22
|
+
|
|
23
|
+
So far this library has been tested on Linux x86 64-bit and Android ARM 64-bit (in Termux & in Kivy).
|
|
24
|
+
Assuming that it proves to be a reliable way of working in python, this library will be developed to maturity and maintained.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install ipfs_node
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Dev Requirements
|
|
33
|
+
|
|
34
|
+
- Go 1.19
|
|
35
|
+
- Python 3.7+
|
|
36
|
+
- IPFS Kubo dependencies
|
|
37
|
+
|
|
38
|
+
## Basic Usage
|
|
39
|
+
|
|
40
|
+
### Working with Files
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from ipfs_node import IpfsNode
|
|
44
|
+
|
|
45
|
+
# Create a new node with a temporary repository
|
|
46
|
+
with IpfsNode.ephemeral() as node:
|
|
47
|
+
# Add a file to IPFS
|
|
48
|
+
cid = node.files.publish("README.md")
|
|
49
|
+
print(f"Added file with CID: {cid}")
|
|
50
|
+
|
|
51
|
+
# Retrieve a file from IPFS
|
|
52
|
+
node.files.download(cid, "download.md")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Using PubSub
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from ipfs_node import IpfsNode
|
|
59
|
+
|
|
60
|
+
with IpfsNode.ephemeral() as node:
|
|
61
|
+
# Subscribe to a topic
|
|
62
|
+
with node.pubsub.subscribe("my-topic") as subscription:
|
|
63
|
+
# Publish a message
|
|
64
|
+
node.pubsub.publish("my-topic", "Hello, IPFS world!")
|
|
65
|
+
|
|
66
|
+
# Receive messages
|
|
67
|
+
message = subscription.next_message(timeout=2.0)
|
|
68
|
+
if message:
|
|
69
|
+
print(f"Received: {message.data.decode('utf-8')}")
|
|
70
|
+
|
|
71
|
+
# Or use a callback
|
|
72
|
+
def on_message(msg):
|
|
73
|
+
print(f"Received via callback: {msg.data.decode('utf-8')}")
|
|
74
|
+
|
|
75
|
+
subscription.subscribe(on_message)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Using TCP Tunnels (LibP2P Stream Mounting)
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from ipfs_node import IpfsNode
|
|
82
|
+
|
|
83
|
+
# Create an IPFS node
|
|
84
|
+
with IpfsNode.ephemeral() as node:
|
|
85
|
+
|
|
86
|
+
# Example 1: Listen for connections on a protocol and forward them to a local service
|
|
87
|
+
node.tunnels.open_listener("my-service", 8888)
|
|
88
|
+
|
|
89
|
+
# Example 2: Forward local connections to a remote peer
|
|
90
|
+
node.tunnels.open_sender("their-service", 8889, node.peer_id)
|
|
91
|
+
|
|
92
|
+
# List active listeners and streams
|
|
93
|
+
tunnels = node.tunnels.get_tunnels()
|
|
94
|
+
print(tunnels.listeners)
|
|
95
|
+
print(tunnels.senders)
|
|
96
|
+
|
|
97
|
+
# Close specific connections when done
|
|
98
|
+
node.tunnels.close_listener("my-service")
|
|
99
|
+
node.tunnels.close_sender("their-service")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Documentation
|
|
103
|
+
|
|
104
|
+
- [Installation Instructions](INSTALL.md)
|
|
105
|
+
- [PubSub Documentation](docs/pubsub.md)
|
|
106
|
+
- [P2P Stream Mounting](docs/p2p.md)
|
|
107
|
+
|
|
108
|
+
## Examples
|
|
109
|
+
|
|
110
|
+
- [Basic Usage](examples/basic_usage.py)
|
|
111
|
+
- [File Sharing](examples/file_sharing.py)
|
|
112
|
+
- [PubSub Example](examples/pubsub_example.py)
|
|
113
|
+
- [Chat Application](examples/chat_app.py)
|
|
114
|
+
- [P2P Stream Mounting](examples/p2p_example.py)
|
|
115
|
+
- [P2P Socket Communication](examples/p2p_socket_example.py)
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT License
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Basic usage example for the Kubo Python library.
|
|
4
|
+
|
|
5
|
+
This example demonstrates how to:
|
|
6
|
+
1. Create an ephemeral IPFS node
|
|
7
|
+
2. Add a file to IPFS
|
|
8
|
+
3. Add a string to IPFS
|
|
9
|
+
4. Retrieve data from IPFS
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
import tempfile
|
|
15
|
+
|
|
16
|
+
# Add the parent directory to the Python path
|
|
17
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
18
|
+
|
|
19
|
+
from ipfs_node import IpfsNode
|
|
20
|
+
|
|
21
|
+
def main():
|
|
22
|
+
# Create a temporary file for the example
|
|
23
|
+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
|
|
24
|
+
temp_file.write("Hello, IPFS!")
|
|
25
|
+
temp_file_path = temp_file.name
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
# Create an ephemeral IPFS node
|
|
29
|
+
print("Creating ephemeral IPFS node...")
|
|
30
|
+
with IpfsNode.ephemeral() as node:
|
|
31
|
+
print("Created IPFS node with ID:", node.peer_id)
|
|
32
|
+
print("Created IPFS node with Multiaddress:", node.get_addrs())
|
|
33
|
+
|
|
34
|
+
# Add a file to IPFS
|
|
35
|
+
print(f"Adding file: {temp_file_path}")
|
|
36
|
+
file_cid = node.files.publish(temp_file_path)
|
|
37
|
+
print(f"File added with CID: {file_cid}")
|
|
38
|
+
|
|
39
|
+
# Add a string to IPFS
|
|
40
|
+
content = "Hello, IPFS from Python!"
|
|
41
|
+
|
|
42
|
+
# Retrieve the file content
|
|
43
|
+
retrieved_content = node.files.read(file_cid)
|
|
44
|
+
print(f"Retrieved content from file: {retrieved_content}")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# Try to connect to a public IPFS node
|
|
48
|
+
try:
|
|
49
|
+
print("Connecting to public IPFS node...")
|
|
50
|
+
# ipfs.io multiaddress
|
|
51
|
+
peer_addr = "/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN"
|
|
52
|
+
success = node.peers.connect(peer_addr)
|
|
53
|
+
print(f"Connection {'successful' if success else 'failed'}")
|
|
54
|
+
except Exception as e:
|
|
55
|
+
print(f"Error connecting to peer: {e}")
|
|
56
|
+
|
|
57
|
+
print("IPFS node operations completed successfully!")
|
|
58
|
+
|
|
59
|
+
finally:
|
|
60
|
+
# Clean up the temporary file
|
|
61
|
+
os.unlink(temp_file_path)
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
main()
|