Skip to content

Install and First App

This guide gives you a minimal Lilya app and the exact commands to run it.

Install

Core package:

pip install lilya

If you also want the Lilya client tools:

pip install lilya[standard]

Build a first app

from lilya.apps import Lilya
from lilya.requests import Request
from lilya.responses import Ok
from lilya.routing import Path


async def welcome():
    return Ok({"message": "Welcome to Lilya"})


async def user(user: str):
    return Ok({"message": f"Welcome to Lilya, {user}"})


async def user_in_request(request: Request):
    user = request.path_params["user"]
    return Ok({"message": f"Welcome to Lilya, {user}"})


app = Lilya(
    routes=[
        Path("/{user}", user),
        Path("/in-request/{user}", user_in_request),
        Path("/", welcome),
    ]
)

Run it

palfrey myapp:app --reload

Then open http://127.0.0.1:8000.

What this app already demonstrates

  • Route declaration with Path
  • Path parameter injection into handlers
  • Native response objects

Next steps

  1. First Production Run
  2. Build a Modular API