DocumentationIntroduction to LenAPI
API referenceGitHub

Introduction to LenAPI

A lightweight ASGI framework that helps developers spin up APIs quickly in a few steps.

YOUR API, WITHOUT THE BUSYWORK

Start with the shape of your idea.

Follow a guide, copy a working example, and build up one part of your backend at a time.

Explore routing
main.py
from lenapi import LENAPI

app = LENAPI()

@app.get("/hello")
def hello():
return {"message": "Hello, world!"}
Ready to run python lenora.py run
22step-by-step guides
Sync + asyncroutes and database access
One toolkitAPI, data, security, realtime

Understand what LenAPI includes, then follow the quickstart and focused guides to build your application step by step.

01

What is LenAPI?

LenAPI is a lightweight Python ASGI framework shaped by real-world backend development. It helps developers spin up APIs quickly in a few steps, with routing, validation, data access, and interactive documentation in one toolkit.

02

What can you build with it?

Key features include:

  • Typed routes, Pydantic validation, and interactive Swagger/OpenAPI docs
  • ORM models, migrations, and sync or async database access
  • Authentication options including JWT, API keys, sessions, OIDC, and social sign-in
  • WebSockets for chat, video signaling, JSON, text, and binary messages
  • Built-in webhook handling for flexible JSON payloads and verified senders
  • Public and private file uploads, middleware, optional gzip, and request throttling
  • Sync/async cache operations and durable background queues with retry and delay options
  • An optional model admin console with per-model permissions and resource monitoring
  • Independent projects that can run separately or mount under a chosen URL prefix
  • Optional OpenAI, Ollama, and Faker integrations
03

Which databases can you use?

LenAPI's supported SQL databases are SQLite (the default), MySQL, and PostgreSQL. MongoDB is the non-relational option and is currently in beta: its separate MongoDocument API is available for developers who want to try it and share feedback. MongoDB does not yet have the same relationship and migration workflow as the SQL backends, so review its guide and limitations before choosing it for production.

  • SQL: SQLite, MySQL, and PostgreSQL use LenAPI's SQL model and migration workflow.
  • Non-relational beta: MongoDB uses MongoDocument for document-based sync and async CRUD and is open for testing.
TIP

Changing DATABASE_TYPE selects the backend; it does not convert existing SQL models, tables, or data. See the MongoDB guide for setup, model differences, and migration limitations.

04

How this documentation is organized

Start with the quickstart to install LenAPI and create your first app. Then follow the guides for routing, validation, data access, security, realtime features, testing, and deployment. Each guide includes practical code you can adapt.

Python
from lenapi import LENAPI

app = LENAPI()

@app.get("/health")
def health():
    return {"status": "ok"}
TIP

The generated development server defaults to http://127.0.0.1:8009, and Swagger UI is available at /docs/.

Explore every feature

22 guides
01Build your first LenAPI appInstall the framework, generate an app, and run a typed API locally.02Routes and routersOrganize endpoints with app decorators, reusable routers, prefixes, tags, and all common HTTP verbs.03Mount independent projectsKeep apps independently configured, then mount sibling projects under URL prefixes when useful.04Request and response schemasValidate request bodies with Pydantic and describe response shapes in Swagger.05Image upload and media servingAccept multipart uploads, save public or private files, and serve private files only through authorized routes.06Models and fieldsDeclare SQLAlchemy-backed tables with model.Model and typed fields, then evolve them through migrations.07Migrations and database setupChoose one database backend, detect model changes, and safely apply migration revisions.08CRUD, search, and paginationCreate records, perform unique lookups, filter and search collections, aggregate values, and paginate results.09Async endpoints and database accessUse async handlers and SQLAlchemy AsyncSession with the same configured database URL.10Authentication patternsChoose JWT, API-key, or Basic authentication, then protect the whole app, a router, or an individual endpoint.11Social sign-in with OAuth and OIDCGenerate explicit login and callback routes for Google, GitHub, and LinkedIn.12Middleware, throttling, and docs protectionAdd security and observability middleware, rate limits, IP cooldowns, CSRF checks, and private Swagger docs.13Dependencies and shared logicReuse route logic for authentication, database access, and request-scoped services.14Admin console and project modelsEnable the optional model admin, choose exposed models and fields, and manage mounted projects from one primary login.15WebSockets: chat, video signaling, JSON, text, and bytesMount a ready-made WebSocket service or handle low-level ASGI WebSocket connections directly.16Cache dataStore JSON-compatible values with expiration in process memory, the configured database, or Redis.17Webhooks: receiving and sending eventsBuild webhook endpoints, choose provider signature verification, handle unsigned senders safely, and process retries without duplicate work.18Background tasks and durable queuesRun small post-response tasks or persist jobs for a separate worker process.19OpenAI, Ollama, and Faker servicesCall OpenAI or local Ollama models asynchronously and generate deterministic fake data for development.20Automated testingRun the framework test suite or generate application endpoint checks and CSV reports.21Configuration and deploymentConfigure the server, database, secrets, proxy boundary, and production process.