Skip to content

Instantly share code, notes, and snippets.

@jfjensen
Created October 18, 2023 09:56
Show Gist options
  • Save jfjensen/c27a84aebb529c66efb1616c6f0d74ba to your computer and use it in GitHub Desktop.
Save jfjensen/c27a84aebb529c66efb1616c6f0d74ba to your computer and use it in GitHub Desktop.
A basic example of how to use Litestar for Python
from asyncio import sleep
from typing import Any
from litestar import Litestar, get
@get("/async")
async def async_hello_world() -> dict[str, Any]:
await sleep(0.1)
return {"hello": "world"}
@get("/sync", sync_to_thread=False)
def sync_hello_world() -> dict[str, Any]:
return {"hello": "world"}
app = Litestar(route_handlers=[sync_hello_world, async_hello_world])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment