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:
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:
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:
The response payload is:
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¶
- Read Configuration & Runtime for bindings, reload, protocols, TLS, workers, and optional event loops.
- Read Deployment & TLS for signal handling, graceful shutdown deadlines, and Linux socket tuning.
- Read Logging & Metrics for automatic formatter matching and Prometheus metrics.
- Keep the CLI Reference open for the complete option list.