Skip to content

Quickstart

This guide takes you from an empty file to a running Litestar application powered by Granian.

Install

Install litestar-granian with your preferred package manager:

uv add litestar-granian
pip install litestar-granian
pdm add litestar-granian
poetry add litestar-granian

Create the Application

Save this example as example.py:

from litestar import Litestar, get

from litestar_granian import GranianPlugin


@get("/")
async def hello() -> dict[str, str]:
    return {"hello": "world"}


app = Litestar(route_handlers=[hello], plugins=[GranianPlugin()])

Run the Server

Start the regular Litestar CLI:

litestar --app example:app run

GranianPlugin registers the run command and starts Granian behind a supervised Litestar parent process.

Verify the Endpoint

Open http://127.0.0.1:8000/ in a browser, or run:

curl http://127.0.0.1:8000/

The response payload is:

{"hello":"world"}

Press Ctrl+C in the server terminal. The port closes cleanly and the command returns to your shell after unwinding any Litestar server lifespans.

Next Steps