Python bindings for Kubo (Go-IPFS)
Project description
Kubo Python Library
A Python wrapper for the Kubo (Go-IPFS) library.
Overview
This library provides Python bindings for Kubo, the Go implementation of IPFS, allowing you to:
- Spawn an in-process IPFS node
- Add and retrieve files/directories from IPFS
- Connect to the IPFS network
- Manage IPFS repositories
- Publish and subscribe to IPFS PubSub topics
- Mount and connect to remote TCP services via libp2p
Project Status
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. Much of the code is LLM-generated, and code coverage is poor.
The API structure of this library WILL CHANGE in the near future!
So far this library has been tested on Linux x86 64-bit and Android ARM 64-bit (in Termux & in Kivy). Assuming that it proves to be a reliable way of working in python, this library will be developed to maturity and maintained.
Installation
pip install kubo_python
Dev Requirements
- Go 1.19+
- Python 3.7+
- IPFS Kubo dependencies
Basic Usage
Working with Files
from kubo_python import IpfsNode
# Create a new node with a temporary repository
with IpfsNode.ephemeral() as node:
# Add a file to IPFS
cid = node.files.add_file("README.md")
print(f"Added file with CID: {cid}")
# Retrieve a file from IPFS
node.files.download(cid, "/path/to/destination.txt")
Using PubSub
from kubo_python import IpfsNode
with IpfsNode.ephemeral() as node:
# Subscribe to a topic
with node.pubsub.subscribe("my-topic") as subscription:
# Publish a message
node.pubsub.publish("my-topic", "Hello, IPFS world!")
# Receive messages
message = subscription.next_message(timeout=2.0)
if message:
print(f"Received: {message.data.decode('utf-8')}")
# Or use a callback
def on_message(msg):
print(f"Received via callback: {msg.data.decode('utf-8')}")
subscription.subscribe(on_message)
Using P2P Stream Mounting
from kubo_python import IpfsNode
# Create an IPFS node
with IpfsNode.ephemeral() as node:
# Example 1: Listen for connections on a protocol and forward them to a local service
node.tcp.open_listener("my-service", "127.0.0.1:8080")
# Example 2: Forward local connections to a remote peer
node.tcp.open_sender("their-service", "127.0.0.1:9090", "QmPeerID...")
# List active listeners and streams
listeners, streams = node.tcp.list_listeners()
# Close specific connections when done
node.tcp.close_listener("my-service")
node.tcp.close_sender("their-service")
Documentation
Examples
- Basic Usage
- File Sharing
- PubSub Example
- Chat Application
- P2P Stream Mounting
- P2P Socket Communication
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kubo_python-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kubo_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 64.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5341b741b899f31d6b6b4a96b5851dff79d644e0fb13a069e3f646b4ae39f4c7
|
|
| MD5 |
19513f6f97cfee41d4531a6bae576aee
|
|
| BLAKE2b-256 |
639c9e64a74c83193ad246622d24f365b7a59a0291fcf09d23ccf55af3dab978
|