Skip to main content

punkasgi

punkasgi is an ASGI server for the TonIO runtime, built on top of HTTPunk.

Warning: punkasgi is in an early stage and still work in progress.

Note: punkasgi was built with substantial help from LLMs, under human supervision.

In a nutshell

  • HTTP/1.0, HTTP/1.1 and HTTP/2 (prior knowledge on plain TCP, ALPN over TLS), with every protocol behaviour coming from httpunk: keep-alive, head timeouts, framing, Date headers, graceful shutdown
  • WebSockets over HTTP/1.1 through the sans-io websockets implementation, with keepalive pings, per-message deflate and the websocket.http.response extension
  • The ASGI 3 protocol handling (scope contents, receive() / send() semantics, lifespan, websocket messages) follows uvicorn
  • Single process architecture: the TonIO runtime's threads are the workers

Installation

pip install punkasgi

punkasgi needs a free-threaded CPython 3.14 or later, as tonio does. The standard extra adds python-dotenv (for --env-file) and PyYAML (for YAML logging configurations).

Quickstart

# main.py
async def app(scope, receive, send):
    assert scope["type"] == "http"
    await send({"type": "http.response.start", "status": 200, "headers": [(b"content-type", b"text/plain")]})
    await send({"type": "http.response.body", "body": b"Hello, world!"})
punkasgi main:app

Or programmatically:

import punkasgi

punkasgi.run("main:app", host="0.0.0.0", port=8000, threads=4)

punkasgi --help lists every option. The ones worth knowing:

option note
--threads size of the tonio runtime, defaults to $WEB_CONCURRENCY or the CPU count
--http auto|h1|h2 protocol selection: auto sniffs the HTTP/2 preface on plain TCP and follows ALPN over TLS
--ws/--no-ws WebSocket upgrades on or off; with them off an upgrade request is answered 400
--timeout-keep-alive hyper's head read timeout: it bounds the idle wait between requests together with the read of the next request head
--timeout-graceful-shutdown how long a shutdown waits for in-flight requests; unset waits without a deadline
--proxy-headers trust X-Forwarded-For / X-Forwarded-Proto from --forwarded-allow-ips; off by default
--access-log one punkasgi.access line per response; off by default

A first SIGINT or SIGTERM starts a graceful shutdown; a second SIGINT leaves at once with whatever is still in flight. Environment variables use the PUNKASGI_ prefix (e.g. PUNKASGI_PORT), loggers are punkasgi.error, punkasgi.access and punkasgi.asgi, and the default server header is punkasgi.

Behaviours worth knowing

These follow httpunk, and through it hyper, rather than any other server:

  • Unread request bodies. After a response completes, a request body the application left unread is drained only if it is already buffered; otherwise the connection closes instead of being reused for the next request.
  • Response content-length. punkasgi does not check the body against the declared length. On HTTP/1 a body shorter than declared fails the response and closes the connection, and a longer one is cut at the declared length; on HTTP/2 the frames go out as sent.
  • Date header. Always written, on both protocols.

License

punkasgi is released under the BSD-3-Clause license.

Metadata

Release files for punkasgi 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for punkasgi 0.1.0
File Size Uploaded
punkasgi-0.1.0.tar.gz 42.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for punkasgi 0.1.0
File Interpreter ABI Platform
punkasgi-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 82.3 kB

Release files / punkasgi-0.1.0.tar.gz

Download URL punkasgi-0.1.0.tar.gz
Size 42.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d03923d3e419bc4be77b63d550e4466a31f4bb169f77e0d28cfa9e1b7254a493
BLAKE2b-256 checksum
How to use checksums
d739d5897451032301790012defa29f51075e29454314febabb3de9e89604e4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / punkasgi-0.1.0-py3-none-any.whl

Download URL punkasgi-0.1.0-py3-none-any.whl
Size 40.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90e3985b1ad3ed885af07a323aa64d02f38aa5e71e728d50ce57f5d7aaeb5bc1
BLAKE2b-256 checksum
How to use checksums
b62cffc00296ce7a0704feb6322d34bd5dbc0cdf9e19e584917f21995f76019f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page