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.2.2.tar.gz (45.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.2.2-cp314-cp314t-musllinux_1_2_x86_64.whl (9.2 MB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

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

Uploaded CPython 3.14tmusllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.14+Windows ARM64

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

Uploaded CPython 3.14+Windows x86-64

pyroh-0.2.2-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.2.2-cp314-abi3-musllinux_1_2_aarch64.whl (9.1 MB view details)

Uploaded CPython 3.14+musllinux: musl 1.2+ ARM64

pyroh-0.2.2-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.2.2-cp314-abi3-manylinux_2_28_aarch64.whl (8.9 MB view details)

Uploaded CPython 3.14+manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.14+macOS 11.0+ ARM64

pyroh-0.2.2-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.2.2.tar.gz.

File metadata

  • Download URL: pyroh-0.2.2.tar.gz
  • Upload date:
  • Size: 45.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.2.2.tar.gz
Algorithm Hash digest
SHA256 b892f7debe72e8d2edd1b83b6514fbc305e1ad5845b1882016781b9012465af8
MD5 8226dd3520be0ad3632ea06f4a89f2f4
BLAKE2b-256 bbb543362a8787a2037f1aa1614f88f54d065fc8d0ac7fd83b32dc2a8d7dd227

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.2.2-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.2.2-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d462ebe515f46d17375d0f30655304dfa8c1bf688e42949d2b43aa7192708380
MD5 13a13c069c0481dc5cec214956bbd65c
BLAKE2b-256 33da5daabb49adb42b142fbc8645d7f90474e01f4b986a5ccc65b63e1da480f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.2.2-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.2.2-cp314-cp314t-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 0e05521d976ce1ccc700c6a4fc64f1341a8a0da97a5036a2c0ad44c0c286f128
MD5 37fd4c24006bade69e27041921ce4d7c
BLAKE2b-256 ddaa226b2b3790ae100b0213e1576af9f2edc9e8ede3075210b93aabd5f3a520

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.2.2-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.2.2-cp314-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1f9feef9874f19179b0bce6c5fea740f24c7562492a42068311d5f781e07a5cc
MD5 c3f27857493c8aea013dfd38c530af14
BLAKE2b-256 55166c624a4ddedf69266f1e8221e07d9a28445463c51cd0b34ca08deaf79d10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.2.2-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.2.2-cp314-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f5217c75beff9c39194409515ed431184e50b8851c523e9f323b26dde26f2738
MD5 c52e3fedcfde1289bdab3194cbcb0dc2
BLAKE2b-256 400f1d7ce9f38bd14f249156606b6e98c6c6e915e95039086925f525e7b2bf7c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.2.2-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.2.2-cp314-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f02a2f8b362dee81ea1c90721ff9fcaab2f7753c5f7ce5368ad58a1e6bb2a597
MD5 fd70d63d000215f45639e0f81bfc0e46
BLAKE2b-256 0bcc2ebc368891d8fbe4d7d735e4875e85904f74bf54e49d3eb12ba9915bcd16

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.2.2-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.2.2-cp314-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 aa9a2d6835f0c9c0b67c12e29b16fd8efbec95fa55c75021b99a87b6b78b3efb
MD5 cea7bb83119620f8b42fafd37aa1ca12
BLAKE2b-256 fd84397bb7b4a10eac7dcb05d8b24de3b02b6bb981897cd158b241a329a8ac44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.2.2-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.2.2-cp314-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4cac2355d9eb5fb20fe670e7dfaabf8cb063ecd51c634abce1b4aa3c6366747a
MD5 519fcf7e7d0a694ad596fe4223a9fe2f
BLAKE2b-256 e26037dcf98d4cb5560a13d7f5c2fe6ae7ded8c08f2b9b3e3d1b99f8e2db02c4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.2.2-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.2.2-cp314-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9d49f17f09e1268239f9bdee3716e5ededecad6faba82e15b653ddf459765002
MD5 2ec4f9eba28859ceb1651d04119f97a3
BLAKE2b-256 6a9aa2aba0a026d13a9c7199b49d046bd09032430d685fd4ee51d3fc0672fb4f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.2.2-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.2.2-cp314-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c27ba585d72fd546b9fc06b66acb1292413fc08d3baed8018722a5da7bd038a5
MD5 e25938a0fe2d1fbc0d94ca13f9e66173
BLAKE2b-256 690c7aa5f9e7230a833069f88828755e7f02947d2bf65f78e134be65e2881310

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyroh-0.2.2-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.2.2-cp314-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9c7fbe5b51a1a20fda984a53da3626ed049eea660d4225533d8942c886c6b54d
MD5 304b4a3147b1305d65fd4fc63ddc3a4e
BLAKE2b-256 af0caecf34bb0802cd1d21710e161e58a00d660f9e65278d4f432ddce38eda84

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