Skip to main content

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

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.3.tar.gz (64.4 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.3-py3-none-any.whl (64.6 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kubo_python-0.1.3.tar.gz
  • Upload date:
  • Size: 64.4 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.3.tar.gz
Algorithm Hash digest
SHA256 7715c12d406b166330a7411b1b14340e8abda7ad4195fe270969a097457f63a2
MD5 51aa6132b8176caf3b398c1de6d28a2d
BLAKE2b-256 ab201da04633c1862f34fe670cf18d9483f9590937c8d8f886d927a64d4eafe0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kubo_python-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 64.6 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 82564ecc8c2d8744153017b4dd38712b07f7939b081a9a1249ffef03804e31ee
MD5 6398fac7fd6afc9301f5a3283ec97c31
BLAKE2b-256 a46bf442d8083cfd35d5296af7a231c0d8482f9cbc639cf12870504466439f75

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