Metadata-Version: 2.4
Name: faststream-sqs-sns
Version: 0.1.0
Summary: Amazon SQS broker with SNS fan-out publishing for FastStream
Keywords: faststream,aws,sqs,sns,asyncio,messaging
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: System :: Distributed Computing
Classifier: Typing :: Typed
Requires-Dist: faststream>=0.7.8,<0.8
Requires-Dist: aiobotocore>=3.10,<4 ; extra == 'aiobotocore'
Requires-Dist: capo-sqs>=0.19,<0.20 ; extra == 'capo'
Requires-Dist: capo-sns>=0.20,<0.21 ; extra == 'capo'
Requires-Dist: zapros>=0.27,<0.28 ; extra == 'capo'
Requires-Dist: faststream[cli]>=0.7.8,<0.8 ; extra == 'cli'
Requires-Dist: faststream[otel]>=0.7.8,<0.8 ; extra == 'otel'
Requires-Dist: faststream[prometheus]>=0.7.8,<0.8 ; extra == 'prometheus'
Requires-Python: >=3.10
Project-URL: Homepage, https://github.com/powersemmi/faststream-sqs-sns
Project-URL: Source, https://github.com/powersemmi/faststream-sqs-sns
Project-URL: Tracker, https://github.com/powersemmi/faststream-sqs-sns/issues
Provides-Extra: aiobotocore
Provides-Extra: capo
Provides-Extra: cli
Provides-Extra: otel
Provides-Extra: prometheus
Description-Content-Type: text/markdown

# faststream-sqs-sns

<p align="center">
  <a href="https://github.com/powersemmi/faststream-sqs-sns/actions/workflows/ci.yaml"><img src="https://github.com/powersemmi/faststream-sqs-sns/actions/workflows/ci.yaml/badge.svg" alt="CI"></a>
  <a href="https://coveralls.io/github/powersemmi/faststream-sqs-sns?branch=main"><img src="https://coveralls.io/repos/github/powersemmi/faststream-sqs-sns/badge.svg?branch=main" alt="Coverage"></a>
  <a href="https://pypi.org/project/faststream-sqs-sns/"><img src="https://img.shields.io/pypi/v/faststream-sqs-sns.svg" alt="PyPI"></a>
  <a href="https://pypi.org/project/faststream-sqs-sns/"><img src="https://img.shields.io/pypi/dm/faststream-sqs-sns.svg" alt="Downloads"></a>
  <a href="https://pypi.org/project/faststream-sqs-sns/"><img src="https://img.shields.io/pypi/pyversions/faststream-sqs-sns.svg" alt="Supported Python versions"></a>
  <a href="https://github.com/powersemmi/faststream-sqs-sns/blob/main/LICENSE"><img src="https://img.shields.io/pypi/l/faststream-sqs-sns.svg" alt="License"></a>
</p>

An [Amazon SQS](https://aws.amazon.com/sqs/) broker for
[FastStream](https://github.com/ag2ai/faststream), with [SNS](https://aws.amazon.com/sns/)
fan-out publishing, maintained by the community.

Subscribers long-poll a queue and keep each message invisible until the handler settles it.
Publishers send to a queue or to an SNS topic, one message or a batch. Two clients sit behind
one shared core: `CapoSqsBroker` (capo) and `AiobotocoreSqsBroker` (aiobotocore). Handlers,
routers, tests and exceptions are the same for both.

## Install

Pick the client the broker talks to AWS with:

```shell
pip install "faststream-sqs-sns[capo]"
pip install "faststream-sqs-sns[aiobotocore]"
```

The package needs Python 3.10 or newer and FastStream 0.7. Other extras: `otel`
(OpenTelemetry), `prometheus` and `cli` (the `faststream` command). SSO profiles with capo need
`capo-sqs[sso]` and `capo-sns[sso]` next to the `capo` extra.

## With capo

```python
from faststream import FastStream
from pydantic import BaseModel

from faststream_sqs_sns import CapoSqsBroker, SnsTopic, SqsQueue


class Order(BaseModel):
    id: int
    amount: float


broker = CapoSqsBroker(region="eu-central-1")
app = FastStream(broker)

orders = SnsTopic("orders", declare=True)
shipments = broker.publisher("shipments")


@broker.subscriber(SqsQueue("orders-billing", declare=True), topic=orders)
@shipments
async def bill(order: Order) -> dict[str, int]:
    # the return value is sent to the `shipments` queue
    return {"order_id": order.id}


@app.after_startup
async def place_order() -> None:
    await broker.publish(Order(id=1, amount=9.5), orders)
```

```shell
faststream run service:app
```

The handler reads the `orders-billing` queue, which the broker subscribes to the `orders` topic,
decodes the JSON body into `Order`, deletes the message once the handler returns, and sends its
result to the `shipments` queue.

## With aiobotocore

```python
import logging

from faststream import FastStream

from faststream_sqs_sns import AiobotocoreSqsBroker, SqsQueue

# the same handlers run on either backend: only the class of the broker changes
broker = AiobotocoreSqsBroker(region="eu-central-1")
app = FastStream(broker)
logger = logging.getLogger(__name__)


@broker.subscriber(SqsQueue("orders", declare=True))
async def bill(order: dict[str, int]) -> None:
    logger.info("billing order %s", order["id"])
```

## Testing

`TestSqsBroker` runs the service in process, with the limits of the real service:

```python
async with TestSqsBroker(broker) as br:
    await br.publish(Order(id=1, amount=9.5), "orders")

    bill.mock.assert_called_once_with({"id": 1, "amount": 9.5})
```

## Documentation

- [Getting started](https://powersemmi.github.io/faststream-sqs-sns/getting-started/)
- [Choosing a backend](https://powersemmi.github.io/faststream-sqs-sns/choosing-a-backend/)
- [LocalStack and credentials](https://powersemmi.github.io/faststream-sqs-sns/localstack-and-credentials/)
- [Queues and topics](https://powersemmi.github.io/faststream-sqs-sns/queues-and-topics/)
- [Declaring resources](https://powersemmi.github.io/faststream-sqs-sns/declaring-resources/)
- [Publishing](https://powersemmi.github.io/faststream-sqs-sns/publishing/)
- [Consuming](https://powersemmi.github.io/faststream-sqs-sns/consuming/)
- [Visibility and flow control](https://powersemmi.github.io/faststream-sqs-sns/visibility-and-flow-control/)
- [FIFO queues](https://powersemmi.github.io/faststream-sqs-sns/fifo-queues/)
- [Testing](https://powersemmi.github.io/faststream-sqs-sns/testing/)
- [FastAPI](https://powersemmi.github.io/faststream-sqs-sns/fastapi/),
  [Observability](https://powersemmi.github.io/faststream-sqs-sns/observability/) and
  [AsyncAPI](https://powersemmi.github.io/faststream-sqs-sns/asyncapi/)
- [API reference](https://powersemmi.github.io/faststream-sqs-sns/api/)

## Development

See [CONTRIBUTING.md](CONTRIBUTING.md). The source lives at
<https://github.com/powersemmi/faststream-sqs-sns>.

## License

Apache License 2.0.
