A high-performance, async-native WebTransport implementation for Python.
Project description
PyWebTransport
A high-performance, async-native WebTransport implementation for Python.
Features
- Full WebTransport protocol implementation (bidirectional streams, unidirectional streams, datagrams).
- High-performance async client and server application frameworks.
- Production-ready components for connection pooling, management, and load balancing.
- Comprehensive monitoring and debugging capabilities.
- Type-safe API with complete type annotations.
- Extensive test coverage (unit, integration, end-to-end).
Installation
pip install pywebtransport
Quick Start
Server
# server.py
import asyncio
from pywebtransport import ServerApp, ServerConfig, WebTransportSession, WebTransportStream
from pywebtransport.exceptions import ConnectionError, SessionError
from pywebtransport.utils import generate_self_signed_cert
generate_self_signed_cert("localhost")
app = ServerApp(
config=ServerConfig.create(
certfile="localhost.crt",
keyfile="localhost.key",
)
)
async def handle_datagrams(session: WebTransportSession) -> None:
try:
datagrams = await session.datagrams
while True:
data = await datagrams.receive()
await datagrams.send(b"ECHO: " + data)
except (ConnectionError, SessionError, asyncio.CancelledError):
pass
async def handle_streams(session: WebTransportSession) -> None:
try:
async for stream in session.incoming_streams():
if isinstance(stream, WebTransportStream):
data = await stream.read_all()
await stream.write_all(b"ECHO: " + data)
except (ConnectionError, SessionError, asyncio.CancelledError):
pass
@app.route("/")
async def echo_handler(session: WebTransportSession) -> None:
datagram_task = asyncio.create_task(handle_datagrams(session))
stream_task = asyncio.create_task(handle_streams(session))
try:
await session.wait_closed()
finally:
datagram_task.cancel()
stream_task.cancel()
if __name__ == "__main__":
app.run(host="127.0.0.1", port=4433)
Client
# client.py
import asyncio
import ssl
from pywebtransport import ClientConfig, WebTransportClient
async def main() -> None:
config = ClientConfig.create(verify_mode=ssl.CERT_NONE)
async with WebTransportClient.create(config=config) as client:
session = await client.connect("https://127.0.0.1:4433/")
print("Connection established. Testing datagrams...")
datagrams = await session.datagrams
await datagrams.send(b"Hello, Datagram!")
response = await datagrams.receive()
print(f"Datagram echo: {response!r}\n")
print("Testing streams...")
stream = await session.create_bidirectional_stream()
await stream.write_all(b"Hello, Stream!")
response = await stream.read_all()
print(f"Stream echo: {response!r}")
await session.close()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
Documentation
- Installation Guide - Setup and installation
- Quick Start - 5-minute tutorial
- API Reference - Complete API documentation
Requirements
- Python 3.11+
- asyncio support
- TLS 1.3
Dependencies:
- aioquic >= 1.2.0
- cryptography >= 45.0.4
Contributing
Contributions are welcome! Please read our Contributing Guide for details.
Development Setup:
git clone https://github.com/lemonsterfy/pywebtransport.git
cd pywebtransport
pip install -r dev-requirements.txt
pip install -e .
tox
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- aioquic for QUIC protocol implementation
- WebTransport Working Group for protocol standardization
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: lemonsterfy@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pywebtransport-0.2.0.tar.gz.
File metadata
- Download URL: pywebtransport-0.2.0.tar.gz
- Upload date:
- Size: 92.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcb81cdefe926f57f2b1ffdb32bb5e408bb7ece1a7e2bcf7fdf8a12d6b42e9ad
|
|
| MD5 |
62c1e4efcc5711340c4a1d58ef1e73cf
|
|
| BLAKE2b-256 |
38323ba9eff5c9837e5ab6f9ff9d98a75a03d24935dab319f15946469559fce6
|
File details
Details for the file pywebtransport-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pywebtransport-0.2.0-py3-none-any.whl
- Upload date:
- Size: 120.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c65c7aade7f151b78f478620c9a04b9d77b67bd81b754c6568e080fb66ce7470
|
|
| MD5 |
4cc18fef6369fe047f2b367e3dc73aea
|
|
| BLAKE2b-256 |
9a085422acd453c76ac54353d72fabb57051892460947ad8f9a8584d61989382
|