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.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lambroute-0.1.4.tar.gz | 52.2 kB | With provenance | Details for lambroute-0.1.4.tar.gz |
Built distributions (wheels)
Total release size: 2.3 MB
Release files / lambroute-0.1.4.tar.gz
| Download URL | lambroute-0.1.4.tar.gz |
|---|---|
| Size | 52.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b91a94cbe437bb0597ddc8c648659ae8a27ede3e40879e66f747645ae9f2300c
|
|
BLAKE2b-256 checksum How to use checksums |
95b5af11fe4c333ac7da56283f20495f838a1729f26d01add953f522fbf44b31
|
| 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 logRelease files / lambroute-0.1.4-cp310-abi3-win_amd64.whl
| Download URL | lambroute-0.1.4-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 195.2 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8c153cd3a84472c666d53c127ababee79490db8ee1bf8e519fbad2ce8e1e0242
|
|
BLAKE2b-256 checksum How to use checksums |
43bd5bc09e16229ca1301baf2e295e61539ffe460c2f6b0b7aacd0ed94b65097
|
| 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 logRelease files / lambroute-0.1.4-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | lambroute-0.1.4-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 491.7 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f00ff189bf1985c4dd73abb454df7668e9fd6d597538f2c3a87933c60505ba47
|
|
BLAKE2b-256 checksum How to use checksums |
83e314071e300159013313ab68d0c8bda5e43f0ab3aa290c42ea10a181ce4af7
|
| 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 logRelease files / lambroute-0.1.4-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | lambroute-0.1.4-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 449.8 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
33fdb0da465bdc3fcff430c33f98efcbaa8bceb5dcb9156a6ac5bd0aeb93b796
|
|
BLAKE2b-256 checksum How to use checksums |
dc94b4555f2d3b7aa19bdc654360608219de1ebe9e77262a4825ae3c8809cc50
|
| 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 logRelease files / lambroute-0.1.4-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | lambroute-0.1.4-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 280.2 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d8e5252ce06674b883c0a30ee1f928e832c4018f9e803d89c55ba87f5234bf62
|
|
BLAKE2b-256 checksum How to use checksums |
498a75940f184ed7fac50447eeabbf0a68d2b7d21967b57ef15087d48314a26e
|
| 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 logRelease files / lambroute-0.1.4-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | lambroute-0.1.4-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 270.8 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
8d1ed5cb7fd2fbf271ca59b4879eb2d3c535deb6c1bdc3ecd805184ae3f4105a
|
|
BLAKE2b-256 checksum How to use checksums |
359a872b94b20728e9f85273f214a91e780953e7b47fc5b76058d74c49130531
|
| 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 logRelease files / lambroute-0.1.4-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | lambroute-0.1.4-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 262.2 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0852b51e65e80651d4df5a8489260a08b16ddd405beecc43871017c2286680f2
|
|
BLAKE2b-256 checksum How to use checksums |
a76e08e8d217ab7bebf5f3483526c54dc5baed9b5dbdf2c3a9e33c47a384cd7a
|
| 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 logRelease files / lambroute-0.1.4-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | lambroute-0.1.4-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 269.9 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
b1873b41efa4be3215826c851181e4e9e48aa17ff5b2474824502b3443d9250a
|
|
BLAKE2b-256 checksum How to use checksums |
a6ccbed4ed4cc1f5ece45fa9492a2c28b31f2ebd004f6cc4ae338dd9a36bbba8
|
| 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 logSecurity for lambroute 0.1.4
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.
Attestation for lambroute-0.1.4.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 logA 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.