Skip to main content

FastAPI-like, modern async SQS message processing for Python with advanced features

Project description

FastSQS

FastAPI-like, production-ready async SQS message processing for Python.

PyPI version License: MIT


Version 0.3.0 - Production Ready Features

⚠️ Pre-1.0 Release Warning: This library is under active development. Breaking changes may occur until version 1.0.0. Pin your version in production.

🚀 New Enterprise Features

  • Idempotency: Prevent duplicate message processing with memory or DynamoDB storage
  • Advanced Error Handling: Exponential backoff, circuit breaker, and DLQ management
  • Visibility Timeout Management: Automatic monitoring and extension for long-running processes
  • Parallelization: Concurrent processing with semaphore-based limiting and thread pools

Recent Updates

Version 0.3.2

  • Auto DynamoDB Table Creation: DynamoDB idempotency store now automatically creates tables with proper schema and TTL configuration
  • Enhanced Table Management: Improved error handling and race condition protection for table operations

Version 0.3.1

  • Idempotency Improvements: Enhanced DynamoDB store reliability and error handling
  • Bug Fixes: Various stability improvements and edge case handling

Key Features

  • 🚀 FastAPI-like API: Familiar decorator-based routing with automatic type inference
  • 🔒 Pydantic Validation: Automatic message validation and serialization using SQSEvent models
  • 🔄 Auto Async/Sync: Write handlers as sync or async functions - framework handles both automatically
  • �️ Middleware Support: Built-in and custom middleware for logging, timing, and more
  • 🦾 Partial Batch Failure: Native support for AWS Lambda batch failure responses
  • 🔀 FIFO & Standard Queues: Full support for both SQS queue types with proper ordering
  • 🎯 Flexible Matching: Automatic field name normalization (camelCase ↔ snake_case)
  • 🏗️ Nested Routing: QueueRouter support for complex routing scenarios
  • 🐍 Type Safety: Full type hints and editor support throughout

Requirements

  • Python 3.8+
  • Pydantic (installed automatically)

Installation

pip install fastsqs

Quick Start

Basic FastAPI-like Example

from fastsqs import FastSQS, SQSEvent

class UserCreated(SQSEvent):
    user_id: str
    email: str
    name: str

class OrderProcessed(SQSEvent):
    order_id: str
    amount: float

# Create FastSQS app
app = FastSQS(debug=True)

# Route messages using SQSEvent models
@app.route(UserCreated)
async def handle_user_created(msg: UserCreated):
    print(f"User created: {msg.name} ({msg.email})")

@app.route(OrderProcessed)
def handle_order_processed(msg: OrderProcessed):
    print(f"Order {msg.order_id}: ${msg.amount}")

# Default handler for unmatched messages
@app.default()
def handle_unknown(payload, ctx):
    print(f"Unknown message: {payload}")

# AWS Lambda handler
def lambda_handler(event, context):
    return app.handler(event, context)

Example SQS Message Payloads

{
  "type": "user_created",
  "user_id": "123",
  "email": "user@example.com",
  "name": "John Doe"
}
{
  "type": "order_processed",
  "order_id": "ord-456",
  "amount": 99.99
}

Advanced Features

# FIFO Queue Support
app = FastSQS(queue_type=QueueType.FIFO)

# Middleware
from fastsqs.middleware import TimingMiddleware, LoggingMiddleware
app.add_middleware(TimingMiddleware())
app.add_middleware(LoggingMiddleware())

# Field Matching - automatically handles camelCase ↔ snake_case
class UserEvent(SQSEvent):
    user_id: str  # Matches: user_id, userId, USER_ID
    first_name: str  # Matches: first_name, firstName

How it Works

  1. Message Parsing: JSON validated and normalized
  2. Route Matching: Type-based routing to handlers
  3. Handler Execution: Sync/async functions supported
  4. Error Handling: Failed messages → SQS retry/DLQ

Error Handling & Performance

  • Predictable Errors: All failures result in batch item failures for SQS retry
  • Parallel Processing: Concurrent message handling (respects FIFO ordering)
  • Type Safety: Full Pydantic validation with IDE support
  • Memory Efficient: Minimal overhead per message

Documentation & Contributing

  • Examples: See examples/ directory for complete working examples
  • Contributing: Issues and PRs welcome!
  • License: MIT

Ready to build type-safe, FastAPI-like SQS processors? Try FastSQS today!

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-0.3.2.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

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

fastsqs-0.3.2-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastsqs-0.3.2.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for fastsqs-0.3.2.tar.gz
Algorithm Hash digest
SHA256 4f7b2708671b4577f82f5051729b5fb374e03846ec55ec297b458bbbcdbee2ec
MD5 a2e92b88faad9b524dbed8a668c6d493
BLAKE2b-256 9b3b5ae1b051167c4af5bfaae706654863f49dd2a16f8cd0f1b5f2879398d00d

See more details on using hashes here.

File details

Details for the file fastsqs-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: fastsqs-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for fastsqs-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 691686b800f407b2921a9975cc840a0851642385db769dce745e5cef991b8ade
MD5 4616833ffad74dda6cf5733a92d9396f
BLAKE2b-256 7f498cde7b17a33894ef7bb31919b6f0ea8fcf6482b84f9fa9ec77b8b727b624

See more details on using hashes here.

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