CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-hypercorn

A high-performance ASGI and WSGI web server implementation that provides comprehensive support for modern web protocols including HTTP/1, HTTP/2, WebSockets, and experimental HTTP/3

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

server-execution.mddocs/

Server Execution

Core server execution functions that provide the main entry points for running Hypercorn servers. These functions handle server startup, worker management, and shutdown processes for both programmatic and command-line usage.

Capabilities

Main Server Runner

Primary function for executing the Hypercorn server with a given configuration, supporting multiple worker classes and handling server lifecycle.

def run(config: Config) -> int:
    """
    Main entry point to run Hypercorn server.
    
    Starts the Hypercorn server with the provided configuration,
    supporting both single-worker and multi-worker modes.
    Handles worker lifecycle, signal handling, and graceful shutdown.
    
    Args:
        config: Config object containing all server settings
        
    Returns:
        Exit code (0 for success, non-zero for errors)
        
    Supported worker classes:
        - 'asyncio': Standard asyncio event loop
        - 'uvloop': High-performance uvloop event loop  
        - 'trio': Trio async framework
    """

Command Line Interface

CLI entry point that parses command-line arguments and runs the server, providing access to all configuration options through command-line flags.

def main(sys_args: list[str] | None = None) -> int:
    """
    CLI entry point with argument parsing.
    
    Parses command-line arguments to create configuration and
    runs the Hypercorn server. Provides access to all Config
    options through command-line flags and positional arguments.
    
    Args:
        sys_args: Optional list of command-line arguments.
                 If None, uses sys.argv
                 
    Returns:
        Exit code (0 for success, non-zero for errors)
        
    Command-line usage:
        hypercorn [OPTIONS] APPLICATION_PATH
        
    Common options:
        --bind, -b: Binding address (can be used multiple times)
        --workers, -w: Number of worker processes  
        --worker-class, -k: Worker class (asyncio, uvloop, trio)
        --certfile: SSL certificate file
        --keyfile: SSL private key file
        --reload: Enable auto-reload on file changes
        --access-logfile: Access log file path
        --error-logfile: Error log file path
        --log-level: Logging level
        --pid: PID file path
        --daemon: Run as daemon process
    """

Usage Examples

Programmatic Server Execution

from hypercorn.config import Config
from hypercorn.run import run

# Create and configure server
config = Config()
config.bind = ["0.0.0.0:8000"] 
config.workers = 4
config.worker_class = "asyncio"

# Run the server
exit_code = run(config)
print(f"Server exited with code: {exit_code}")

Command Line Usage

# Basic usage
hypercorn app:application

# Specify binding and workers
hypercorn --bind 0.0.0.0:8000 --workers 4 app:application

# HTTPS with SSL certificates
hypercorn --certfile cert.pem --keyfile key.pem --bind 0.0.0.0:443 app:application

# Development mode with auto-reload
hypercorn --reload --bind 127.0.0.1:8000 app:application

# Production settings
hypercorn \
  --bind 0.0.0.0:8000 \
  --workers 8 \
  --worker-class uvloop \
  --access-logfile access.log \
  --error-logfile error.log \
  --pid hypercorn.pid \
  app:application

Integration with Process Managers

# Using with systemd
[Unit]
Description=Hypercorn ASGI Server
After=network.target

[Service]
Type=exec
ExecStart=/usr/local/bin/hypercorn --bind 0.0.0.0:8000 --workers 4 app:application
Restart=always
User=www-data
Group=www-data

[Install]
WantedBy=multi-user.target

Signal Handling

The server responds to standard UNIX signals:

  • SIGTERM: Graceful shutdown
  • SIGINT: Graceful shutdown (Ctrl+C)
  • SIGUSR1: Restart workers (master process continues)
  • SIGCHLD: Handle child process termination

Worker Management

In multi-worker mode:

  • Master process manages worker lifecycle
  • Workers are automatically restarted if they crash
  • Graceful worker replacement during configuration reloads
  • Load balancing across workers using SO_REUSEPORT (when available)

Install with Tessl CLI

npx tessl i tessl/pypi-hypercorn

docs

application-wrappers.md

async-integration.md

configuration.md

events.md

index.md

logging.md

middleware.md

server-execution.md

types.md

utilities.md

tile.json