Server Reference ¶
Running Stario applications is handled by app.serve().
Basic Usage ¶
import asyncio
from stario import Stario, RichTracer
async def main():
with RichTracer() as tracer:
app = Stario(tracer)
app.get("/", home)
await app.serve(host="127.0.0.1", port=8000)
if __name__ == "__main__":
asyncio.run(main())
Configuration ¶
| Argument | Default | Description |
|---|---|---|
host |
"127.0.0.1" |
Bind address. Use "0.0.0.0" for prod. |
port |
8000 |
Port to listen on. |
workers |
1 |
Number of worker processes. |
Production Configuration ¶
For performance, use uvloop and multiple workers.
import uvloop
import os
workers = int(os.environ.get("WORKERS", 4))
uvloop.run(app.serve(host="0.0.0.0", port=8000, workers=workers))
Hot Reload (Development) ¶
Use watchfiles to automatically restart the server when files change.
uvx watchfiles "python main.py" .
Deployment ¶
Docker ¶
Stario requires Python 3.14+.
FROM python:3.14-slim
WORKDIR /app
COPY . .
RUN pip install .
CMD ["python", "main.py"]
Reverse Proxy (Nginx/Caddy) ¶
Since Stario uses SSE extensively, ensure your proxy disables buffering for streaming routes.
Nginx Example:
location /stream {
proxy_pass http://127.0.0.1:8000;
proxy_buffering off;
proxy_cache off;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
Graceful Shutdown ¶
Stario handles SIGINT and SIGTERM. It stops accepting new requests and allows active ones to finish before exiting. Connections using w.alive() will be terminated and cleaned up automatically.
