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 EXPERIMENTAL

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 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.

Compatibility

  • linux x86-64 (tested on Ubuntu)
  • linux arm-64 (tested on Ubuntu on a raspberry pi 5)

Roadmap

py_ipfs_node, will be incorporated into ipfs_toolkit when py_ipfs_node's API has stabilised.

ipfs_toolkit will become a multimodal IPFS library with a unified API for alternative modes of using IPFS:

  • running an embedded IPFS node
  • interacting with a separate IPFS node via its HTTP RPC

You can check out a prototype version of the combination of these two libraries under the kubo_python branch of the IPFS-Toolkit repo: https://github.com/emendir/IPFS-Toolkit-Python/tree/kubo_python

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.publish("README.md")
    print(f"Added file with CID: {cid}")
    
    # Retrieve a file from IPFS
    node.files.download(cid, "download.md")

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 TCP Tunnels (LibP2P 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", 8888)
    
    # Example 2: Forward local connections to a remote peer
    node.tunnels.open_sender("their-service", 8889, node.peer_id)
    
    # List active listeners and streams
    tunnels = node.tunnels.get_tunnels()
    print(tunnels.listeners)
    print(tunnels.senders)
    
    # Close specific connections when done
    node.tunnels.close_listener("my-service")
    node.tunnels.close_sender("their-service")

Documentation

Examples

Contributing

Get Involved

  • GitHub Discussions: if you want to share ideas
  • GitHub Issues: if you find bugs, other issues, or would like to submit feature requests
  • GitHub Merge Requests: if you think you know what you're doing, you're very welcome!

Donations

To support me in my work on this and other projects, you can make donations with the following currencies:

Donations help me:

  • dedicate more time to developing and maintaining open-source projects
  • cover costs for IT infrastructure
  • finance projects requiring additional hardware & compute

About the Developer

This project is developed by a human one-man team, publishing under the name Emendir.
I build open technologies trying to improve our world; learning, working and sharing under the principle:

Freely I have received, freely I give.

Feel welcome to join in with code contributions, discussions, ideas and more!

Open-Source in the Public Domain

I dedicate this project to the public domain. It is open source and free to use, share, modify, and build upon without restrictions or conditions.

I make no patent or trademark claims over this project.

Formally, you may use this project under either the:

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

ipfs_node-0.1.11.tar.gz (88.7 MB view details)

Uploaded Source

Built Distribution

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

ipfs_node-0.1.11-py3-none-any.whl (89.2 MB view details)

Uploaded Python 3

File details

Details for the file ipfs_node-0.1.11.tar.gz.

File metadata

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

File hashes

Hashes for ipfs_node-0.1.11.tar.gz
Algorithm Hash digest
SHA256 600a420f6d0ed4262c70590fc2611b9fb1d0934d864ea2ab742a31de69bb24fd
MD5 5feb917943178ac3885757a765db46de
BLAKE2b-256 8b6fbb688cbe73b0fbc5c208a48f388be57ec78fbfe6f90c6f6deeb4c3b8b8ca

See more details on using hashes here.

File details

Details for the file ipfs_node-0.1.11-py3-none-any.whl.

File metadata

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

File hashes

Hashes for ipfs_node-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 cc1d6fb7bd52623c405f7a93630c15b2bb5f0d3f59c8f2b6da7e8ed19260207d
MD5 65565725f3b1caf5315c8e30f2b5e2a5
BLAKE2b-256 03d778551d27bc26eb45085b06690263f2029269a0fb40440d318aa7cd3ed451

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