{"id":2523,"library":"granian","title":"Granian","description":"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.","status":"active","version":"2.7.3","language":"python","source_language":"en","source_url":"https://github.com/emmett-framework/granian","tags":["http server","asgi","wsgi","rust","performance","websockets"],"install":[{"cmd":"pip install granian","lang":"bash","label":"Install Granian"}],"dependencies":[{"reason":"Used for the command-line interface (CLI) to run applications.","package":"click","optional":false}],"imports":[{"note":"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.","symbol":"Server","correct":"from granian.server.embed import Server"}],"quickstart":{"code":"# main.py\nasync def app(scope, receive, send):\n    assert scope['type'] == 'http'\n    await send({\n        'type': 'http.response.start',\n        'status': 200,\n        'headers': [\n            [b'content-type', b'text/plain'],\n        ],\n    })\n    await send({\n        'type': 'http.response.body',\n        'body': b'Hello, world!',\n    })\n\n# To run from your terminal (assuming main.py is in current directory):\n# granian --interface asgi main:app --port 8000","lang":"python","description":"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`."},"warnings":[{"fix":"Upgrade Python to 3.10+.","message":"Granian 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.","severity":"breaking","affected_versions":">=2.6.0"},{"fix":"Upgrade Granian to v2.7.1 or newer to ensure proper websocket disconnect event handling.","message":"Prior 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.","severity":"gotcha","affected_versions":"<2.7.1"},{"fix":"Upgrade Granian to v2.7.1 or newer to resolve the thread panic issue.","message":"Versions 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.","severity":"gotcha","affected_versions":"<2.7.1"},{"fix":"Upgrade Granian to v2.5.6 or newer to ensure correct `PATH_INFO` handling.","message":"On 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.","severity":"gotcha","affected_versions":"<2.5.6"},{"fix":"Upgrade Granian to v2.5.5 or newer if experiencing startup issues on Python 3.14 with `forkserver`.","message":"On 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`.","severity":"gotcha","affected_versions":"<2.5.5"}],"env_vars":null,"search_vec":"'3.10':69 'activ':58 'aim':39 'applic':12 'asgi':74 'asgi/3':24 'avoid':47 'built':17 'compat':66 'crate':21 'depend':45 'granian':1,2 'gunicorn':50 'handl':31 'high':6 'high-perform':5 'http':8,53,72 'http-tool':52 'http/1':33 'http/2':34 'hyper':20 'implement':13 'interfac':28 'maintain':59 'minor':64 'offer':29 'patch':62 'perform':7,44,77 'project':38 'provid':41 'python':11,68 'regular':61 'releas':65 'robust':30 'rsgi':25 'rust':15,76 'server':9,73 'singl':43 'solut':46 'stack':55 'support':23 'tool':54 'typic':49 'upon':18 'uvicorn':51 'websocket':36,78 'wsgi':27,75","created_at":"2026-04-11T01:31:42.705726+00:00","updated_at":"2026-04-16T15:27:09.275884+00:00","problems":[{"fix":"Install Granian using pip: `pip install granian`","cause":"The 'granian' package is not installed in the Python environment you are currently using, or the environment is not properly activated.","error":"ModuleNotFoundError: No module named 'granian'"},{"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.","cause":"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.","error":"[ERROR] Application callable raised an exception"},{"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`.","cause":"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.","error":"granian: command not found"},{"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).","cause":"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.","error":"RuntimeError: ASGI flow error"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.8.2","cli_name":"granian","cli_version":"granian 2.7.4","type":"library","homepage":"https://granian.rs","github":"https://github.com/sponsors/gi0baro","docs":null,"changelog":null,"pypi":"https://pypi.org/project/granian/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}