Skip to main content

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.
  • Standard envelopes: opt-in CloudEvent[T] base (CloudEvents 1.0), dot-path discriminators for metadata+data envelopes, and __message_type__ for namespaced/versioned route keys (com.acme.payment.approved.v1).
  • 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).
  • Idempotency: IdempotencyMiddleware dedups at-least-once delivery behind a structural IdempotencyStore protocol (in-memory store included); raise SkipMessage anywhere to ack a record without processing.
  • Tracing: TracingMiddleware reads W3C traceparent from message attributes into a typed ctx.state.trace.
  • 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.

Metadata

Release files for fastsqs 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastsqs 1.2.0
File Size Uploaded
fastsqs-1.2.0.tar.gz 86.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastsqs 1.2.0
File Interpreter ABI Platform
fastsqs-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 120.1 kB

Release files / fastsqs-1.2.0.tar.gz

Download URL fastsqs-1.2.0.tar.gz
Size 86.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3f93e0edf4eed0f632453af16c0a05108034d8aad7c41e481a7a035002daf5ff
BLAKE2b-256 checksum
How to use checksums
7e9e0237b7b3365954781faa497bf9abba47c271398d6fd6f7630cb49c13d6dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 17, 2026.

Transparency log

Release files / fastsqs-1.2.0-py3-none-any.whl

Download URL fastsqs-1.2.0-py3-none-any.whl
Size 34.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49942143b12dbe9ce2f97461be2ff8ff7c2d7bf14e7cbadea182c55d80515286
BLAKE2b-256 checksum
How to use checksums
bf5c6e0b7a7d55ae781b7543a6b0d0943040540c9aaab49faf9630d2c19f1635
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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