Registry / web-framework / granian

granian

JSON →
library2.8.2pypypi✓ verified 23d ago

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 granian
INSTALL
IMPORT
SIG · GRANIAN
G
granian
web-frameworkpythonv2.8.2
Install
2.1s avg
Import
331ms
Disk
35MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.8.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.352s · 39MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.1s · import 0.310s · 39MB
35MB installed
● package 35MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Server
from granian.server.embed import Server
This import is for embedding Granian programmatically within an application for advanced lifecycle management. It is currently considered experimental and only supports async protocols (ASGI/RSGI), not WSGI. Most users will interact with Granian via its command-line interface directly.

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`.

# main.py async def app(scope, receive, send): assert scope['type'] == 'http' await send({ 'type': 'http.response.start', 'status': 200, 'headers': [ [b'content-type', b'text/plain'], ], }) await send({ 'type': 'http.response.body', 'body': b'Hello, world!', }) # To run from your terminal (assuming main.py is in current directory): # granian --interface asgi main:app --port 8000
granian --version
Debug
Known issues
breakingGranian dropped support for Python 3.9 and PyPy 3.9/3.10 starting from v2.6.0. Users on these versions must upgrade their Python environment to Python 3.10 or newer.
fix
Upgrade Python to 3.10+.
affects: >=2.6.0
gotchaPrior to v2.7.1, ASGI applications, particularly those using Django channels, might not reliably receive `websocket.disconnect` events after a server-initiated close, potentially leading to connection hangs.
fix
Upgrade Granian to v2.7.1 or newer to ensure proper websocket disconnect event handling.
affects: <2.7.1
gotchaVersions prior to v2.7.1 could experience an occasional runtime thread panic (`Cannot drop pointer into Python heap without the thread being attached`) during websocket cleanup on shutdown.
fix
Upgrade Granian to v2.7.1 or newer to resolve the thread panic issue.
affects: <2.7.1
gotchaOn WSGI applications, versions prior to v2.5.6 could have incorrect `PATH_INFO` values in the `environ` dictionary when the `--url-path-prefix` option was used. This could lead to incorrect routing or resource access.
fix
Upgrade Granian to v2.5.6 or newer to ensure correct `PATH_INFO` handling.
affects: <2.5.6
gotchaOn Unix systems, Granian v2.5.5 addressed an issue preventing startup on Python 3.14 when using the `forkserver` multiprocessing start method, by falling back to `spawn`.
fix
Upgrade Granian to v2.5.5 or newer if experiencing startup issues on Python 3.14 with `forkserver`.
affects: <2.5.5
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'granian'
The 'granian' package is not installed in the Python environment you are currently using, or the environment is not properly activated.
fix
Install Granian using pip: `pip install granian`
[ERROR] Application callable raised an exception
An unhandled exception occurred within your Python application code that Granian is serving, leading to a worker process crash or restart. This can also be triggered by using Python's built-in `breakpoint()` which Granian might interpret as an error.
fix
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.
granian: command not found
The `granian` executable is not in your system's PATH. This usually happens if Granian was not installed or the Python virtual environment where it's installed is not activated. It can also occur if attempting to use CLI flags introduced in newer versions with an older Granian installation.
fix
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`.
RuntimeError: ASGI flow error
This error arises in ASGI applications, particularly with WebSockets, when there is an invalid state or message sequence according to the ASGI specification. It often means the application is trying to send data over a connection that is already closed or improperly handled.
fix
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).
Upgrade
Version history
2.8.2latest on PyPI · released Aug 23, 2026
Audit
Dependencies
clickrequiredUsed for the command-line interface (CLI) to run applications.
Agent activity
14 hits · last 30 days
node
12
Resources