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.3

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.3
File Size Uploaded Provenance Actions
lambroute-0.1.3.tar.gz 52.6 kB With provenance Details for lambroute-0.1.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for lambroute 0.1.3
File Actions
lambroute-0.1.3-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for lambroute-0.1.3-cp310-abi3-win_amd64.whl
lambroute-0.1.3-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for lambroute-0.1.3-cp310-abi3-musllinux_1_2_x86_64.whl
lambroute-0.1.3-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for lambroute-0.1.3-cp310-abi3-musllinux_1_2_aarch64.whl
lambroute-0.1.3-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.3-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
lambroute-0.1.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for lambroute-0.1.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
lambroute-0.1.3-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for lambroute-0.1.3-cp310-abi3-macosx_11_0_arm64.whl
lambroute-0.1.3-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for lambroute-0.1.3-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 2.3 MB

Release files / lambroute-0.1.3.tar.gz

Download URL lambroute-0.1.3.tar.gz
Size 52.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d121334e19df93eb356a8c23f07ba1d998a7560168d882ac7178564392779067
BLAKE2b-256 checksum
How to use checksums
bfea85f0ce9dbe0f2e74b8ca926d1d58a60fcbb824cd165742d32db0ef75855b
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.3-cp310-abi3-win_amd64.whl

Download URL lambroute-0.1.3-cp310-abi3-win_amd64.whl
Size 198.6 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
617cc0d29e11553ffb62a7ee82e0e83f669568d4459173bce6b385b89521dff9
BLAKE2b-256 checksum
How to use checksums
8eef44355b2a2226b0701c5818b1063129073b2af8c4b75c14903cb12a465c89
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.3-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL lambroute-0.1.3-cp310-abi3-musllinux_1_2_x86_64.whl
Size 494.8 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
3f59c2a8f43464d47755a1a1765dd3f1cee29fae71d0b30b9d1a3d880f83c486
BLAKE2b-256 checksum
How to use checksums
b97103a5547f833e49f5e582e2328e31a22545aeb62e65829ac6b7e1a63157d5
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.3-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL lambroute-0.1.3-cp310-abi3-musllinux_1_2_aarch64.whl
Size 452.0 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
1b4e862cd2f69ae1e5403821392b9076a2592c3d78cf62d72405736873401bef
BLAKE2b-256 checksum
How to use checksums
e482766c0a59f3d1d025dc4577856b8f0bfd59c57f50275263b63aa69ff39863
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.3-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL lambroute-0.1.3-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 282.9 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
715c3c99c9872253153d63ca0ee0db8acb845b7e048569d04b9a8fc13d364c39
BLAKE2b-256 checksum
How to use checksums
a0cb0ac50fe054250fad970a113e54c17e24efdca28035b86079dd4e81899196
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.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL lambroute-0.1.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 273.1 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
d36a11ebef352e6dc76feba4f2e302345e9b4ea064bee64bfa68aa34171f2c67
BLAKE2b-256 checksum
How to use checksums
d8d85d7da2abee8346c0fbefd0c4bc3366d013f2b4f01718aa9d89044728c19d
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.3-cp310-abi3-macosx_11_0_arm64.whl

Download URL lambroute-0.1.3-cp310-abi3-macosx_11_0_arm64.whl
Size 262.8 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e4daffc754fd2f4f116d0f3091921a518ed25f6fc69423fed5849a6bf0b42f79
BLAKE2b-256 checksum
How to use checksums
1fa45e56f0f1524e7820e8c845c2f9f7228901b9e90903cb271b093b01761bb6
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.3-cp310-abi3-macosx_10_12_x86_64.whl

Download URL lambroute-0.1.3-cp310-abi3-macosx_10_12_x86_64.whl
Size 275.5 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f4622d6bc111c15ad9066614017d0b5b526ff6538c6a5de76986d71d33b5df00
BLAKE2b-256 checksum
How to use checksums
44e8cf41292f511f433ea57001055c2c886d0903270d2f2a407e939f09aec6af
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.3

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 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for lambroute-0.1.3.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