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.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.0.tar.gz (46.9 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.0-cp314-abi3-win_arm64.whl (5.6 MB view details)

Uploaded CPython 3.14+Windows ARM64

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

Uploaded CPython 3.14+Windows x86-64

pyroh-0.4.0-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.0-cp314-abi3-musllinux_1_2_aarch64.whl (8.6 MB view details)

Uploaded CPython 3.14+musllinux: musl 1.2+ ARM64

pyroh-0.4.0-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.0-cp314-abi3-manylinux_2_28_aarch64.whl (8.4 MB view details)

Uploaded CPython 3.14+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.14+macOS 11.0+ ARM64

pyroh-0.4.0-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.0.tar.gz.

File metadata

  • Download URL: pyroh-0.4.0.tar.gz
  • Upload date:
  • Size: 46.9 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.0.tar.gz
Algorithm Hash digest
SHA256 189d2a218d231efb3559361a3d9be9a6b615e37bdbed3f4b97381fae1e9788eb
MD5 0806e6cd5766af9073ea8044274acd1c
BLAKE2b-256 5846355f9d07aa4870c4730d49dadcaa6ff270950bdda3ed6f46e2ac09ee4763

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.0-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.0-cp314-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 c9d39ac030ea0db78112af86c09527d291b5df7f74b3b7b92d75c4b1f78778f3
MD5 99e770253d6c52fb0506788fff3380bd
BLAKE2b-256 42a6723b3e7a4120f4e9eb33a0aaad3182e16d0950f9e8ccec280f768a71d7ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.0-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.0-cp314-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 75ed619512ff46e63f48a9112292602c4c63432a643170d0f5ab7ee9b8138e0d
MD5 9df35b59d0daaac885d77559b5c3e608
BLAKE2b-256 0f96360b63ea5cf24219d3c40830d966161aafaba3e54106c6e5af01cb6cb835

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.0-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.0-cp314-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 eac445662b6aa8b20b83d7aa0a502702177e25638d86b83769ec068398528862
MD5 bb6ed136ca4f61683a839ce2dba1b699
BLAKE2b-256 e7a9fb185ec63f589e416e973c1060b519c65cc1bb4db5ac204e5a6780c2935a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.0-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.0-cp314-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 253f656ead4bad1c65dba2ad2f2dccf533cd9004d177f65ca5b205d00b9bff96
MD5 9395c23b2b409ace117f1f8ac9077503
BLAKE2b-256 194b83598e5ea2712039746ff8c34b841cfef61c123da8252b07a56a3be9e1e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.0-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.0-cp314-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dcc23b2543c12a18bc4b70eb30d4bccf76368c165b7013388b66c8d31bbb0d12
MD5 438c5898ca06c97932e3346e47767392
BLAKE2b-256 8c9a4877054033300738d4f96d8c6289dff9a6cc01ebdd91325e190803055706

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.0-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.0-cp314-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dda364fb796a8d2282245942a98288e8153f1fa1dbad3d33c5d7cbd2949c2073
MD5 55a6d051f32385e7b02d6e871fd18070
BLAKE2b-256 9d05e4ce93071a1121d01120fad85310912ab6249da2a02ab461287c03e6776c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.0-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.0-cp314-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bbbbe635eef4dc5af3d3e3f047d337b6e73d49d303d98e9b4c2fd8101bc5147d
MD5 b337634264a9d2b2ed6efb957356a97b
BLAKE2b-256 b4b38388292b5cf5fa273e2736a629999624719feb06ea7b931c7baff7cc3dad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.0-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.0-cp314-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 376b9d0ed9f7d6bc6e559d290456621e4f07285dbcc2dc89a701e4baeed3829c
MD5 8852c39952edcf5caac45d7a771bff0c
BLAKE2b-256 509416fd3d0e918a5b7f362f8073eb2fc7e5faab6c94f7b68548c6751f0710b4

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