Skip to main content

An async-native WebTransport stack for Python.

Project description

PyWebTransport Logo

PyWebTransport

An async-native WebTransport stack for Python


PyPI version Python Version License: Apache 2.0 CI Coverage Docs

Features

  • Sans-I/O Architecture: Powered by an ownership-driven Rust state machine decoupled from an autonomous threaded reactor via a lock-free IPC boundary.
  • Transport Primitives: Full implementation of bidirectional streams, unidirectional streams, and unreliable datagrams.
  • Structured Concurrency: Deterministic lifecycle management for connections and streams via asynchronous context managers.
  • Zero-Copy I/O: End-to-end support for buffer protocols and memoryview to minimize data copying overhead.
  • Application Framework: Declarative ServerApp featuring path-based routing and composable stateful middleware.

Installation

pip install pywebtransport

Quick Start

Server

import asyncio

from pywebtransport import Event, ServerApp, ServerConfig, WebTransportSession, WebTransportStream
from pywebtransport.types import EventType
from pywebtransport.utils import generate_self_signed_cert

generate_self_signed_cert(hostname="localhost")

app = ServerApp(config=ServerConfig(certfile="localhost.crt", keyfile="localhost.key"))


@app.route(path="/")
async def echo_handler(session: WebTransportSession) -> None:
    async def on_datagram(event: Event) -> None:
        if isinstance(event.data, dict) and (data := event.data.get("data")):
            await session.send_datagram(data=b"ECHO: " + data)

    session.events.on(event_type=EventType.DATAGRAM_RECEIVED, handler=on_datagram)

    try:
        async for stream in session.incoming_bidirectional_streams():
            asyncio.create_task(handle_stream(stream))
    finally:
        session.events.off(event_type=EventType.DATAGRAM_RECEIVED, handler=on_datagram)


async def handle_stream(stream: WebTransportStream) -> None:
    try:
        data = await stream.read_all()
        await stream.write_all(data=b"ECHO: " + data, end_stream=True)
    except Exception:
        pass


if __name__ == "__main__":
    app.run(host="127.0.0.1", port=4433)

Client

import asyncio
import ssl

from pywebtransport import ClientConfig, WebTransportClient
from pywebtransport.types import EventType


async def main() -> None:
    config = ClientConfig(verify_mode=ssl.CERT_NONE)

    async with WebTransportClient(config=config) as client:
        session = await client.connect(url="https://127.0.0.1:4433/")

        await session.send_datagram(data=b"Hello, Datagram!")

        event = await session.events.wait_for(event_type=EventType.DATAGRAM_RECEIVED)
        if isinstance(event.data, dict) and (data := event.data.get("data")):
            print(f"Datagram: {data!r}")

        stream = await session.create_bidirectional_stream()
        await stream.write_all(data=b"Hello, Stream!", end_stream=True)

        response = await stream.read_all()
        print(f"Stream: {response!r}")

        await session.close()


if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass

Interoperability

Infrastructure

Endpoints

  • /echo: Bidirectional stream and datagram reflection.
  • /stats: Current session statistics and negotiated parameters.
  • /status: Global server health and aggregate metrics.
  • /webtransport/devious-baton: Devious Baton protocol state transition validation.

Sponsors

License

Distributed under the terms of the Apache License 2.0. See LICENSE for details.

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

pywebtransport-0.19.1.tar.gz (809.3 kB view details)

Uploaded Source

Built Distributions

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

pywebtransport-0.19.1-cp312-abi3-win_arm64.whl (2.3 MB view details)

Uploaded CPython 3.12+Windows ARM64

pywebtransport-0.19.1-cp312-abi3-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.12+Windows x86-64

pywebtransport-0.19.1-cp312-abi3-manylinux_2_34_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.34+ x86-64

pywebtransport-0.19.1-cp312-abi3-manylinux_2_34_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.34+ ARM64

pywebtransport-0.19.1-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (4.6 MB view details)

Uploaded CPython 3.12+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file pywebtransport-0.19.1.tar.gz.

File metadata

  • Download URL: pywebtransport-0.19.1.tar.gz
  • Upload date:
  • Size: 809.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pywebtransport-0.19.1.tar.gz
Algorithm Hash digest
SHA256 6338490f05a226f81655a763357e252299e2d7f42efbe0e1b8cd51b35b9b7fe7
MD5 ff28ce700af5766470f66d14508e63b2
BLAKE2b-256 76025e107af9335bc0530d6ec331a309211f2146bd7c7902adde33ab316da09e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywebtransport-0.19.1.tar.gz:

Publisher: ci.yml on wtransport/pywebtransport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pywebtransport-0.19.1-cp312-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for pywebtransport-0.19.1-cp312-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 86edbea9f958cea56cb965e189faa40c09b23ce1bc99bbc23cbf5387e2ab84a6
MD5 07b0cde87537e51c29b56c1a4576c7fb
BLAKE2b-256 a1e765b54d845d66c29f7835b34e75a66b6152dd1b524008fe6fb3b908eafab7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywebtransport-0.19.1-cp312-abi3-win_arm64.whl:

Publisher: ci.yml on wtransport/pywebtransport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pywebtransport-0.19.1-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pywebtransport-0.19.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ebfa25dda4365f9d98714faa72de3ba3cded49ebf1b71a816f178f5a90ace34f
MD5 2b5f49fc088f9c14f5966903d0c95d41
BLAKE2b-256 6f9bb971b73b30326e49b23a256091829b49226fe67c89db02c05c603411817f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywebtransport-0.19.1-cp312-abi3-win_amd64.whl:

Publisher: ci.yml on wtransport/pywebtransport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pywebtransport-0.19.1-cp312-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pywebtransport-0.19.1-cp312-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e5281afad62e699e293ad2f8e0595adc695a341ee2bc18cc3cc010a7e80a7650
MD5 4b6d846a9e69d1ac638788b29693082f
BLAKE2b-256 a4373c80cdd82bf70535ef05b1b43ee30d3d5d086694bf1f6d1feceb61b0dae2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywebtransport-0.19.1-cp312-abi3-manylinux_2_34_x86_64.whl:

Publisher: ci.yml on wtransport/pywebtransport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pywebtransport-0.19.1-cp312-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pywebtransport-0.19.1-cp312-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 cd564c1ce724c2a9386784ce135f9e8c55dce43f7155784674f5f3eeca9669bb
MD5 525532feaae56b82f945306404408f75
BLAKE2b-256 efb528911bcaae76912fef6002bc9d3cb4b9704b40c559f0b5fe98bc29642b5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywebtransport-0.19.1-cp312-abi3-manylinux_2_34_aarch64.whl:

Publisher: ci.yml on wtransport/pywebtransport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pywebtransport-0.19.1-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for pywebtransport-0.19.1-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 913581ee457a8e0742ee56df4315d8805f7bdf57f2d33b7a8af368c049e59cd1
MD5 6071ed98b8c38a038e0238de5e1b12a2
BLAKE2b-256 d2e3945f4ae3301f959c63c636fd9492e2f083d907851f3421e716a946d2352c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pywebtransport-0.19.1-cp312-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: ci.yml on wtransport/pywebtransport

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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