How emmett-framework/granian works
Granian is a Rust-backed HTTP server for Python applications. The principal workflow is configuring a server, starting worker processes, accepting HTTP connections, dispatching requests through the selected ASGI, RSGI, or WSGI adapter, and returning responses to clients. Its documented capabilities also include WebSockets, TLS/mTLS, static files, and metrics. The excerpts and source index support the main Rust worker, protocol, networking, runtime, and metrics relationships; some Python startup wiring and unsampled feature internals are not shown, so those links are omitted.
Main entry points: workers.rs Connection Workers · asgi/serve.rs ASGI Serving · common.py Worker Supervisor · rsgi/serve.rs RSGI Serving
Components 24
Python Control Plane
- CLI Configuration
granian/cli.py - Worker Supervisor
granian/server/common.py - Process Workers
granian/server/mp.py - Thread Workers
granian/server/mt.py
Rust Server Core
- Connection Workers
src/workers.rs - Serve Runtime
src/serve.rs - Socket Listeners
src/net.rs
Python Interfaces
- ASGI Adapter
src/asgi/io.rs - ASGI Serving
src/asgi/serve.rs - RSGI Adapter
src/rsgi/io.rs - RSGI Serving
src/rsgi/serve.rs - WSGI Adapter
src/wsgi/io.rs - WSGI Serving
src/wsgi/serve.rs
HTTP Features
- HTTP Protocol
src/http.rs - WebSockets
src/ws.rs - TLS and mTLS
src/tls.rs - Static Files
src/files.rs
Runtime and Metrics
- Async Runtime
src/runtime.rs - Python Callbacks
src/callbacks.rs - Metrics Export
src/metrics.rs - Worker IPC
src/ipc.rs
Other components
- Server Operator
- Python Application
- HTTP Client
Connections 30
- Server Operator → CLI Configuration: configures
README.md - Python Application → Worker Supervisor: target to serve
README.md - CLI Configuration → Worker Supervisor: starts server
- Worker Supervisor → Process Workers: spawns
granian/server/mp.py - Worker Supervisor → Thread Workers: selects mode
granian/server/mt.py - Process Workers → Connection Workers: runs workers
- Thread Workers → Connection Workers: runs workers
- Connection Workers → Socket Listeners: accepts connections
src/workers.rs - Connection Workers → ASGI Serving: dispatches requests
src/workers.rs - Connection Workers → RSGI Serving: dispatches requests
src/workers.rs - Connection Workers → WSGI Serving: dispatches requests
src/workers.rs - ASGI Serving → Serve Runtime: serves via
src/asgi/serve.rs - RSGI Serving → Serve Runtime: serves via
src/rsgi/serve.rs - WSGI Serving → Serve Runtime: serves via
src/wsgi/serve.rs - ASGI Serving → HTTP Protocol: handles HTTP
src/asgi/serve.rs - RSGI Serving → HTTP Protocol: handles HTTP
src/rsgi/serve.rs - WSGI Serving → HTTP Protocol: handles HTTP
src/wsgi/serve.rs - ASGI Adapter → ASGI Serving: adapts requests
- RSGI Adapter → RSGI Serving: adapts requests
- WSGI Adapter → WSGI Serving: adapts requests
- Connection Workers → Static Files: checks mounts
src/workers.rs - Connection Workers → TLS and mTLS: configures TLS
src/workers.rs - Connection Workers → Metrics Export: updates metrics
src/workers.rs - Serve Runtime → Async Runtime: runs tasks
src/serve.rs - Async Runtime → Python Callbacks: uses callbacks
src/runtime.rs - Connection Workers → Worker IPC: uses worker IPC
src/workers.rs - Metrics Export → Worker IPC: collects worker data
src/metrics.rs - HTTP Client → Socket Listeners: opens connection
README.md - HTTP Protocol → HTTP Client: returns response
- ASGI Serving → WebSockets: supports WebSockets
README.md