emmett-framework /granian
A Rust HTTP server for Python applications
★ 5,786⑂ 186👁 42⑃ 458● 396▤ 120
+1
日增长
5,786
stars
186
forks
42
watchers
458
prs
396
issues
120
releases
README
The Rust HTTP server for Python
---
Granian is a Rust HTTP server for Python applications built on top of Hyper and Tokio.
Rationale
The main reasons behind Granian design are:
- Have a single, correct HTTP implementation, supporting versions 1, 2 (and eventually 3)
- Provide a single package for several platforms
- Avoid the usual Gunicorn + uvicorn + http-tools dependency composition on unix systems
- Provide stable performance when compared to existing alternatives
Adopting Granian would thus be a good choice when:
- wanting a modern, single dependency to serve both ASGI and WSGI applications
- looking for the most performant way to serve your Python application under HTTP/2
- you need great concurrency capabilities, especially with websockets
- you care about throughput more than everything else
On the other hand, Granian won't be the ideal option if:
- you want a pure Python solution
- you need advanced debugging features
- your application relies on trio or gevent
- you're looking for ASGI extensions not (yet) implemented
Features
- Supports ASGI/3, RSGI and WSGI interface applications
- HTTP/1 and HTTP/2 protocols
- HTTPS and mTLS
- Websockets
- Direct static files serving
- ASGI pathsend extension
Quickstart
You can install Granian using pip:
$ pip install granian
ASGI
Create an application in your main.py:
python
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!',
})
and serve it using Granian CLI:
$ granian --interface asgi main:app
RSGI
Create an application your main.py:
python
async def app(scope, proto):
assert scope.proto == 'http'
proto.response_str(
status=200,
headers=[
('content-type', 'text/plain')
],
body="Hello, world!"
)
and serve it using Granian CLI:
$ granian --interface rsgi main:app
WSGI
Create an application your main.py:
python
def app(environ, start_response):
start_response('200 OK', [('content-type', 'text/plain')])
return [b"Hello, world!"]
and serve it using Granian CLI:
$ granian --interface wsgi main:app
Extra dependencies
Mind that Granian also provides several extra dependencies you might be interested into, in particular:
- dotenv (allows to load environment files)
- pname (allows to customize processes' names)
- reload (adds reload on changes functionality)
- rloop
- uvloop
- winloop
You can combine the above extras to suit your needs, eg:
$ pip install granian[pname,uvloop]
For further information, check the options below.
Options
You can check all the options provided by Granian with the --help command:
$ granian --help
Usage: granian [OPTIONS] APP
APP Application target to serve. [required]
Top issues
#577Feature request: Pre-compressed static files13 comments · 2025-05-13#613Setting to send ping in websocket connections10 comments · 2025-06-20#594Feature request: Allow disabling the server header entirely9 comments · 2025-06-06#358Add documentation for "programmatic" usage8 comments · 2024-07-29#602Support file-based configuration7 comments · 2025-06-10#651Occasionally, when the service is shut down, it fails to close normally and the progress gets stuck5 comments · 2025-07-26#586[Feature request] Decompress `Content-Encoding` request bodies5 comments · 2025-05-26#93ASGI extensions support5 comments · 2023-06-26
Discussions
#974Enroll granian in anthropics/oss-scanner0 comments · 2026-11-11#960Optional Django ASGI runserver integration using the embedded server1 comments · 2026-10-30#907Why is keep-alive capped at 60s?1 comments · 2026-08-14#906Free-threaded Python: four Granian worker threads use one CPU core while four processes scale normally2 comments · 2026-08-14#886Load balancing via reverse proxy1 comments · 2026-07-28#880Support non-HTTP protocols for deploying behind reverse proxies1 comments · 2026-07-10#842Need help with metrics1 comments · 2026-04-14#841Clarify worker-count warning and note Uvicorn comparison1 comments · 2026-04-13
Latest release
Granian 2.8.8 v2.8.8 2026-11-11Patch release Changes since 2.8.7: Fix WSGI input readline/readlines splitting with buffered contents Avoid to strip newlines in WSGI input readline/readlines methods Fix a bug with duplicated headers handling in ASGI websocket denial responses Add a 500ms delay on EMFILE/ENFILE accept errors in listeners Bump dependencies