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.2.tar.gz (48.1 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.2-cp314-abi3-win_arm64.whl (5.7 MB view details)

Uploaded CPython 3.14+Windows ARM64

pyroh-0.4.2-cp314-abi3-win_amd64.whl (6.1 MB view details)

Uploaded CPython 3.14+Windows x86-64

pyroh-0.4.2-cp314-abi3-musllinux_1_2_x86_64.whl (8.5 MB view details)

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

pyroh-0.4.2-cp314-abi3-musllinux_1_2_aarch64.whl (8.4 MB view details)

Uploaded CPython 3.14+musllinux: musl 1.2+ ARM64

pyroh-0.4.2-cp314-abi3-manylinux_2_28_x86_64.whl (8.1 MB view details)

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

pyroh-0.4.2-cp314-abi3-manylinux_2_28_aarch64.whl (8.2 MB view details)

Uploaded CPython 3.14+manylinux: glibc 2.28+ ARM64

pyroh-0.4.2-cp314-abi3-macosx_11_0_arm64.whl (6.7 MB view details)

Uploaded CPython 3.14+macOS 11.0+ ARM64

pyroh-0.4.2-cp314-abi3-macosx_10_12_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.14+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: pyroh-0.4.2.tar.gz
  • Upload date:
  • Size: 48.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.2.tar.gz
Algorithm Hash digest
SHA256 d8f6e567cc24d9a924b31688032b6e59376379c1d0e094fa83175062ede29162
MD5 f09977c0b97f1d854da50c836a4d8e86
BLAKE2b-256 1661dfc0214a9dc428303cd61cda112053f403b7e646583c22927a5df8b4bf1f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.2-cp314-abi3-win_arm64.whl
  • Upload date:
  • Size: 5.7 MB
  • Tags: CPython 3.14+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.2-cp314-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1cef294fa3cd8ca1c9336b1be5870c258930bc184a0b3727b5d9bee8b04def12
MD5 a673e7bb86af27e4739955f7af7428d8
BLAKE2b-256 f5ad556e3068f3b75d98d6cee80fe0fb68c7be6dd79212c3fcbee23423c8cd1b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.2-cp314-abi3-win_amd64.whl
  • Upload date:
  • Size: 6.1 MB
  • Tags: CPython 3.14+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.2-cp314-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ba19c19be4399c2702ab8ffb09d40e72aa0b4ec168b1ae6995cb0209c223ad79
MD5 84499f736fc49e1d290126975d00357a
BLAKE2b-256 6b197fa8419314584ac6b9adac091eb0596bddca39b778823fd961b5cb74214e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.2-cp314-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 8.5 MB
  • Tags: CPython 3.14+, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.2-cp314-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1f9a226bf76411bd4fe7eff97365a9e798ad7025ec664861da4618cca802b6ba
MD5 24564729732d34d641f05d96d37bb769
BLAKE2b-256 5b3fb54e143a769edd0fc1ea2edd02c64f8e37bbed5bdc86f994ceb586a017a7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.2-cp314-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 8.4 MB
  • Tags: CPython 3.14+, musllinux: musl 1.2+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.2-cp314-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4d398aceb1f6208320753d3c77ac8deb13638224a48c9596d3a8f031abaf426e
MD5 ea9f2740accafa5a53392d2e2d70e0ab
BLAKE2b-256 6a5976d5c86fa636d1b1b402e60a809141785cb2e70a3f388a04d817dc78f43e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.2-cp314-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 8.1 MB
  • Tags: CPython 3.14+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.2-cp314-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3d8876dd9d558c691ff4fd135980a6208b1b3ddbcd33d1d9f13c762151df1f7e
MD5 afd67e4ad301234a777e572fcdb716dc
BLAKE2b-256 6ae210bd1195f027765f226bd960b1bbee8bad6b4335ae814aa1f4ff4b1dee03

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.2-cp314-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 8.2 MB
  • Tags: CPython 3.14+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.2-cp314-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d9d7aa83ba63c614a2ed467225ac4f05bb534331d52856e3dd18e1d9a223e151
MD5 080f29e78915093ec68b07bb57f86719
BLAKE2b-256 3e16248ea8323e8448ae8c7730c599c1ad4b73f41de81b6fc412272bcec6cf14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.2-cp314-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 6.7 MB
  • Tags: CPython 3.14+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.2-cp314-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 36a5acbb3a3c6dbe886cd69e47e7fcafce0c2476e759bce9a27a5f1e39d7950d
MD5 41f3d5627f377abb70294499d0e41b02
BLAKE2b-256 f5b296bb55a06b891f8c0b31e3fcca07e50c1a7004a4d497729d0faee93db7b1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.4.2-cp314-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 6.9 MB
  • Tags: CPython 3.14+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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.2-cp314-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3481532780b4fd3b9cf6de5dc78758a13aa7350ed053568c3502f53ff11ab319
MD5 a1c7968fffd26865d30a73955c3221ff
BLAKE2b-256 5407037f6a2014297405aef1d68657918c969a7c5cfb2340d6b96d990c46c097

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