Skip to main content

No project description provided

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 node ID.
        # 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.id, 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. Pass this to remote peers so they can connect.
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 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.3.0.tar.gz (46.5 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.3.0-cp314-cp314t-musllinux_1_2_x86_64.whl (9.2 MB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

pyroh-0.3.0-cp314-cp314t-musllinux_1_2_aarch64.whl (9.1 MB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ ARM64

pyroh-0.3.0-cp314-abi3-win_arm64.whl (7.0 MB view details)

Uploaded CPython 3.14+Windows ARM64

pyroh-0.3.0-cp314-abi3-win_amd64.whl (7.1 MB view details)

Uploaded CPython 3.14+Windows x86-64

pyroh-0.3.0-cp314-abi3-musllinux_1_2_x86_64.whl (9.2 MB view details)

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

pyroh-0.3.0-cp314-abi3-musllinux_1_2_aarch64.whl (9.1 MB view details)

Uploaded CPython 3.14+musllinux: musl 1.2+ ARM64

pyroh-0.3.0-cp314-abi3-manylinux_2_28_x86_64.whl (8.8 MB view details)

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

pyroh-0.3.0-cp314-abi3-manylinux_2_28_aarch64.whl (8.9 MB view details)

Uploaded CPython 3.14+manylinux: glibc 2.28+ ARM64

pyroh-0.3.0-cp314-abi3-macosx_11_0_arm64.whl (7.5 MB view details)

Uploaded CPython 3.14+macOS 11.0+ ARM64

pyroh-0.3.0-cp314-abi3-macosx_10_12_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.14+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: pyroh-0.3.0.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0.tar.gz
Algorithm Hash digest
SHA256 9f081c1d8fa56f478b890deac551fa1bfa26a0a1974447534f9e542e89bc450a
MD5 12c8800ed6a92079ff96ab8c75870b40
BLAKE2b-256 0bf2e89039314ca0b7300f405598ad83e32eb74f40e50b643a4e57f8e65a4e11

See more details on using hashes here.

File details

Details for the file pyroh-0.3.0-cp314-cp314t-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: pyroh-0.3.0-cp314-cp314t-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 9.2 MB
  • Tags: CPython 3.14t, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 16016f34bed13b12f9b05287b12d6ddea5a2a842c5e5e1091fc29aed660f5b97
MD5 33dc45667d072b9381f0f1b52ba5b231
BLAKE2b-256 55cac6a128de55b2c275304b143c06c8b721c2d94db4d803f9d4fafee37a3aa3

See more details on using hashes here.

File details

Details for the file pyroh-0.3.0-cp314-cp314t-musllinux_1_2_aarch64.whl.

File metadata

  • Download URL: pyroh-0.3.0-cp314-cp314t-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 9.1 MB
  • Tags: CPython 3.14t, musllinux: musl 1.2+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0-cp314-cp314t-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3881e21ba35715a639969e5480e46532a4a5b60c0f4a089131a25da174c741b9
MD5 08d692da7d814aecb9656eaec1580896
BLAKE2b-256 eafb3574aec83b73a680db670e28c32bb1a53dbb55b2020d0d953aad53c70ce8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.3.0-cp314-abi3-win_arm64.whl
  • Upload date:
  • Size: 7.0 MB
  • Tags: CPython 3.14+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0-cp314-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 0a31c57da695bcd0d3a95d532292413363829cf9cd05dcef80527eb917b15906
MD5 f788a8a84a3a6405516694937feab862
BLAKE2b-256 9883217a1cbc6db03f7989d719c9d4a015a3734b0ea1071243c344a36390761b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.3.0-cp314-abi3-win_amd64.whl
  • Upload date:
  • Size: 7.1 MB
  • Tags: CPython 3.14+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0-cp314-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 31828959c8bafc9860a71b30294c47e2ccc7ddc670d59ec04d1e58c18d3781e2
MD5 4013b71556bf85cb7d8284f7cc5d0e05
BLAKE2b-256 1adede0969748dbb87e749b649b7113e2a128f13d6303702cc4dbd568278cf67

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.3.0-cp314-abi3-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 9.2 MB
  • Tags: CPython 3.14+, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0-cp314-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 def67da862209650838987595991088b884b92ffd988a581590e4dcdbfba8102
MD5 be772cbe584ded071c4d3c4afbd41919
BLAKE2b-256 ec657a1f939481f4a75df2fe51312f655eb6fcb0175176c7743392a1f9258d52

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.3.0-cp314-abi3-musllinux_1_2_aarch64.whl
  • Upload date:
  • Size: 9.1 MB
  • Tags: CPython 3.14+, musllinux: musl 1.2+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0-cp314-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 e1d3c6362c1c49bc7ea25c57725724f840445bfccec5b9d29d3b1696c8abf9f3
MD5 cb912cec56b32c1652a83f0b77421f5b
BLAKE2b-256 f301971299cb34cb5408323d8746712f14ebdb6aa44a834e981dd68132828f9b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.3.0-cp314-abi3-manylinux_2_28_x86_64.whl
  • Upload date:
  • Size: 8.8 MB
  • Tags: CPython 3.14+, manylinux: glibc 2.28+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0-cp314-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 93519116642362ce8d0edd091a55135545f03cc2f31cd91b430cc03d90c1b398
MD5 e8439c08d0e7d12f9eb81c2524a22d15
BLAKE2b-256 aae4295ee84b452bad66f4cfb4fe19ccf8714535617e230b28e07a61a3dc5d60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.3.0-cp314-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 8.9 MB
  • Tags: CPython 3.14+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0-cp314-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9eb3f42211daf76b674571f0634e6125258dcf86d192c4380b04c438321c0ce4
MD5 7f21a98201accf58c59db5487c1c7c38
BLAKE2b-256 45ac8949d32cfc0e21680bfef8ce5f41b551308bbd7b47db70e388854fdbbf0b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.3.0-cp314-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 7.5 MB
  • Tags: CPython 3.14+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0-cp314-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5bdaf92ed1f3f4df0789c7fd852a5f19d7002ab39c64eeaf24e4bf19dde7aff5
MD5 40bcb0c787b6b1331d7e92d5c59f2e14
BLAKE2b-256 4bbb837f2ad22d26ba2bac8a6b5d8fa595a2c707bfaf0f9334fdd0b1e5bf18ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.3.0-cp314-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 7.7 MB
  • Tags: CPython 3.14+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","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.3.0-cp314-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1940c00ce344bc5515abe255d0d6933807d3db995193be771f71b855f73c30bb
MD5 b91a3a3fc6026301ffe82a0eede67dc0
BLAKE2b-256 d3b4151673edf74f33ec53cbeb5ff90b65d38992156ec60cba921a099d8c871e

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