pynghttp2
pynghttp2 are simple asyncio Python bindings based on ctypes for the nghttp2 library. The only thing you need is a libnghttp2 version on your system.
On Debian-based systems you can install nghttp2 simply via apt:
apt-get install libnghttp2-14
The project was created in the context of a student work for an HTTP/2 protocol gateway in the µPCN project - an implementation of Delay-tolerant Networking (DTN) protocols.
Installation
pip install pynghttp2
Examples
High-Level API
from pynghttp2 import http2
# GET request
resp = await http2.get('http://localhost:64602/ping')
content = await resp.text()
assert content == 'pong'
# POST request
message = b"Lorem ipsum dolorem"
resp = await http2.post('http://localhost:64602/echo', data=message)
echo = await resp.read()
assert echo == message
Client Session
from pynghttp2 import ClientSession
# Multiplex two requests
async with ClientSession(host='localhost', port=64602) as session:
stream1 = session.get('http://localhost:64602/stream')
stream2 = session.get('http://localhost:64602/stream')
await asyncio.gather(stream1.read(), stream2.read())
Server Session
import asyncio
from pynghttp2 import ServerSession
async def handle_request(req):
"""Echo the request body"""
msg = await req.read()
await req.response(200, data=msg)
with ServerSession(host='localhost', port=8080) as session:
while True:
# Wait for next incoming request
req = await session
# Handle each request in its own task to be able to multiplex
# multiple requests and responses
asyncio.ensure_future(handle_request(req))
Metadata
Release files for pynghttp2 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pynghttp2-0.3.2.tar.gz | 24.0 kB | Without provenance | Details for pynghttp2-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pynghttp2-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for pynghttp2-0.3.2-py3-none-any.whl |
Total release size: 49.3 kB
Release files / pynghttp2-0.3.2.tar.gz
| Download URL | pynghttp2-0.3.2.tar.gz |
|---|---|
| Size | 24.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42263801c3ab55d5aca188af9fa269fd68eefa5fdb43cb22f7686055b6de7247
|
|
BLAKE2b-256 checksum How to use checksums |
ac454e13a6d7bef018f10493c7370ca8c9710cf882017881f79fe6043df5f5a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / pynghttp2-0.3.2-py3-none-any.whl
| Download URL | pynghttp2-0.3.2-py3-none-any.whl |
|---|---|
| Size | 25.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0051bb45c549a4ce4d5bbe8cbde237d50bf84c3366a445c9bc0b27c5e7871937
|
|
BLAKE2b-256 checksum How to use checksums |
f951340b717a7f2555c63d1e4a938f435e0fd30bb09b7cfc16c135f9be65d799
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for pynghttp2 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.