Skip to main content

A friendly, asyncio-like Python wrapper for Iroh

Project description

pyroh

A friendly, asyncio-like Python wrapper for iroh.

Pyroh wraps iroh's rust bindings via pyo3 and integrates with asyncio using the standard StreamReader/StreamWriter interface.


Requirements

  • Python ≥ 3.14

Installation

pip install pyroh

To build from source:

maturin develop

Quickstart

import asyncio
import pyroh

ALPN = b"myapp/1"

async def handle_connection(conn: pyroh.Connection) -> None:
    reader, writer = await conn.accept_bi()
    data = await reader.read(1024)
    print(f"server got: {data!r}")
    writer.write(b"hello back")
    writer.close()
    await writer.wait_closed()

async def main():
    # Bind a server endpoint. A fresh keypair is generated automatically.
    server = await pyroh.Endpoint.bind(alpns=[ALPN])
    async with server:
        srv = server.start_server(handle_connection)

        # Bind a client endpoint and connect by full address or ticket.
        # By default, this hangs until the endpoint is online.
        # You can disable this behavior by doing
        # `endpoint = await pyroh.Endpoint.bind(wait_online=False)`
        # and then awaiting `endpoint.wait_online()` later
        client = await pyroh.Endpoint.bind(alpns=[ALPN])
        async with client:
            conn = await client.connect(server.ticket, alpn=ALPN)
            async with conn:
                reader, writer = await conn.open_bi()
                writer.write(b"hello")
                writer.close()
                response = await reader.read(1024)
                print(f"client got: {response!r}")

        srv.close()

asyncio.run(main())

You can view more examples in the examples folder


API

pyroh.Endpoint

The main entry point. Represents a local QUIC endpoint.

endpoint = await pyroh.Endpoint.bind(
    alpns=[b"myapp/1"],  # ALPNs to accept; default is [b"pyroh/1"]
    key=None,            # 32-byte secret key, or None to generate a fresh one
    wait_online=True,    # if False, return immediately and call wait_online() manually
)

Properties

Property Type Description
id str Node ID (public key) as a hex string. Requires discovery to connect directly.
addr EndpointAddr Full endpoint address (node ID + relay/direct addresses). Use this without discovery.
ticket str Serialized endpoint ticket for sharing full address info.
secret_key bytes The 32-byte secret key for this endpoint's identity. Store it to reuse the same node ID across restarts.

Methods

Method Description
await endpoint.connect(addr, *, alpn=b"pyroh/1") Connect to a remote peer by node ID, EndpointAddr, or endpoint ticket string. Returns a Connection.
endpoint.start_server(handler) Start accepting connections, calling handler(conn) for each one. Returns a Server.
await endpoint.wait_online() Wait until the endpoint has contacted a relay and is reachable. Only needed when bind(wait_online=False) was used.
endpoint.set_alpns(alpns) Update the set of accepted ALPNs at runtime (e.g. for protocol upgrades).
await endpoint.close() (or async with endpoint) Shut down the endpoint.

pyroh.EndpointAddr

Represents full dial information (node ID + optional relay/direct addresses).

Class methods

Method Description
EndpointAddr.from_json(raw) Parse full address info from JSON (e.g. Endpoint.addr_json).
EndpointAddr.from_id(node_id) Create an ID-only address (discovery required).
EndpointAddr.from_ticket(ticket) Parse a serialized endpoint ticket into full address info.

pyroh.Connection

A QUIC connection to a remote peer. Connections multiplex streams — open as many as you need without the overhead of new connections.

Methods

Method Description
await conn.open_bi() Open a bidirectional stream. Returns (StreamReader, StreamWriter).
await conn.accept_bi() Accept a bidirectional stream opened by the remote. Returns (StreamReader, StreamWriter).
await conn.open_uni() Open a send-only stream. Returns StreamWriter.
await conn.accept_uni() Accept a receive-only stream opened by the remote. Returns StreamReader.
await conn.abort(error_code=0, reason="") Forcefully close the connection with an application error code.
conn.close() Close all open streams on this connection.
async with conn Context manager — calls close() and wait_closed() on exit.

pyroh.Server

Returned by endpoint.start_server(handler). Accepts connections in a background task.

Method Description
await server.serve_forever() Block until the server is closed (e.g. from a signal handler).
server.close() Stop accepting new connections. Does not close the underlying endpoint.
server.id Node ID of the underlying endpoint (same as endpoint.id).

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

pyroh-0.4.1.tar.gz (47.3 kB view details)

Uploaded Source

Built Distributions

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

pyroh-0.4.1-cp314-abi3-win_arm64.whl (5.6 MB view details)

Uploaded CPython 3.14+Windows ARM64

pyroh-0.4.1-cp314-abi3-win_amd64.whl (6.0 MB view details)

Uploaded CPython 3.14+Windows x86-64

pyroh-0.4.1-cp314-abi3-musllinux_1_2_x86_64.whl (8.7 MB view details)

Uploaded CPython 3.14+musllinux: musl 1.2+ x86-64

pyroh-0.4.1-cp314-abi3-musllinux_1_2_aarch64.whl (8.6 MB view details)

Uploaded CPython 3.14+musllinux: musl 1.2+ ARM64

pyroh-0.4.1-cp314-abi3-manylinux_2_28_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.14+manylinux: glibc 2.28+ x86-64

pyroh-0.4.1-cp314-abi3-manylinux_2_28_aarch64.whl (8.4 MB view details)

Uploaded CPython 3.14+manylinux: glibc 2.28+ ARM64

pyroh-0.4.1-cp314-abi3-macosx_11_0_arm64.whl (6.6 MB view details)

Uploaded CPython 3.14+macOS 11.0+ ARM64

pyroh-0.4.1-cp314-abi3-macosx_10_12_x86_64.whl (6.8 MB view details)

Uploaded CPython 3.14+macOS 10.12+ x86-64

File details

Details for the file pyroh-0.4.1.tar.gz.

File metadata

  • Download URL: pyroh-0.4.1.tar.gz
  • Upload date:
  • Size: 47.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyroh-0.4.1.tar.gz
Algorithm Hash digest
SHA256 15e8d5a0f29128bc477a94d06e61a8eb4371322c5582721e05eb14116f4b4f7c
MD5 6707a26b9e74b53d518bd8e37ade4511
BLAKE2b-256 168458e927fb3b5b39c22d04b4bb61fd26a74ae9520579ba454c2959d5bf462e

See more details on using hashes here.

File details

Details for the file pyroh-0.4.1-cp314-abi3-win_arm64.whl.

File metadata

  • Download URL: pyroh-0.4.1-cp314-abi3-win_arm64.whl
  • Upload date:
  • Size: 5.6 MB
  • Tags: CPython 3.14+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyroh-0.4.1-cp314-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 b08978d84d9f0734f5d7dfa4fe3aefeb97aa3fa297a4fbdf4d543c2d942206d2
MD5 4bc0648b84cc8a51934674fa5c8a3c68
BLAKE2b-256 57aea1424fcf687a1136d1bec610e3bbd244dc816ca6b2dc23ea182ecf6c0c02

See more details on using hashes here.

File details

Details for the file pyroh-0.4.1-cp314-abi3-win_amd64.whl.

File metadata

  • Download URL: pyroh-0.4.1-cp314-abi3-win_amd64.whl
  • Upload date:
  • Size: 6.0 MB
  • Tags: CPython 3.14+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyroh-0.4.1-cp314-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6a1fd27ec698f4ace6011b9cfe4df6c881cb4236e81c7afc4986b102ae76bbcb
MD5 dab40a5505381aeb3313073e07c48aa3
BLAKE2b-256 88901050b1dbb877b78da2d64cb98f7a9c3b276998d0056f14f83b598cb8f1e4

See more details on using hashes here.

File details

Details for the file pyroh-0.4.1-cp314-abi3-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: pyroh-0.4.1-cp314-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 8.7 MB
  • Tags: CPython 3.14+, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyroh-0.4.1-cp314-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6c9810b9ecced0f48ad3a5676dfc3818e10b53b4800ab2c76f1e72436d82b07b
MD5 b13b6d2bf6774aefb49ea41fee05fb4b
BLAKE2b-256 b233686fd5992a79fee7436e7b69d855b401b90a4178657baab991ad14956047

See more details on using hashes here.

File details

Details for the file pyroh-0.4.1-cp314-abi3-musllinux_1_2_aarch64.whl.

File metadata

  • Download URL: pyroh-0.4.1-cp314-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: CPython 3.14+, musllinux: musl 1.2+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyroh-0.4.1-cp314-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 315680e46e2be5809ec42545ca9f99f8b3eae0c32086e33668fd49427c46a9b6
MD5 dc17b0abcb2acd39d784907b346a8245
BLAKE2b-256 320bacf770b10b022fc735d3754232005c81796db9ca8799b8a4c898015a47a2

See more details on using hashes here.

File details

Details for the file pyroh-0.4.1-cp314-abi3-manylinux_2_28_x86_64.whl.

File metadata

  • Download URL: pyroh-0.4.1-cp314-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: CPython 3.14+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyroh-0.4.1-cp314-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0ad1be58c32811e8c375b50c9eb8ecdd84ce50c0846d3bc2c18d0998fdbdf953
MD5 f65e3b24f89aa74b67db9f4da2c2edbe
BLAKE2b-256 8589d8b15017db8eb45ddb53ae52c08ec9046a862c80b5a35d23c36ea74c1c94

See more details on using hashes here.

File details

Details for the file pyroh-0.4.1-cp314-abi3-manylinux_2_28_aarch64.whl.

File metadata

  • Download URL: pyroh-0.4.1-cp314-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 8.4 MB
  • Tags: CPython 3.14+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyroh-0.4.1-cp314-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3296136bd1a98c7e6883d2e2ed0be8509a46e2963267c57a2cb57d47418591a6
MD5 7d212f0aa15b07c3c0efade2b5439999
BLAKE2b-256 a01b4c7dd98c52a47d7833f90b098810d4e707cbc96df935d17deec6fedd1fe3

See more details on using hashes here.

File details

Details for the file pyroh-0.4.1-cp314-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pyroh-0.4.1-cp314-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 6.6 MB
  • Tags: CPython 3.14+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyroh-0.4.1-cp314-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1174680129aa5c352b44afb9b27a91fcf9243f2be62f632d97ffda5a95a6ee95
MD5 a7742f31b4d967fee101ef026b326e2a
BLAKE2b-256 006df8fb4c1529f87d4396aac097155d4faf206a7d7e94c22ac58b3eeced4447

See more details on using hashes here.

File details

Details for the file pyroh-0.4.1-cp314-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: pyroh-0.4.1-cp314-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 6.8 MB
  • Tags: CPython 3.14+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyroh-0.4.1-cp314-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a9a7809c6d9e8ddf9fe37f5a134219fb20de6b8a45202c9a495c777fdcb6be74
MD5 e04eb73db32eb9dc9a0c2b34aa9cbcba
BLAKE2b-256 86fe6dd78547c2808124b4edd1c3ccee23a0261b173e7b18b285748519a6418b

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