Top Related Projects
Quick Overview
aioquic is a Python library that provides a QUIC implementation based on the asyncio framework. It supports both client and server roles, offering a high-performance, asynchronous implementation of the QUIC protocol and HTTP/3.
Pros
- Asynchronous implementation, leveraging Python's asyncio for efficient I/O operations
- Supports both client and server roles for QUIC and HTTP/3
- Extensive test suite ensuring reliability and compliance with the QUIC protocol
- Active development and maintenance, with regular updates and improvements
Cons
- Limited to Python environments, not suitable for projects using other programming languages
- May have a steeper learning curve for developers not familiar with asyncio
- Performance might not match that of native implementations in languages like C or Rust
- Documentation could be more comprehensive for advanced use cases
Code Examples
- Creating a QUIC client connection:
import asyncio
from aioquic.quic.configuration import QuicConfiguration
from aioquic.quic.connection import QuicConnection
async def main():
configuration = QuicConfiguration(is_client=True)
connection = QuicConnection(configuration=configuration)
# Connect to a QUIC server
await connection.connect(("example.com", 443), now=asyncio.get_event_loop().time())
asyncio.run(main())
- Sending HTTP/3 request:
from aioquic.h3.connection import H3Connection
from aioquic.h3.events import DataReceived, HeadersReceived
async def send_request(connection):
h3_conn = H3Connection(connection)
stream_id = h3_conn.get_next_available_stream_id()
h3_conn.send_headers(
stream_id=stream_id,
headers=[
(b":method", b"GET"),
(b":scheme", b"https"),
(b":authority", b"example.com"),
(b":path", b"/"),
],
)
while True:
event = await h3_conn.get_event()
if isinstance(event, (HeadersReceived, DataReceived)):
# Process received headers or data
print(event)
- Creating a QUIC server:
from aioquic.quic.configuration import QuicConfiguration
from aioquic.asyncio import serve
async def handle_stream(reader, writer):
data = await reader.read()
writer.write(b"Hello, QUIC!")
await writer.close()
async def main():
configuration = QuicConfiguration(is_client=False)
await serve(
host="0.0.0.0",
port=4433,
configuration=configuration,
stream_handler=handle_stream,
)
asyncio.run(main())
Getting Started
To get started with aioquic, follow these steps:
-
Install the library:
pip install aioquic
-
Import the necessary modules:
from aioquic.quic.configuration import QuicConfiguration from aioquic.quic.connection import QuicConnection from aioquic.asyncio import connect
-
Create a QUIC configuration and establish a connection:
configuration = QuicConfiguration(is_client=True) async with connect("example.com", 443, configuration=configuration) as connection: # Use the connection for QUIC communication
For more detailed usage and advanced features, refer to the project's documentation and examples in the GitHub repository.
Competitor Comparisons
ngtcp2 project is an effort to implement IETF QUIC protocol
Pros of ngtcp2
- Written in C, offering potentially better performance and lower-level control
- Focuses solely on QUIC implementation, allowing for a more specialized and optimized codebase
- Provides a comprehensive test suite for QUIC protocol compliance
Cons of ngtcp2
- Requires more manual management of memory and resources
- Less user-friendly for high-level application development compared to Python-based aioquic
- May have a steeper learning curve for developers not familiar with C programming
Code Comparison
ngtcp2 (C):
ngtcp2_conn *conn;
ngtcp2_conn_client_new(&conn, dcid, ¶ms, &callbacks, NULL);
ngtcp2_conn_handshake(conn, buf, &pktlen, NULL, 0, timestamp);
aioquic (Python):
async def run_client(configuration):
async with connect("localhost", 4433, configuration=configuration) as client:
await client.ping()
The code snippets demonstrate the difference in complexity and abstraction level between the two libraries. ngtcp2 requires more low-level setup and management, while aioquic provides a higher-level, more Pythonic interface for QUIC connections.
A QUIC implementation in pure Go
Pros of quic-go
- Written in Go, offering better performance and concurrency handling
- More mature project with a larger community and more frequent updates
- Supports both client and server implementations
Cons of quic-go
- Limited to Go ecosystem, less flexible for cross-language projects
- Steeper learning curve for developers not familiar with Go
- Larger codebase, potentially more complex to understand and modify
Code Comparison
aioquic (Python):
async def connect(host, port, configuration):
async with connect(host, port, configuration=configuration) as client:
await client.ping()
quic-go (Go):
session, err := quic.DialAddr(addr, tlsConf, config)
if err != nil {
return err
}
stream, err := session.OpenStreamSync(context.Background())
Additional Notes
Both aioquic and quic-go are implementations of the QUIC protocol, but they cater to different ecosystems. aioquic is Python-based and leverages asyncio, making it suitable for Python projects and easier integration with other async libraries. quic-go, on the other hand, is designed for Go applications and benefits from Go's performance characteristics and concurrency model.
Cross-platform, C implementation of the IETF QUIC protocol, exposed to C, C++, C# and Rust.
Pros of msquic
- Developed and maintained by Microsoft, potentially offering better long-term support and resources
- Written in C, which may provide better performance and lower-level control
- Extensive documentation and integration guides for various platforms
Cons of msquic
- Larger codebase and potentially more complex to understand and contribute to
- Primarily focused on Windows platforms, though cross-platform support is available
- Steeper learning curve for developers not familiar with C programming
Code Comparison
msquic (C):
QUIC_STATUS
ServerStreamCallback(
_In_ HQUIC Stream,
_In_opt_ void* Context,
_Inout_ QUIC_STREAM_EVENT* Event
)
{
// Handle stream events
}
aioquic (Python):
@asyncio.coroutine
def handle_stream(stream):
while True:
data = yield from stream.recv()
if not data:
break
# Process data
Additional Notes
Both msquic and aioquic implement the QUIC protocol, but they target different use cases and developer audiences. msquic is more suitable for systems programming and high-performance scenarios, while aioquic is ideal for Python developers looking for an asyncio-compatible QUIC implementation. The choice between them depends on the specific project requirements, target platform, and development team expertise.
Async-friendly QUIC implementation in Rust
Pros of quinn
- Written in Rust, offering memory safety and performance benefits
- More active development with frequent updates and contributions
- Comprehensive documentation and examples
Cons of quinn
- Steeper learning curve for developers not familiar with Rust
- Potentially less integration options with Python-based projects
Code Comparison
quinn (Rust):
let mut endpoint = Endpoint::server(server_config, server_addr)?;
while let Some(conn) = endpoint.accept().await {
tokio::spawn(handle_connection(conn));
}
aioquic (Python):
async def run_server(host, port):
configuration = QuicConfiguration(is_client=False)
await serve(host, port, configuration=configuration, handler=handle_client)
Additional Notes
Both quinn and aioquic are QUIC protocol implementations, but they cater to different ecosystems. quinn is more suitable for Rust-based projects, while aioquic integrates well with Python applications. The choice between them often depends on the primary programming language of the project and the specific requirements for QUIC implementation.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
aioquic
.. image:: https://img.shields.io/pypi/l/aioquic.svg :target: https://pypi.python.org/pypi/aioquic :alt: License
.. image:: https://img.shields.io/pypi/v/aioquic.svg :target: https://pypi.python.org/pypi/aioquic :alt: Version
.. image:: https://img.shields.io/pypi/pyversions/aioquic.svg :target: https://pypi.python.org/pypi/aioquic :alt: Python versions
.. image:: https://github.com/aiortc/aioquic/workflows/tests/badge.svg :target: https://github.com/aiortc/aioquic/actions :alt: Tests
.. image:: https://img.shields.io/codecov/c/github/aiortc/aioquic.svg :target: https://codecov.io/gh/aiortc/aioquic :alt: Coverage
.. image:: https://readthedocs.org/projects/aioquic/badge/?version=latest :target: https://aioquic.readthedocs.io/ :alt: Documentation
What is aioquic
?
aioquic
is a library for the QUIC network protocol in Python. It features
a minimal TLS 1.3 implementation, a QUIC stack and an HTTP/3 stack.
aioquic
is used by Python opensource projects such as dnspython
,
hypercorn
, mitmproxy
_ and the Web Platform Tests
_ cross-browser test
suite. It has also been used extensively in research papers about QUIC.
To learn more about aioquic
please read the documentation
_.
Why should I use aioquic
?
aioquic
has been designed to be embedded into Python client and server
libraries wishing to support QUIC and / or HTTP/3. The goal is to provide a
common codebase for Python libraries in the hope of avoiding duplicated effort.
Both the QUIC and the HTTP/3 APIs follow the "bring your own I/O" pattern, leaving actual I/O operations to the API user. This approach has a number of advantages including making the code testable and allowing integration with different concurrency models.
A lot of effort has gone into writing an extensive test suite for the
aioquic
code to ensure best-in-class code quality, and it is regularly
tested for interoperability
_ against other QUIC implementations
_.
Features
- minimal TLS 1.3 implementation conforming with
RFC 8446
_ - QUIC stack conforming with
RFC 9000
_ (QUIC v1) andRFC 9369
_ (QUIC v2)- IPv4 and IPv6 support
- connection migration and NAT rebinding
- logging TLS traffic secrets
- logging QUIC events in QLOG format
- version negotiation conforming with
RFC 9368
_
- HTTP/3 stack conforming with
RFC 9114
_- server push support
- WebSocket bootstrapping conforming with
RFC 9220
_ - datagram support conforming with
RFC 9297
_
Installing
The easiest way to install aioquic
is to run:
.. code:: bash
pip install aioquic
Building from source
If there are no wheels for your system or if you wish to build aioquic
from source you will need the OpenSSL development headers.
Linux .....
On Debian/Ubuntu run:
.. code-block:: console
sudo apt install libssl-dev python3-dev
On Alpine Linux run:
.. code-block:: console
sudo apk add openssl-dev python3-dev bsd-compat-headers libffi-dev
OS X ....
On OS X run:
.. code-block:: console
brew install openssl
You will need to set some environment variables to link against OpenSSL:
.. code-block:: console
export CFLAGS=-I$(brew --prefix openssl)/include export LDFLAGS=-L$(brew --prefix openssl)/lib
Windows .......
On Windows the easiest way to install OpenSSL is to use Chocolatey
_.
.. code-block:: console
choco install openssl
You will need to set some environment variables to link against OpenSSL:
.. code-block:: console
$Env:INCLUDE = "C:\Progra1\OpenSSL\include"
$Env:LIB = "C:\Progra1\OpenSSL\lib"
Running the examples
aioquic
comes with a number of examples illustrating various QUIC usecases.
You can browse these examples here: https://github.com/aiortc/aioquic/tree/main/examples
License
aioquic
is released under the BSD license
_.
.. _read the documentation: https://aioquic.readthedocs.io/en/latest/ .. _dnspython: https://github.com/rthalley/dnspython .. _hypercorn: https://github.com/pgjones/hypercorn .. _mitmproxy: https://github.com/mitmproxy/mitmproxy .. _Web Platform Tests: https://github.com/web-platform-tests/wpt .. _tested for interoperability: https://interop.seemann.io/ .. _QUIC implementations: https://github.com/quicwg/base-drafts/wiki/Implementations .. _cryptography: https://cryptography.io/ .. _Chocolatey: https://chocolatey.org/ .. _BSD license: https://aioquic.readthedocs.io/en/latest/license.html .. _RFC 8446: https://datatracker.ietf.org/doc/html/rfc8446 .. _RFC 9000: https://datatracker.ietf.org/doc/html/rfc9000 .. _RFC 9114: https://datatracker.ietf.org/doc/html/rfc9114 .. _RFC 9220: https://datatracker.ietf.org/doc/html/rfc9220 .. _RFC 9297: https://datatracker.ietf.org/doc/html/rfc9297 .. _RFC 9368: https://datatracker.ietf.org/doc/html/rfc9368 .. _RFC 9369: https://datatracker.ietf.org/doc/html/rfc9369
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot