Skip to main content

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

PyPI version Supported Python versions Downloads per month License: MIT Docs build Contributor Covenant 2.1

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 SQSEvent model; bad messages become clean batch failures.
  • Dependency injection: declare Depends(...) params (powered by fast-depends); no @inject needed.
  • Typed Context: ctx.message_id, ctx.queue_type, and more as typed attributes; arbitrary scratch in ctx.state.
  • Middleware: before/after hooks with balanced unwind (resources acquired in before are always released).
  • Partial batch failure: native ReportBatchItemFailures for 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.handler accepts 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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastsqs-1.1.4.tar.gz (72.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastsqs-1.1.4-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

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

Hashes for fastsqs-1.1.4.tar.gz
Algorithm Hash digest
SHA256 005be167b0ed0d3c7d113097144dcb9e6141864e67942016dcd8d1d72a65bf77
MD5 8cfa810634761c0daa5187f738a4f070
BLAKE2b-256 be9cef21166bf25184977571aa338669ce23cd4f08ca0b7f3c7da6023f251d89

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastsqs-1.1.4.tar.gz:

Publisher: release.yml on fastsqs/fastsqs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for fastsqs-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a86de608fefbb19f5d4106ce0b15623105eb32204d5fd5859b1ab1b6d1d65c64
MD5 f8e50ae14b048cc08410d5688ba4e935
BLAKE2b-256 63eae669ee5aecb2467f23aafba66e4142c229552a1f61add8ef449710aec721

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastsqs-1.1.4-py3-none-any.whl:

Publisher: release.yml on fastsqs/fastsqs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page