Skip to main content

lambroute

Lambda + Route + Swagger. A lightweight Python API framework for AWS Lambda, with a Rust routing core and auto-generated OpenAPI/Swagger docs.

Write plain Python functions; lambroute handles routing, parameter parsing, validation, responses, errors, CORS, auth hooks and OpenAPI/Swagger for API Gateway (REST API, HTTP API 1.0 / 2.0) and Lambda Function URLs.

pip install lambroute                 # core: zero runtime dependencies
pip install "lambroute[validation]"   # + Pydantic v2 request/response models

Supported: CPython 3.10–3.14 · Linux x86_64 / arm64 (manylinux2014, AWS Lambda), macOS, Windows. One abi3 wheel per platform covers every supported Python version.

Quick start

from lambroute import API

app = API(title="Customer Management API", version="1.0.0", swagger=True)

@app.get("/customers")
def get_customers(limit: int = 20):
    return {"success": True, "data": []}

@app.get("/customers/{customer_id}")
def get_customer(customer_id: str):
    return {"customer_id": customer_id}

@app.post("/customers", status_code=201)
def create_customer(request):            # `request` (or `r: Request`) injects the Request
    return {"received": request.json()}

def lambda_handler(event, context):
    return app.resolve(event, context)   # or simply: lambda_handler = app

GET /docs serves Swagger UI, /redoc ReDoc, and /openapi.json the spec — all generated from the same route registry used for routing.

Features

Area What you get
Routing @app.get/post/put/patch/delete/options/head, {param} and greedy {proxy+} paths, static-over-dynamic priority with backtracking, Router(prefix=…) modules (nestable), duplicate/conflict detection at import time, 404 / 405 + Allow, HEAD→GET, configurable trailing slashes, strip_prefixes and automatic stage stripping
Parameters Bound from the signature: path, query (list[int] for repeated keys), headers (Header()), body (Pydantic model or Body()), Request injection, Annotated[..., Query(alias=…), Ge(1)]
Validation Built-in coercion for str/int/float/bool/Decimal/UUID/date/datetime/Enum/Literal/Optional/list (no Pydantic needed); Pydantic v2 models, constraints and response_model when installed. All errors are collected into one 422
Responses dict/list/scalars → JSON, str → text, bytes → base64 binary, None → 204, (body, status[, headers]) tuples, Response/JSONResponse, cookies, pluggable ResponseSerializer / envelope
Errors HTTPException hierarchy, @app.exception_handler(...), uniform JSON error body with request_id, no stack traces or exception messages leaked (opt-in debug), pluggable error_formatter
Middleware (request, call_next) -> Response, deterministic order, RequestLoggingMiddleware (structured, never logs bodies), SecurityHeadersMiddleware
Auth APIKeyAuth (constant-time), BearerAuth(verifier) (bring PyJWT or anything), custom providers, app/router/route level, public=True, authorize= → 403
CORS CORSConfig with exact/regex origins, credentials safety check, automatic preflight
Async async def handlers on a reused per-environment event loop
Testing lambroute.testing.TestClient + event builders for all three payload formats

Validation example

from pydantic import BaseModel, EmailStr
from lambroute import API

app = API(swagger=True)

class EmployeeCreate(BaseModel):
    name: str
    email: EmailStr
    department: str

@app.post("/employees", request_model=EmployeeCreate, status_code=201)
def create_employee(body: EmployeeCreate):
    return {"name": body.name, "email": body.email}

Invalid input yields:

{"error": {"code": "validation_error", "message": "Request validation failed",
  "details": [{"loc": ["body", "email"], "msg": "value is not a valid email address: ...", "type": "value_error"}],
  "request_id": "c6af9ac6-..."}}

Modular routers, auth and CORS

from lambroute import API, APIKeyAuth, BearerAuth, CORSConfig, Router

app = API(
    auth=BearerAuth(lambda token, request: verify_jwt(token)),   # default for all routes
    cors=CORSConfig(allow_origins=["https://app.example.com"]),
    swagger=True,
    docs_auth=APIKeyAuth(keys=["docs-secret"]),                 # protect /docs in prod
)

customers = Router(prefix="/customers", tags=["customers"])

@customers.get("/{customer_id}", authorize=lambda r: "read" in r.principal["scopes"])
def get_customer(customer_id: int):
    ...

@app.get("/health", public=True)
def health():
    return "ok"

app.include_router(customers)

