An async HTTP client built on httpunk
Project description
punkreq
punkreq is an async HTTP client for Python, built on top of httpunk.
Note: punkreq is currently in alpha stage.
Note: punkreq was built with substantial help from LLMs, under human supervision.
In a nutshell
- Async only, with multiple runtime backends: import the client from the
module matching your runtime –
punkreq.asyncioorpunkreq.tonio - HTTP/1.1 and HTTP/2, negotiated via TLS ALPN by default; HTTP/2 prior
knowledge with
http1=False - Connection pooling with keep-alive (h1) and multiplexing (h2)
- Transparent response decompression: gzip and deflate everywhere, zstd on
Python 3.14+, brotli with the
punkreq[brotli]extra - Conservative automatic retries — only requests the server provably never processed (HTTP/2 graceful GOAWAY, refused streams, keep-alive races)
- Opt-in cookie jar, basic/bearer auth, multipart uploads
- HTTP proxies:
HTTP_PROXY/HTTPS_PROXY/NO_PROXYenvironment support, CONNECT tunneling for https destinations. - Zero runtime dependencies beyond httpunk
Installation
pip install punkreq
Quickstart
import asyncio
from punkreq.asyncio import Client
async def main():
async with Client(base_url="https://api.example.com") as client:
response = await client.post("/items", json={"name": "widget"})
response.raise_for_status()
print(await response.json())
asyncio.run(main())
One-off requests without managing a client:
from punkreq import asyncio as punkreq
response = await punkreq.get("https://www.example.com")
print(response.status_code, response.headers["content-type"])
Responses resolve as soon as the head arrives; the body is read on demand —
await response.read() / text() / json(), or streamed:
async with Client() as client:
response = await client.get("https://example.com/large.bin")
async for chunk in response.iter_bytes(chunk_size=65536):
...
Reading to the end releases the connection automatically. When you might stop early, use the request as a context manager so the response is always closed:
async with client.get("https://example.com/huge.ndjson") as response:
async for line in response.iter_lines():
if found(line):
break # the block exit closes the response and frees the connection
Configuration
import punkreq
from punkreq.asyncio import Client
client = Client(
base_url="https://api.example.com",
headers={"x-api-key": "..."},
auth=("user", "pass"), # or punkreq.BearerAuth("token")
cookies={}, # enables the cookie jar (off by default)
timeout=punkreq.Timeout(5.0, total=30.0), # no timeouts by default
limits=punkreq.Limits(max_connections=100),
proxy="http://proxy.internal:3128", # env vars honored by default
verify=True, # bool | CA bundle path | ssl.SSLContext
)
By default: redirects on (max 10), no timeouts, no cookie jar unless requested, HTTP/2 enabled, 90s keep-alive expiry, unlimited connections.
Timeout has four independent fields — total (a deadline for the whole
request, redirects included), connect, read and pool. There is no write
timeout: request bodies are written full-duplex from background tasks, so
total is the bound for slow uploads.
Backends
punkreq never asks for a backend at call sites — pick it by import:
from punkreq.asyncio import Client # asyncio, available everywhere
from punkreq.tonio import Client # tonio, free-threaded CPython >= 3.14 on Unix
License
punkreq is released under the BSD License.
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 punkreq-0.1.1.tar.gz.
File metadata
- Download URL: punkreq-0.1.1.tar.gz
- Upload date:
- Size: 54.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2fc4020c071067811f8fe4a844d5fa196daa78241616b57337384cb4013c104
|
|
| MD5 |
46a67358b158cccf2c86725519b18be4
|
|
| BLAKE2b-256 |
6b5d6b0776cf01b41e021b873dc46b594ab822f41414d1f287d0109798c83419
|
Provenance
The following attestation bundles were made for punkreq-0.1.1.tar.gz:
Publisher:
publish.yml on gi0baro/punkreq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
punkreq-0.1.1.tar.gz -
Subject digest:
a2fc4020c071067811f8fe4a844d5fa196daa78241616b57337384cb4013c104 - Sigstore transparency entry: 2153266540
- Sigstore integration time:
-
Permalink:
gi0baro/punkreq@46dd4675c71f7254948c92e2d8ad30521c5b08b6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/gi0baro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@46dd4675c71f7254948c92e2d8ad30521c5b08b6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file punkreq-0.1.1-py3-none-any.whl.
File metadata
- Download URL: punkreq-0.1.1-py3-none-any.whl
- Upload date:
- Size: 43.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
960b5aa9ac47273999939b697b31e7b065ada76efba27c56c5cfdc27e5ead702
|
|
| MD5 |
10017e499875a2fd1b6bbea90b940685
|
|
| BLAKE2b-256 |
949ac71c0414ed880fed195855671e38b293a7e3c2fb1bf02b2f1a6c24b580f9
|
Provenance
The following attestation bundles were made for punkreq-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on gi0baro/punkreq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
punkreq-0.1.1-py3-none-any.whl -
Subject digest:
960b5aa9ac47273999939b697b31e7b065ada76efba27c56c5cfdc27e5ead702 - Sigstore transparency entry: 2153266619
- Sigstore integration time:
-
Permalink:
gi0baro/punkreq@46dd4675c71f7254948c92e2d8ad30521c5b08b6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/gi0baro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@46dd4675c71f7254948c92e2d8ad30521c5b08b6 -
Trigger Event:
release
-
Statement type: