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.4.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.4-py3-none-any.whl (64.6 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kubo_python-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 578d5ae16a19b52b987ee435cda679fb7ac6f2eec826d089c6068f397ceb44c7
MD5 3b7504e670007fc2deb31fe6538341ba
BLAKE2b-256 1a6af350f851c2b5aefc3dcb96fbffe5f7da35ed2357c6ad5ad18bbd4648d15a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kubo_python-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2857b47a4480897d6671934bfeb900b849661216f0f7191baf0063c49c16a9fe
MD5 e96f6c81d0edbee58a745de34b024c8a
BLAKE2b-256 03860ce5b58aa3d800dfcf2580b1990390b892e5909e68c49206d0b817e51832

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