Testing without AWS

from lambroute.testing import TestClient

client = TestClient(app)                          # HTTP API v2 events
assert client.get("/customers/1", headers={"Authorization": "Bearer t"}).status_code == 200
TestClient(app, event_format="rest")              # REST API proxy events
TestClient(app, event_format="http-v1")           # HTTP API payload 1.0

Configuration (environment)

Variable Default Effect
LAMBROUTE_DEBUG false Adds exception type/message (never tracebacks) to 500 bodies
LAMBROUTE_DOCS_ENABLED true false turns docs off even if swagger=True
LAMBROUTE_ENGINE auto native (require Rust), python (force fallback)

Performance

Routing runs in a Rust trie (PyO3) with exactly one Python→Rust call per request. On x86_64 / Python 3.13 it matches routes 3–5× faster than the identical pure-Python engine, flat from 10 to 10,000 routes (~0.15 µs static, ~0.4 µs dynamic). Because routing is a small part of a request, the full event→response pipeline is ~1.1–1.2× faster (≈9 µs vs ≈10 µs). Import plus API() is ≈35 ms with either engine. Full method and numbers: docs/benchmarks.md.

If no native wheel is available, lambroute falls back to the pure-Python engine (identical behaviour, verified by a randomized parity test) and logs a warning; set LAMBROUTE_ENGINE=native to fail fast instead.

Documentation

Development

python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"            # builds the Rust extension via maturin
maturin develop --release           # rebuild after Rust changes
cargo test -p lambroute-native    # Rust unit tests
pytest                              # Python + integration tests (both engines)
ruff check . && mypy                # lint + strict typing
python tests/benchmarks/bench_routing.py

License

MIT

Metadata

Release files for lambroute 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lambroute 0.1.0
File Size Uploaded Provenance Actions
lambroute-0.1.0.tar.gz 51.8 kB With provenance Details for lambroute-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for lambroute 0.1.0
File Actions
lambroute-0.1.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for lambroute-0.1.0-cp310-abi3-win_amd64.whl
lambroute-0.1.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for lambroute-0.1.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
lambroute-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for lambroute-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
lambroute-0.1.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for lambroute-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
lambroute-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for lambroute-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 1.3 MB

Release files / lambroute-0.1.0.tar.gz

Download URL lambroute-0.1.0.tar.gz
Size 51.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6ef2f069c0acec9aab913651d252150e00354f88a55b2cc51d45832e358921eb
BLAKE2b-256 checksum
How to use checksums
16b11b17541495acf8a79ea4513477496a8fea5ce4e277a19f5927c218e87bf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / lambroute-0.1.0-cp310-abi3-win_amd64.whl

Download URL lambroute-0.1.0-cp310-abi3-win_amd64.whl
Size 197.9 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
4a1415ec95a0aed239d4dd4fc0da5160f0e0e549a209acab6a121264da94633d
BLAKE2b-256 checksum
How to use checksums
57a227531cbf6db22ee178c0f9a13443766898668460744718e61f729304f0ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / lambroute-0.1.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL lambroute-0.1.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 282.7 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
c825b3fe626e561613c3edac3ed0e18a302dfd7781526a899a7d412eb3526c70
BLAKE2b-256 checksum
How to use checksums
2bebcb1f95be6bfd0bbeb14ecf9789fbb55dd4c2a5653c3cf49caf9d5b0340ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / lambroute-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL lambroute-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 272.7 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
8066e3882c58417c5aa153af173993f9c71aeb4ba7ec3905e28548328af93cc3
BLAKE2b-256 checksum
How to use checksums
f1d9e6a93501fd4228f42b9309182973215e936fdb60384dbc9a9615a98aa5ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / lambroute-0.1.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL lambroute-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Size 262.5 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4d367378b441bc9562d791c4aa87737e6f166a817d509ab55a0977239fb830a7
BLAKE2b-256 checksum
How to use checksums
42877a4814e6dbea276e5f3687f9294a6361f790d7ab8fc3e907ac43fa88525b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / lambroute-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL lambroute-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 275.3 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
9cc5d3fa88aef4133c276b5602e36fb3d3d556d695687decbc8f6c6b8ade478f
BLAKE2b-256 checksum
How to use checksums
3b1e2dfc3ee34c034b03d77cd312673edc12952a3d1f48e9585a1a5d8741ec91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Security for lambroute 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for lambroute-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page