FastSQS¶
The application object: register routes, attach routers and middleware, and handle Lambda events.
FastSQS ¶
Bases: RecordProcessingMixin
Main FastSQS application class for handling AWS SQS messages.
FastAPI-style interface for routing and processing SQS messages with support for middleware, validation, and concurrency. Record/batch processing lives in RecordProcessingMixin (processing.py).
route ¶
route(event_model: Type[SQSEvent], *, middlewares: Optional[List[Middleware]] = None) -> Callable[[Handler], Handler]
Register a route for a specific SQS event model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_model
|
Type[SQSEvent]
|
Pydantic model class for the event |
required |
middlewares
|
Optional[List[Middleware]]
|
Optional list of middlewares to apply |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[Handler], Handler]
|
Decorator function for the handler |
default ¶
Register a default handler for unmatched messages.
Returns:
| Type | Description |
|---|---|
Callable[[Handler], Handler]
|
Decorator function for the default handler |
include_router ¶
Include an external router in the application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
router
|
SQSRouter
|
SQSRouter instance to include |
required |
add_middleware ¶
Add a middleware to the application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
middleware
|
Middleware
|
Middleware instance to add |
required |
handler ¶
Main synchronous handler entry point for Lambda.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
dict | list
|
SQS event — |
required |
context
|
Any
|
Lambda context object |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with batch failure information |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called from within a running event loop |
async_handler
async
¶
Asynchronous handler entry point for testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
dict | list
|
SQS event — |
required |
context
|
Any
|
Lambda context object |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with batch failure information |