Granian

2.7.3 · active · verified Fri Apr 10

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.

Warnings

Install

Imports

Quickstart

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

view raw JSON →