Skip to main content

Run an IPFS node inside of python using kubo as a library.

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 ipfs_node

Dev Requirements

  • Go 1.19+
  • Python 3.7+
  • IPFS Kubo dependencies

Basic Usage

Working with Files

from ipfs_node 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 ipfs_node 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 ipfs_node 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.tunnels.open_listener("my-service", "127.0.0.1:8080")

    # Example 2: Forward local connections to a remote peer
    node.tunnels.open_sender("their-service", "127.0.0.1:9090", "QmPeerID...")

    # List active listeners and streams
    listeners, streams = node.tunnels.list_listeners()

    # Close specific connections when done
    node.tunnels.close_listener("my-service")
    node.tunnels.close_sender("their-service")

Documentation

Examples

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 Distribution

kubo_python-0.1.5.tar.gz (32.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kubo_python-0.1.5-py3-none-any.whl (32.4 MB view details)

Uploaded Python 3

File details

Details for the file kubo_python-0.1.5.tar.gz.

File metadata

  • Download URL: kubo_python-0.1.5.tar.gz
  • Upload date:
  • Size: 32.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for kubo_python-0.1.5.tar.gz
Algorithm Hash digest
SHA256 c1e3c527e2a2301e795d48c440612f031770ac3376c8a7adbc398b271e9bc5d6
MD5 ad2fa91652184f84221b796c5f797220
BLAKE2b-256 4e31fadc3c20cd99d3ae0695aa471268cb5c4b61cec74bbbe04c28c2c0088f67

See more details on using hashes here.

File details

Details for the file kubo_python-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: kubo_python-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 32.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for kubo_python-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dd9a258bcec3d439ccd74a46fe77c6448cc432aabd3b380e35a3ad4e5341b0bd
MD5 4e77b0b34318cf90bdef138774e5a710
BLAKE2b-256 8920ee74a14776e9d7cd81de29aa6cf5e50d3aff348c8ff5ca026b04ee8ba143

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page