Skip to main content

Python bindings for prime-iroh (P2P Pipeline Parallel Communication Backend)

Project description

Prime Intellect

PRIME-IROH: P2P Pipeline Parallel Communication


This codebase exposes a Python interface for reliable, asynchronous peer-to-peer communication built upon Iroh. The core classes exposed are:

  • Node: A class combining a single-peer sender/ receiver in one class, allowing to send to exactly one and receive from exactly one (potentially different) peer. The class allows for concurrent communication by opening multiple, consistent streams.
  • Work: A class representing the future of an asynchronous operation, that can be awaited using a wait method.

Because we are building on top of Iroh, we get many nice networking features out of the box. Most importantly, the library guarantees reliable P2P connections between nodes, trying to establish directions connections whenever possible, and falling back to NAT-hole punching and relaying when necessary. The API is mirroring the way asynchronous communication is handled in torch.distributed, i.e. exposing isend and irecv that return work objects that can be awaited using a wait method. This allows for a clean integration with the rest of the PyTorch ecosystem.

Installation

Quick Install: Run the following command for a quick install:

curl -sSL https://raw.githubusercontent.com/PrimeIntellect-ai/prime-iroh/refs/heads/master/script/install.sh | bash

Manual Install: First, install uv and cargo to build the project.

curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env

Then, clone the repository

git clone git@github.com:PrimeIntellect-ai/prime-iroh.git && cd prime-iroh

To build the Rust backend run cargo build, to build the Python bindings run uv sync. This will let you install prime-iroh as a Python package within the virtual environment.

Usage

You can find the basic usage examples in the examples directory showing unidirectional and bidirectional communication patterns in Rust.

Run unidirectional communication example:

cargo run --example unidirectional

Run bidirectional communication example:

cargo run --example bidirectional

For Python usage, you would use the node class as follows:

# On the receiver side
from prime_iroh import Node

# Initialize the node
node = Node(num_streams=1)
print(f"Connect to: {node.node_id()}")

# Wait for sender to connect
while not node.can_recv():
    time.sleep(0.1)

# Receive message
msg = node.irecv(tag=0).wait()
# On the sender side
from prime_iroh import Node

# Initialize the node
node = Node(num_streams=1)

# Connect to the receiver
node.connect(peer_id=...)

# Wait for connection to be established
while not node.can_send():
    time.sleep(0.1)

# Send message
node.isend("Hello, world!".encode(), tag=0, latency=None).wait()

Tests

We include unit tests and integration tests for the Rust backend which can be run using cargo test. The integration tests for uni- and bidirectional communication are also ported to Python and can be run using uv run pytest.

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

prime_iroh-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

prime_iroh-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file prime_iroh-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for prime_iroh-0.1.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c63f5cfd1e0282f30b5ed9696ed57e75239ef14b59a739bfa8bfa390cecd6426
MD5 c8c2aa076565145a72fdf59346948106
BLAKE2b-256 d79babf714a3680df33ddf11fa0c9fd90eaf477ea49012086607a1c603654097

See more details on using hashes here.

File details

Details for the file prime_iroh-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for prime_iroh-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f0026a696f9fd07aa92218ada36fc04a92d9db1fa784d12e6550de1f170d501f
MD5 ab6d00ae5ec17f1612a22d5a1898bc96
BLAKE2b-256 5d9556fb88845d92ee55f1b2619e514dac1d4063888e00b965b9451a323e2cd8

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