A FastAPI-style router for AWS SQS on Lambda: pydantic routing, dependency injection, middleware, and native partial batch failure.
Project description
FastSQS
A FastAPI-style router for AWS SQS on Lambda
Pydantic routing · dependency injection · middleware · native partial batch failure
Documentation · Quickstart · Changelog · Source · Issues
FastSQS turns an SQS-triggered Lambda into a typed, declarative app. You write
handlers for pydantic event models; FastSQS parses each record, routes it,
validates it, runs your middleware, and returns the batchItemFailures SQS
expects, so failed messages are redelivered and dead-lettered by the queue's
own redrive policy, not by bespoke in-app code.
Features
- FastAPI-style routing:
@app.route(OrderCreated)dispatches by a payload discriminator (default key"type"). - Pydantic validation: handlers receive a validated
SQSEventmodel; bad messages become clean batch failures. - Dependency injection: declare
Depends(...)params (powered byfast-depends); no@injectneeded. - Typed
Context:ctx.message_id,ctx.queue_type, and more as typed attributes; arbitrary scratch inctx.state. - Middleware:
before/afterhooks with balanced unwind (resources acquired inbeforeare always released). - Partial batch failure: native
ReportBatchItemFailuresfor standard and FIFO queues. - FIFO-aware: queue type is inferred from the event-source ARN; per-group ordering with a configurable failure mode.
- EventBridge Pipes ready:
app.handleraccepts both the Lambda{"Records": [...]}envelope and a bare list of records. - Shape detection:
is_sqs_event(event)lets one Lambda multiplex SQS and non-SQS (e.g. API Gateway) events. - In-process test client: drive your app with synthetic events, no AWS required.
- Typed: ships
py.typed; full editor and mypy support.
Install
pip install fastsqs
Requires Python 3.10+. Depends on pydantic>=2 and fast-depends>=3,<4.
Quick start
from fastsqs import FastSQS, SQSEvent
app = FastSQS() # queue type auto-detected from the event-source ARN
class OrderCreated(SQSEvent):
order_id: str
amount: int
@app.route(OrderCreated)
async def handle_order(msg: OrderCreated):
print("processing", msg.order_id, msg.amount)
# raising marks this record as failed -> SQS redelivers it
# Lambda entry point (set as the function handler):
def handler(event, context):
return app.handler(event, context)
A message routes by its discriminator value ("type" by default), matched to
the event model's name in snake_case, so {"type": "order_created", ...} routes
to OrderCreated. Field names accept both snake_case and their camelCase
aliases via Pydantic alias generation.
Why fastsqs
Reach for fastsqs when a queue carries many message types and you would
otherwise branch by hand in one large handler. It gives you correct
ReportBatchItemFailures together with the FastAPI model on top: route by type,
validate with pydantic, inject dependencies, and read a typed Context. For a
single trivial handler with no validation, a plain boto3 loop is still fine.
Documentation
Full documentation, including guides, concepts, and the API reference: fastsqs.github.io
- Quickstart
- Guide — routing, dependency injection, middleware, FIFO, testing
- Concepts — how routing, the batch lifecycle, and partial batch failure work
- API Reference
Contributing
Issues and pull requests are welcome. See CONTRIBUTING.md for dev setup, and the Code of Conduct. Open an issue to discuss anything non-trivial first.
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastsqs-1.1.4.tar.gz.
File metadata
- Download URL: fastsqs-1.1.4.tar.gz
- Upload date:
- Size: 72.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
005be167b0ed0d3c7d113097144dcb9e6141864e67942016dcd8d1d72a65bf77
|
|
| MD5 |
8cfa810634761c0daa5187f738a4f070
|
|
| BLAKE2b-256 |
be9cef21166bf25184977571aa338669ce23cd4f08ca0b7f3c7da6023f251d89
|
Provenance
The following attestation bundles were made for fastsqs-1.1.4.tar.gz:
Publisher:
release.yml on fastsqs/fastsqs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastsqs-1.1.4.tar.gz -
Subject digest:
005be167b0ed0d3c7d113097144dcb9e6141864e67942016dcd8d1d72a65bf77 - Sigstore transparency entry: 1920450685
- Sigstore integration time:
-
Permalink:
fastsqs/fastsqs@a77ccc7618df173e4a82f91b840451d695dd0a0d -
Branch / Tag:
refs/tags/v1.1.4 - Owner: https://github.com/fastsqs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a77ccc7618df173e4a82f91b840451d695dd0a0d -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastsqs-1.1.4-py3-none-any.whl.
File metadata
- Download URL: fastsqs-1.1.4-py3-none-any.whl
- Upload date:
- Size: 27.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a86de608fefbb19f5d4106ce0b15623105eb32204d5fd5859b1ab1b6d1d65c64
|
|
| MD5 |
f8e50ae14b048cc08410d5688ba4e935
|
|
| BLAKE2b-256 |
63eae669ee5aecb2467f23aafba66e4142c229552a1f61add8ef449710aec721
|
Provenance
The following attestation bundles were made for fastsqs-1.1.4-py3-none-any.whl:
Publisher:
release.yml on fastsqs/fastsqs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastsqs-1.1.4-py3-none-any.whl -
Subject digest:
a86de608fefbb19f5d4106ce0b15623105eb32204d5fd5859b1ab1b6d1d65c64 - Sigstore transparency entry: 1920450873
- Sigstore integration time:
-
Permalink:
fastsqs/fastsqs@a77ccc7618df173e4a82f91b840451d695dd0a0d -
Branch / Tag:
refs/tags/v1.1.4 - Owner: https://github.com/fastsqs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a77ccc7618df173e4a82f91b840451d695dd0a0d -
Trigger Event:
push
-
Statement type: