Skip to content

API reference

The public Python API is intentionally small. Most users only touch the top-level serve() function and a Config instance.

High-performance HTTP/2 ASGI server for FastAPI, Starlette, and similar apps.

h2corn is optimized for h2c behind a trusted reverse proxy, with optional direct TLS support for TCP deployments. Application traffic stays on HTTP/2 end-to-end instead of being downgraded to HTTP/1.1 inside the trust boundary.

The two entrypoints are:

  • serve — start the server through the multi-worker supervisor (Unix) or in-process (Windows). This matches the behavior of the h2corn CLI.
  • Server — embed a single-worker server in your own event loop.

Configuration is provided through Config, which is also constructable from environment variables or a TOML file.

SymbolWhat it is
serveStart the server through the multi-worker supervisor (or in-process on Windows).
ServerEmbed a single-worker server in your own event loop.
ConfigFrozen dataclass holding every server option.
ProxyProtocolModeLiteral type for the proxy_protocol option.
ASGIAppCallable type alias for an ASGI 3 application.

For per-option descriptions, defaults, environment variables, and CLI flags, see the Configuration reference.