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, a middleware system, and native partial batch failure.

PyPI version Status Python License: MIT

Documentation · 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.3.tar.gz (71.5 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.3-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file fastsqs-1.1.3.tar.gz.

File metadata

  • Download URL: fastsqs-1.1.3.tar.gz
  • Upload date:
  • Size: 71.5 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.3.tar.gz
Algorithm Hash digest
SHA256 dbcddec5f6f739eae59cdebee099fb84325d4120ba5d27878e47d35a1ef0d0b7
MD5 3d6cfe6ad48f488997a05fd7dcc291be
BLAKE2b-256 7cd29aa6fa28c1fa441d7f6d20f9aed4866016c34907a9c333a5d423bdbc3467

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastsqs-1.1.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: fastsqs-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 27.1 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eb8a8991d1586ee4a38b0b0eb693dc2eb086119138c6f7f4652d44fbed118624
MD5 6a57a49e11e9d51e4f6f428817231d7b
BLAKE2b-256 9ec8f2a8ce525dd5ad6b8c9ffb607758743761a0693bf3ac5c7f8890fcace4f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastsqs-1.1.3-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