Granian is a high-performance HTTP server for Python applications, implemented in Rust and built upon the Hyper crate. It supports ASGI/3, RSGI, and WSGI interfaces, offering robust handling for HTTP/1, HTTP/2, and Websockets. The project aims to provide a single, performant dependency solution, avoiding the typical Gunicorn + Uvicorn + http-tools stack. It is actively maintained with regular patch and minor releases, compatible with Python 3.10 and above.
pip install granianVerified import paths — ran on the pinned version, not inferred.
Create an ASGI application in a file (e.g., `main.py`), then serve it using the `granian` command-line interface. This example starts Granian on `127.0.0.1:8000` serving the ASGI application `app` from `main.py`.
Upgrade Python to 3.10+.
Upgrade Granian to v2.7.1 or newer to ensure proper websocket disconnect event handling.
Upgrade Granian to v2.7.1 or newer to resolve the thread panic issue.
Upgrade Granian to v2.5.6 or newer to ensure correct `PATH_INFO` handling.
Upgrade Granian to v2.5.5 or newer if experiencing startup issues on Python 3.14 with `forkserver`.
Install Granian using pip: `pip install granian`
Debug your application code to identify and fix the underlying exception. If using `breakpoint()`, consider removing it or using a remote debugger. For more detailed Granian crash information, set the environment variable `RUST_BACKTRACE=full` before running Granian.
Ensure Granian is installed via `pip install granian` and that your virtual environment is activated. If you're seeing issues with specific flags, upgrade Granian to the latest version: `pip install --upgrade granian`.
Review your ASGI application's WebSocket handling logic to ensure messages are only sent when the connection is active and that the connection lifecycle (connect, receive, disconnect) is correctly managed. Ensure you are using the latest version of Granian, as some related issues have been resolved in recent updates (e.g., version 2.3.2 fixed a related issue with Django Channels).