emmett-framework /granian

A Rust HTTP server for Python applications

★ 5,786⑂ 186👁 42⑃ 458● 396▤ 120
RustBSD-3-ClauseCreated 2022-04-15
下载:Granian 2.8.8Granian-2.8.8 ↓2.8.82026-11-11
+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

Discussions

Latest release

Granian 2.8.8 v2.8.8 2026-11-11
Patch 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

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON