Created
October 18, 2023 09:56
-
-
Save jfjensen/c27a84aebb529c66efb1616c6f0d74ba to your computer and use it in GitHub Desktop.
A basic example of how to use Litestar for Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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