faststream-sqs-sns 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. faststream_sqs_sns-0.1.0/LICENSE +201 -0
  2. faststream_sqs_sns-0.1.0/PKG-INFO +168 -0
  3. faststream_sqs_sns-0.1.0/README.md +130 -0
  4. faststream_sqs_sns-0.1.0/faststream_sqs_sns/__init__.py +53 -0
  5. faststream_sqs_sns-0.1.0/faststream_sqs_sns/_transport/__init__.py +230 -0
  6. faststream_sqs_sns-0.1.0/faststream_sqs_sns/_transport/aiobotocore.py +455 -0
  7. faststream_sqs_sns-0.1.0/faststream_sqs_sns/_transport/capo.py +451 -0
  8. faststream_sqs_sns-0.1.0/faststream_sqs_sns/annotations.py +24 -0
  9. faststream_sqs_sns-0.1.0/faststream_sqs_sns/broker/__init__.py +0 -0
  10. faststream_sqs_sns-0.1.0/faststream_sqs_sns/broker/aiobotocore.py +46 -0
  11. faststream_sqs_sns-0.1.0/faststream_sqs_sns/broker/capo.py +49 -0
  12. faststream_sqs_sns-0.1.0/faststream_sqs_sns/broker/config.py +49 -0
  13. faststream_sqs_sns-0.1.0/faststream_sqs_sns/broker/core.py +404 -0
  14. faststream_sqs_sns-0.1.0/faststream_sqs_sns/broker/logging.py +53 -0
  15. faststream_sqs_sns-0.1.0/faststream_sqs_sns/broker/registrator.py +221 -0
  16. faststream_sqs_sns-0.1.0/faststream_sqs_sns/broker/router.py +134 -0
  17. faststream_sqs_sns-0.1.0/faststream_sqs_sns/declare.py +173 -0
  18. faststream_sqs_sns-0.1.0/faststream_sqs_sns/encoding.py +123 -0
  19. faststream_sqs_sns-0.1.0/faststream_sqs_sns/exceptions.py +108 -0
  20. faststream_sqs_sns-0.1.0/faststream_sqs_sns/fastapi/__init__.py +47 -0
  21. faststream_sqs_sns-0.1.0/faststream_sqs_sns/fastapi/aiobotocore.py +42 -0
  22. faststream_sqs_sns-0.1.0/faststream_sqs_sns/fastapi/capo.py +44 -0
  23. faststream_sqs_sns-0.1.0/faststream_sqs_sns/fastapi/fastapi.py +303 -0
  24. faststream_sqs_sns-0.1.0/faststream_sqs_sns/limits.py +268 -0
  25. faststream_sqs_sns-0.1.0/faststream_sqs_sns/message.py +176 -0
  26. faststream_sqs_sns-0.1.0/faststream_sqs_sns/opentelemetry/__init__.py +3 -0
  27. faststream_sqs_sns-0.1.0/faststream_sqs_sns/opentelemetry/middleware.py +28 -0
  28. faststream_sqs_sns-0.1.0/faststream_sqs_sns/opentelemetry/provider.py +89 -0
  29. faststream_sqs_sns-0.1.0/faststream_sqs_sns/parser.py +84 -0
  30. faststream_sqs_sns-0.1.0/faststream_sqs_sns/prometheus/__init__.py +3 -0
  31. faststream_sqs_sns-0.1.0/faststream_sqs_sns/prometheus/middleware.py +38 -0
  32. faststream_sqs_sns-0.1.0/faststream_sqs_sns/prometheus/provider.py +44 -0
  33. faststream_sqs_sns-0.1.0/faststream_sqs_sns/publisher/__init__.py +0 -0
  34. faststream_sqs_sns-0.1.0/faststream_sqs_sns/publisher/config.py +24 -0
  35. faststream_sqs_sns-0.1.0/faststream_sqs_sns/publisher/factory.py +47 -0
  36. faststream_sqs_sns-0.1.0/faststream_sqs_sns/publisher/fake.py +33 -0
  37. faststream_sqs_sns-0.1.0/faststream_sqs_sns/publisher/producer.py +210 -0
  38. faststream_sqs_sns-0.1.0/faststream_sqs_sns/publisher/specification.py +71 -0
  39. faststream_sqs_sns-0.1.0/faststream_sqs_sns/publisher/usecase.py +233 -0
  40. faststream_sqs_sns-0.1.0/faststream_sqs_sns/py.typed +0 -0
  41. faststream_sqs_sns-0.1.0/faststream_sqs_sns/response.py +150 -0
  42. faststream_sqs_sns-0.1.0/faststream_sqs_sns/schemas.py +309 -0
  43. faststream_sqs_sns-0.1.0/faststream_sqs_sns/security.py +63 -0
  44. faststream_sqs_sns-0.1.0/faststream_sqs_sns/subscriber/__init__.py +0 -0
  45. faststream_sqs_sns-0.1.0/faststream_sqs_sns/subscriber/config.py +39 -0
  46. faststream_sqs_sns-0.1.0/faststream_sqs_sns/subscriber/factory.py +85 -0
  47. faststream_sqs_sns-0.1.0/faststream_sqs_sns/subscriber/settler.py +338 -0
  48. faststream_sqs_sns-0.1.0/faststream_sqs_sns/subscriber/specification.py +105 -0
  49. faststream_sqs_sns-0.1.0/faststream_sqs_sns/subscriber/usecase.py +532 -0
  50. faststream_sqs_sns-0.1.0/faststream_sqs_sns/testing.py +461 -0
  51. faststream_sqs_sns-0.1.0/pyproject.toml +171 -0
  52. faststream_sqs_sns-0.1.0/pyproject.toml.orig +170 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2026 onwards] AG2AI, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.4
2
+ Name: faststream-sqs-sns
3
+ Version: 0.1.0
4
+ Summary: Amazon SQS broker with SNS fan-out publishing for FastStream
5
+ Keywords: faststream,aws,sqs,sns,asyncio,messaging
6
+ License-Expression: Apache-2.0
7
+ License-File: LICENSE
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Framework :: AsyncIO
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: System :: Distributed Computing
19
+ Classifier: Typing :: Typed
20
+ Requires-Dist: faststream>=0.7.8,<0.8
21
+ Requires-Dist: aiobotocore>=3.10,<4 ; extra == 'aiobotocore'
22
+ Requires-Dist: capo-sqs>=0.19,<0.20 ; extra == 'capo'
23
+ Requires-Dist: capo-sns>=0.20,<0.21 ; extra == 'capo'
24
+ Requires-Dist: zapros>=0.27,<0.28 ; extra == 'capo'
25
+ Requires-Dist: faststream[cli]>=0.7.8,<0.8 ; extra == 'cli'
26
+ Requires-Dist: faststream[otel]>=0.7.8,<0.8 ; extra == 'otel'
27
+ Requires-Dist: faststream[prometheus]>=0.7.8,<0.8 ; extra == 'prometheus'
28
+ Requires-Python: >=3.10
29
+ Project-URL: Homepage, https://github.com/powersemmi/faststream-sqs-sns
30
+ Project-URL: Source, https://github.com/powersemmi/faststream-sqs-sns
31
+ Project-URL: Tracker, https://github.com/powersemmi/faststream-sqs-sns/issues
32
+ Provides-Extra: aiobotocore
33
+ Provides-Extra: capo
34
+ Provides-Extra: cli
35
+ Provides-Extra: otel
36
+ Provides-Extra: prometheus
37
+ Description-Content-Type: text/markdown
38
+
39
+ # faststream-sqs-sns
40
+
41
+ <p align="center">
42
+ <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>
43
+ <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>
44
+ <a href="https://pypi.org/project/faststream-sqs-sns/"><img src="https://img.shields.io/pypi/v/faststream-sqs-sns.svg" alt="PyPI"></a>
45
+ <a href="https://pypi.org/project/faststream-sqs-sns/"><img src="https://img.shields.io/pypi/dm/faststream-sqs-sns.svg" alt="Downloads"></a>
46
+ <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>
47
+ <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>
48
+ </p>
49
+
50
+ An [Amazon SQS](https://aws.amazon.com/sqs/) broker for
51
+ [FastStream](https://github.com/ag2ai/faststream), with [SNS](https://aws.amazon.com/sns/)
52
+ fan-out publishing, maintained by the community.
53
+
54
+ Subscribers long-poll a queue and keep each message invisible until the handler settles it.
55
+ Publishers send to a queue or to an SNS topic, one message or a batch. Two clients sit behind
56
+ one shared core: `CapoSqsBroker` (capo) and `AiobotocoreSqsBroker` (aiobotocore). Handlers,
57
+ routers, tests and exceptions are the same for both.
58
+
59
+ ## Install
60
+
61
+ Pick the client the broker talks to AWS with:
62
+
63
+ ```shell
64
+ pip install "faststream-sqs-sns[capo]"
65
+ pip install "faststream-sqs-sns[aiobotocore]"
66
+ ```
67
+
68
+ The package needs Python 3.10 or newer and FastStream 0.7. Other extras: `otel`
69
+ (OpenTelemetry), `prometheus` and `cli` (the `faststream` command). SSO profiles with capo need
70
+ `capo-sqs[sso]` and `capo-sns[sso]` next to the `capo` extra.
71
+
72
+ ## With capo
73
+
74
+ ```python
75
+ from faststream import FastStream
76
+ from pydantic import BaseModel
77
+
78
+ from faststream_sqs_sns import CapoSqsBroker, SnsTopic, SqsQueue
79
+
80
+
81
+ class Order(BaseModel):
82
+ id: int
83
+ amount: float
84
+
85
+
86
+ broker = CapoSqsBroker(region="eu-central-1")
87
+ app = FastStream(broker)
88
+
89
+ orders = SnsTopic("orders", declare=True)
90
+ shipments = broker.publisher("shipments")
91
+
92
+
93
+ @broker.subscriber(SqsQueue("orders-billing", declare=True), topic=orders)
94
+ @shipments
95
+ async def bill(order: Order) -> dict[str, int]:
96
+ # the return value is sent to the `shipments` queue
97
+ return {"order_id": order.id}
98
+
99
+
100
+ @app.after_startup
101
+ async def place_order() -> None:
102
+ await broker.publish(Order(id=1, amount=9.5), orders)
103
+ ```
104
+
105
+ ```shell
106
+ faststream run service:app
107
+ ```
108
+
109
+ The handler reads the `orders-billing` queue, which the broker subscribes to the `orders` topic,
110
+ decodes the JSON body into `Order`, deletes the message once the handler returns, and sends its
111
+ result to the `shipments` queue.
112
+
113
+ ## With aiobotocore
114
+
115
+ ```python
116
+ import logging
117
+
118
+ from faststream import FastStream
119
+
120
+ from faststream_sqs_sns import AiobotocoreSqsBroker, SqsQueue
121
+
122
+ # the same handlers run on either backend: only the class of the broker changes
123
+ broker = AiobotocoreSqsBroker(region="eu-central-1")
124
+ app = FastStream(broker)
125
+ logger = logging.getLogger(__name__)
126
+
127
+
128
+ @broker.subscriber(SqsQueue("orders", declare=True))
129
+ async def bill(order: dict[str, int]) -> None:
130
+ logger.info("billing order %s", order["id"])
131
+ ```
132
+
133
+ ## Testing
134
+
135
+ `TestSqsBroker` runs the service in process, with the limits of the real service:
136
+
137
+ ```python
138
+ async with TestSqsBroker(broker) as br:
139
+ await br.publish(Order(id=1, amount=9.5), "orders")
140
+
141
+ bill.mock.assert_called_once_with({"id": 1, "amount": 9.5})
142
+ ```
143
+
144
+ ## Documentation
145
+
146
+ - [Getting started](https://powersemmi.github.io/faststream-sqs-sns/getting-started/)
147
+ - [Choosing a backend](https://powersemmi.github.io/faststream-sqs-sns/choosing-a-backend/)
148
+ - [LocalStack and credentials](https://powersemmi.github.io/faststream-sqs-sns/localstack-and-credentials/)
149
+ - [Queues and topics](https://powersemmi.github.io/faststream-sqs-sns/queues-and-topics/)
150
+ - [Declaring resources](https://powersemmi.github.io/faststream-sqs-sns/declaring-resources/)
151
+ - [Publishing](https://powersemmi.github.io/faststream-sqs-sns/publishing/)
152
+ - [Consuming](https://powersemmi.github.io/faststream-sqs-sns/consuming/)
153
+ - [Visibility and flow control](https://powersemmi.github.io/faststream-sqs-sns/visibility-and-flow-control/)
154
+ - [FIFO queues](https://powersemmi.github.io/faststream-sqs-sns/fifo-queues/)
155
+ - [Testing](https://powersemmi.github.io/faststream-sqs-sns/testing/)
156
+ - [FastAPI](https://powersemmi.github.io/faststream-sqs-sns/fastapi/),
157
+ [Observability](https://powersemmi.github.io/faststream-sqs-sns/observability/) and
158
+ [AsyncAPI](https://powersemmi.github.io/faststream-sqs-sns/asyncapi/)
159
+ - [API reference](https://powersemmi.github.io/faststream-sqs-sns/api/)
160
+
161
+ ## Development
162
+
163
+ See [CONTRIBUTING.md](CONTRIBUTING.md). The source lives at
164
+ <https://github.com/powersemmi/faststream-sqs-sns>.
165
+
166
+ ## License
167
+
168
+ Apache License 2.0.
@@ -0,0 +1,130 @@
1
+ # faststream-sqs-sns
2
+
3
+ <p align="center">
4
+ <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>
5
+ <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>
6
+ <a href="https://pypi.org/project/faststream-sqs-sns/"><img src="https://img.shields.io/pypi/v/faststream-sqs-sns.svg" alt="PyPI"></a>
7
+ <a href="https://pypi.org/project/faststream-sqs-sns/"><img src="https://img.shields.io/pypi/dm/faststream-sqs-sns.svg" alt="Downloads"></a>
8
+ <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>
9
+ <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>
10
+ </p>
11
+
12
+ An [Amazon SQS](https://aws.amazon.com/sqs/) broker for
13
+ [FastStream](https://github.com/ag2ai/faststream), with [SNS](https://aws.amazon.com/sns/)
14
+ fan-out publishing, maintained by the community.
15
+
16
+ Subscribers long-poll a queue and keep each message invisible until the handler settles it.
17
+ Publishers send to a queue or to an SNS topic, one message or a batch. Two clients sit behind
18
+ one shared core: `CapoSqsBroker` (capo) and `AiobotocoreSqsBroker` (aiobotocore). Handlers,
19
+ routers, tests and exceptions are the same for both.
20
+
21
+ ## Install
22
+
23
+ Pick the client the broker talks to AWS with:
24
+
25
+ ```shell
26
+ pip install "faststream-sqs-sns[capo]"
27
+ pip install "faststream-sqs-sns[aiobotocore]"
28
+ ```
29
+
30
+ The package needs Python 3.10 or newer and FastStream 0.7. Other extras: `otel`
31
+ (OpenTelemetry), `prometheus` and `cli` (the `faststream` command). SSO profiles with capo need
32
+ `capo-sqs[sso]` and `capo-sns[sso]` next to the `capo` extra.
33
+
34
+ ## With capo
35
+
36
+ ```python
37
+ from faststream import FastStream
38
+ from pydantic import BaseModel
39
+
40
+ from faststream_sqs_sns import CapoSqsBroker, SnsTopic, SqsQueue
41
+
42
+
43
+ class Order(BaseModel):
44
+ id: int
45
+ amount: float
46
+
47
+
48
+ broker = CapoSqsBroker(region="eu-central-1")
49
+ app = FastStream(broker)
50
+
51
+ orders = SnsTopic("orders", declare=True)
52
+ shipments = broker.publisher("shipments")
53
+
54
+
55
+ @broker.subscriber(SqsQueue("orders-billing", declare=True), topic=orders)
56
+ @shipments
57
+ async def bill(order: Order) -> dict[str, int]:
58
+ # the return value is sent to the `shipments` queue
59
+ return {"order_id": order.id}
60
+
61
+
62
+ @app.after_startup
63
+ async def place_order() -> None:
64
+ await broker.publish(Order(id=1, amount=9.5), orders)
65
+ ```
66
+
67
+ ```shell
68
+ faststream run service:app
69
+ ```
70
+
71
+ The handler reads the `orders-billing` queue, which the broker subscribes to the `orders` topic,
72
+ decodes the JSON body into `Order`, deletes the message once the handler returns, and sends its
73
+ result to the `shipments` queue.
74
+
75
+ ## With aiobotocore
76
+
77
+ ```python
78
+ import logging
79
+
80
+ from faststream import FastStream
81
+
82
+ from faststream_sqs_sns import AiobotocoreSqsBroker, SqsQueue
83
+
84
+ # the same handlers run on either backend: only the class of the broker changes
85
+ broker = AiobotocoreSqsBroker(region="eu-central-1")
86
+ app = FastStream(broker)
87
+ logger = logging.getLogger(__name__)
88
+
89
+
90
+ @broker.subscriber(SqsQueue("orders", declare=True))
91
+ async def bill(order: dict[str, int]) -> None:
92
+ logger.info("billing order %s", order["id"])
93
+ ```
94
+
95
+ ## Testing
96
+
97
+ `TestSqsBroker` runs the service in process, with the limits of the real service:
98
+
99
+ ```python
100
+ async with TestSqsBroker(broker) as br:
101
+ await br.publish(Order(id=1, amount=9.5), "orders")
102
+
103
+ bill.mock.assert_called_once_with({"id": 1, "amount": 9.5})
104
+ ```
105
+
106
+ ## Documentation
107
+
108
+ - [Getting started](https://powersemmi.github.io/faststream-sqs-sns/getting-started/)
109
+ - [Choosing a backend](https://powersemmi.github.io/faststream-sqs-sns/choosing-a-backend/)
110
+ - [LocalStack and credentials](https://powersemmi.github.io/faststream-sqs-sns/localstack-and-credentials/)
111
+ - [Queues and topics](https://powersemmi.github.io/faststream-sqs-sns/queues-and-topics/)
112
+ - [Declaring resources](https://powersemmi.github.io/faststream-sqs-sns/declaring-resources/)
113
+ - [Publishing](https://powersemmi.github.io/faststream-sqs-sns/publishing/)
114
+ - [Consuming](https://powersemmi.github.io/faststream-sqs-sns/consuming/)
115
+ - [Visibility and flow control](https://powersemmi.github.io/faststream-sqs-sns/visibility-and-flow-control/)
116
+ - [FIFO queues](https://powersemmi.github.io/faststream-sqs-sns/fifo-queues/)
117
+ - [Testing](https://powersemmi.github.io/faststream-sqs-sns/testing/)
118
+ - [FastAPI](https://powersemmi.github.io/faststream-sqs-sns/fastapi/),
119
+ [Observability](https://powersemmi.github.io/faststream-sqs-sns/observability/) and
120
+ [AsyncAPI](https://powersemmi.github.io/faststream-sqs-sns/asyncapi/)
121
+ - [API reference](https://powersemmi.github.io/faststream-sqs-sns/api/)
122
+
123
+ ## Development
124
+
125
+ See [CONTRIBUTING.md](CONTRIBUTING.md). The source lives at
126
+ <https://github.com/powersemmi/faststream-sqs-sns>.
127
+
128
+ ## License
129
+
130
+ Apache License 2.0.
@@ -0,0 +1,53 @@
1
+ """Amazon SQS broker with SNS fan-out publishing for FastStream.
2
+
3
+ ``CapoSqsBroker`` needs the ``capo`` extra and ``AiobotocoreSqsBroker`` the ``aiobotocore``
4
+ extra; both are resolved on first use, so the rest of the package imports with either alone.
5
+ """
6
+
7
+ from typing import TYPE_CHECKING, Any
8
+
9
+ from faststream_sqs_sns.annotations import SqsMessage
10
+ from faststream_sqs_sns.broker.core import SqsBroker
11
+ from faststream_sqs_sns.broker.router import SqsPublisher, SqsRoute, SqsRouter
12
+ from faststream_sqs_sns.response import SqsResponse
13
+ from faststream_sqs_sns.schemas import RedrivePolicy, SnsTopic, SqsQueue
14
+ from faststream_sqs_sns.security import AwsSecurity
15
+ from faststream_sqs_sns.subscriber.settler import FlowControl
16
+
17
+ if TYPE_CHECKING:
18
+ from faststream_sqs_sns.broker.aiobotocore import AiobotocoreSqsBroker
19
+ from faststream_sqs_sns.broker.capo import CapoSqsBroker
20
+
21
+ __all__ = (
22
+ "AiobotocoreSqsBroker",
23
+ "AwsSecurity",
24
+ "CapoSqsBroker",
25
+ "FlowControl",
26
+ "RedrivePolicy",
27
+ "SnsTopic",
28
+ "SqsBroker",
29
+ "SqsMessage",
30
+ "SqsPublisher",
31
+ "SqsQueue",
32
+ "SqsResponse",
33
+ "SqsRoute",
34
+ "SqsRouter",
35
+ )
36
+
37
+
38
+ def __getattr__(name: str) -> Any:
39
+ # Each broker module imports its backend; a missing extra raises an ImportError naming it.
40
+ if name == "CapoSqsBroker":
41
+ from faststream_sqs_sns.broker.capo import ( # ruff: ignore[import-outside-top-level]
42
+ CapoSqsBroker,
43
+ )
44
+
45
+ return CapoSqsBroker
46
+ if name == "AiobotocoreSqsBroker":
47
+ from faststream_sqs_sns.broker.aiobotocore import ( # ruff: ignore[import-outside-top-level]
48
+ AiobotocoreSqsBroker,
49
+ )
50
+
51
+ return AiobotocoreSqsBroker
52
+ msg = f"module {__name__!r} has no attribute {name!r}"
53
+ raise AttributeError(msg)