Skip to content

API reference

Use serve() with a Config for the standard server entrypoint, or Server to embed one worker in an existing event loop. The reference is grouped by the ASGI concept a symbol describes; each page contains the complete signature and docstring.

Blazing-fast HTTP/2 ASGI server for Python, written in Rust.

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.

PagePublic symbols
Server entrypointsserve, Server
Configuration typesConfig, ProxyProtocolMode, LifespanMode, CertReqsMode, LoopImpl, ServerHeaderMode, LogFormat
ASGI applications and aliasesASGIApp, FrameworkASGIApp, Application, Receive, Send, Scope, ReceiveMessage, SendMessage, Message
Scopes and extensionsASGIVersions, HTTPASGIVersions, LifespanASGIVersions, Headers, ScopeHeaders, State, Extensions, HTTPExtensions, WebSocketExtensions, ExtensionParameters, TLSExtension
HTTP scope and messagesHTTPScope, HTTPRequest, HTTPDisconnect, HTTPResponseStart, HTTPResponseBody, HTTPResponseTrailers, HTTPResponsePathsend, HTTPResponseZeroCopySend, HTTPResponseEarlyHint
WebSocket scope and messagesWebSocketScope, WebSocketConnect, WebSocketReceiveBytes, WebSocketReceiveText, WebSocketDisconnect, WebSocketAccept, WebSocketSendBytes, WebSocketSendText, WebSocketClose, WebSocketHTTPResponseStart, WebSocketHTTPResponseBody
Lifespan scope and messagesLifespanScope, LifespanStartup, LifespanShutdown, LifespanStartupComplete, LifespanStartupFailed, LifespanShutdownComplete, LifespanShutdownFailed

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