Build your first LenAPI app
Install the framework, generate an app, and run a typed API locally.
Work through each step in order. The examples use the generated LenAPI project structure and are designed to be adapted to your app.
Install LenAPI
Install from PyPI with pip, or use uv. In a uv-managed project, uv add records LenAPI in pyproject.toml and syncs the environment; uv pip install installs it into the active environment.
# pip
python -m pip install lenapi
# Add LenAPI to a uv-managed project
uv add lenapi
# Or install into the active environment with uv
uv pip install lenapiGenerate the application scaffold
The scaffold separates application code from framework internals. It includes settings, a main module, app models and schemas, tests, and migrations.
lenora startproject myproject
cd myprojectAdd a typed route
LenAPI reads the Pydantic model from the handler signature, validates the incoming JSON body, and documents the operation in OpenAPI.
from pydantic import BaseModel
from lenapi import LENAPI, Router
app = LENAPI()
api = Router(prefix="/api")
class Greeting(BaseModel):
name: str
@api.post("/hello")
async def hello(data: Greeting):
return {"message": f"Hello, {data.name}!"}
app.include_router(api)Migrate, then run
Migrations are explicit. The first migration includes framework-owned tables and discovers models imported by the application.
python lenora.py migration
python lenora.py runThe default development address is http://127.0.0.1:8009. Open /docs/ to try the endpoint in Swagger UI.