swarmauri_middleware_ratepolicy 0.8.4.dev3__tar.gz → 0.11.0.dev1__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.
- swarmauri_middleware_ratepolicy-0.11.0.dev1/PKG-INFO +194 -0
- swarmauri_middleware_ratepolicy-0.11.0.dev1/README.md +160 -0
- {swarmauri_middleware_ratepolicy-0.8.4.dev3 → swarmauri_middleware_ratepolicy-0.11.0.dev1}/pyproject.toml +14 -12
- swarmauri_middleware_ratepolicy-0.8.4.dev3/PKG-INFO +0 -143
- swarmauri_middleware_ratepolicy-0.8.4.dev3/README.md +0 -113
- {swarmauri_middleware_ratepolicy-0.8.4.dev3 → swarmauri_middleware_ratepolicy-0.11.0.dev1}/LICENSE +0 -0
- {swarmauri_middleware_ratepolicy-0.8.4.dev3 → swarmauri_middleware_ratepolicy-0.11.0.dev1}/swarmauri_middleware_ratepolicy/RetryPolicyMiddleware.py +0 -0
- {swarmauri_middleware_ratepolicy-0.8.4.dev3 → swarmauri_middleware_ratepolicy-0.11.0.dev1}/swarmauri_middleware_ratepolicy/__init__.py +0 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_middleware_ratepolicy
|
|
3
|
+
Version: 0.11.0.dev1
|
|
4
|
+
Summary: Synchronous retry-policy middleware for Swarmauri with bounded attempts and exponential backoff.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: swarmauri,middleware,ratepolicy,retry,tenacity,backoff,resilience,fault tolerance,request middleware,retry policy
|
|
8
|
+
Author: Jacob Stewart
|
|
9
|
+
Author-email: jacob@swarmauri.com
|
|
10
|
+
Requires-Python: >=3.10,<3.15
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: System Administrators
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
28
|
+
Requires-Dist: swarmauri_base
|
|
29
|
+
Requires-Dist: swarmauri_core
|
|
30
|
+
Requires-Dist: swarmauri_standard
|
|
31
|
+
Requires-Dist: tenacity
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
<p align="center">
|
|
37
|
+
<a href="https://pepy.tech/project/swarmauri_middleware_ratepolicy/">
|
|
38
|
+
<img src="https://static.pepy.tech/badge/swarmauri_middleware_ratepolicy/month" alt="PyPI - Downloads"/></a>
|
|
39
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_middleware_ratepolicy/">
|
|
40
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_middleware_ratepolicy.svg"/></a>
|
|
41
|
+
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
42
|
+
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
43
|
+
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
44
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_middleware_ratepolicy" alt="PyPI - License"/></a>
|
|
45
|
+
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
46
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_middleware_ratepolicy?label=swarmauri_middleware_ratepolicy&color=green" alt="PyPI - swarmauri_middleware_ratepolicy"/></a>
|
|
47
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
48
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
49
|
+
|
|
50
|
+
# Swarmauri Middleware Rate Policy
|
|
51
|
+
|
|
52
|
+
`swarmauri_middleware_ratepolicy` is the Swarmauri retry-policy middleware for
|
|
53
|
+
wrapping request-like call flows with bounded retry attempts and exponential
|
|
54
|
+
backoff. It provides a synchronous `dispatch(request, call_next)` surface that
|
|
55
|
+
retries failing operations before finally re-raising the exception.
|
|
56
|
+
|
|
57
|
+
## Why Use Swarmauri Middleware Rate Policy
|
|
58
|
+
|
|
59
|
+
- Retry flaky upstream operations with a consistent middleware surface.
|
|
60
|
+
- Bound retry counts while still applying exponential backoff.
|
|
61
|
+
- Add basic resilience to synchronous request-processing or job-execution
|
|
62
|
+
pipelines.
|
|
63
|
+
- Combine with circuit breakers and logging to build layered fault handling.
|
|
64
|
+
|
|
65
|
+
## FAQ
|
|
66
|
+
|
|
67
|
+
> **What parameters does this middleware expose?**
|
|
68
|
+
> `max_retries` and `initial_wait`.
|
|
69
|
+
|
|
70
|
+
> **How is the wait interval calculated?**
|
|
71
|
+
> The middleware sleeps for `initial_wait * 2**attempts` between retries.
|
|
72
|
+
|
|
73
|
+
> **Is the middleware async?**
|
|
74
|
+
> No. The current implementation is synchronous.
|
|
75
|
+
|
|
76
|
+
> **What happens after the retry limit is reached?**
|
|
77
|
+
> The last exception is re-raised.
|
|
78
|
+
|
|
79
|
+
## Features
|
|
80
|
+
|
|
81
|
+
- Bounded retry loops over a synchronous `call_next` callable.
|
|
82
|
+
- Exponential backoff using `initial_wait`.
|
|
83
|
+
- Log messages for processing, retry attempts, and success.
|
|
84
|
+
- Swarmauri `MiddlewareBase` integration for reusable resilience flows.
|
|
85
|
+
- Supports Python 3.10, 3.11, 3.12, 3.13, and 3.14.
|
|
86
|
+
|
|
87
|
+
## Installation
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
uv add swarmauri_middleware_ratepolicy
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
pip install swarmauri_middleware_ratepolicy
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Usage
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
101
|
+
|
|
102
|
+
retry = RetryPolicyMiddleware(max_retries=3, initial_wait=0.5)
|
|
103
|
+
|
|
104
|
+
class RequestEnvelope:
|
|
105
|
+
def __init__(self, payload: str):
|
|
106
|
+
self.payload = payload
|
|
107
|
+
|
|
108
|
+
request = RequestEnvelope("work-item-123")
|
|
109
|
+
|
|
110
|
+
def call_next(req):
|
|
111
|
+
raise RuntimeError("Simulated upstream failure")
|
|
112
|
+
|
|
113
|
+
retry.dispatch(request, call_next)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Examples
|
|
117
|
+
|
|
118
|
+
### Retry a failing operation
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
import logging
|
|
122
|
+
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
123
|
+
|
|
124
|
+
logging.basicConfig(level=logging.INFO)
|
|
125
|
+
|
|
126
|
+
retry = RetryPolicyMiddleware(max_retries=3, initial_wait=0.25)
|
|
127
|
+
|
|
128
|
+
def unstable(_request):
|
|
129
|
+
raise RuntimeError("Temporary failure")
|
|
130
|
+
|
|
131
|
+
retry.dispatch({"task": "sync"}, unstable)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Wrap an external API call
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
import httpx
|
|
138
|
+
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
139
|
+
|
|
140
|
+
retry = RetryPolicyMiddleware(max_retries=4, initial_wait=0.25)
|
|
141
|
+
|
|
142
|
+
class RequestWrapper:
|
|
143
|
+
def __init__(self, url: str):
|
|
144
|
+
self.url = url
|
|
145
|
+
|
|
146
|
+
response = retry.dispatch(
|
|
147
|
+
RequestWrapper("https://api.example.com/data"),
|
|
148
|
+
lambda req: httpx.get(req.url, timeout=5),
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
print(response.status_code)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Register in a larger middleware stack
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
158
|
+
|
|
159
|
+
middleware = RetryPolicyMiddleware(max_retries=2, initial_wait=1.0)
|
|
160
|
+
print(middleware.type)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Related Packages
|
|
164
|
+
|
|
165
|
+
- [swarmauri_middleware_circuitbreaker](https://pypi.org/project/swarmauri_middleware_circuitbreaker/)
|
|
166
|
+
- [swarmauri_state_clipboard](https://pypi.org/project/swarmauri_state_clipboard/)
|
|
167
|
+
- [swarmauri_middleware_ratepolicy](https://pypi.org/project/swarmauri_middleware_ratepolicy/)
|
|
168
|
+
|
|
169
|
+
## Swarmauri Foundations
|
|
170
|
+
|
|
171
|
+
- [swarmauri](https://pypi.org/project/swarmauri/)
|
|
172
|
+
- [swarmauri_core](https://pypi.org/project/swarmauri_core/)
|
|
173
|
+
- [swarmauri_base](https://pypi.org/project/swarmauri_base/)
|
|
174
|
+
- [swarmauri_standard](https://pypi.org/project/swarmauri_standard/)
|
|
175
|
+
|
|
176
|
+
## More Documentation
|
|
177
|
+
|
|
178
|
+
- [Tenacity documentation](https://tenacity.readthedocs.io/en/stable/index.html)
|
|
179
|
+
|
|
180
|
+
## Best Practices
|
|
181
|
+
|
|
182
|
+
- Keep retry counts small for latency-sensitive user requests.
|
|
183
|
+
- Use circuit breakers when a dependency is consistently unhealthy instead of
|
|
184
|
+
only increasing retries.
|
|
185
|
+
- Apply retries around idempotent operations whenever possible.
|
|
186
|
+
- Convert async flows deliberately if you need to wrap them with this
|
|
187
|
+
synchronous middleware surface.
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
This project is licensed under the Apache-2.0 License.
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://pepy.tech/project/swarmauri_middleware_ratepolicy/">
|
|
5
|
+
<img src="https://static.pepy.tech/badge/swarmauri_middleware_ratepolicy/month" alt="PyPI - Downloads"/></a>
|
|
6
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_middleware_ratepolicy/">
|
|
7
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_middleware_ratepolicy.svg"/></a>
|
|
8
|
+
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
9
|
+
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
10
|
+
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
11
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_middleware_ratepolicy" alt="PyPI - License"/></a>
|
|
12
|
+
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
13
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_middleware_ratepolicy?label=swarmauri_middleware_ratepolicy&color=green" alt="PyPI - swarmauri_middleware_ratepolicy"/></a>
|
|
14
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
15
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
16
|
+
|
|
17
|
+
# Swarmauri Middleware Rate Policy
|
|
18
|
+
|
|
19
|
+
`swarmauri_middleware_ratepolicy` is the Swarmauri retry-policy middleware for
|
|
20
|
+
wrapping request-like call flows with bounded retry attempts and exponential
|
|
21
|
+
backoff. It provides a synchronous `dispatch(request, call_next)` surface that
|
|
22
|
+
retries failing operations before finally re-raising the exception.
|
|
23
|
+
|
|
24
|
+
## Why Use Swarmauri Middleware Rate Policy
|
|
25
|
+
|
|
26
|
+
- Retry flaky upstream operations with a consistent middleware surface.
|
|
27
|
+
- Bound retry counts while still applying exponential backoff.
|
|
28
|
+
- Add basic resilience to synchronous request-processing or job-execution
|
|
29
|
+
pipelines.
|
|
30
|
+
- Combine with circuit breakers and logging to build layered fault handling.
|
|
31
|
+
|
|
32
|
+
## FAQ
|
|
33
|
+
|
|
34
|
+
> **What parameters does this middleware expose?**
|
|
35
|
+
> `max_retries` and `initial_wait`.
|
|
36
|
+
|
|
37
|
+
> **How is the wait interval calculated?**
|
|
38
|
+
> The middleware sleeps for `initial_wait * 2**attempts` between retries.
|
|
39
|
+
|
|
40
|
+
> **Is the middleware async?**
|
|
41
|
+
> No. The current implementation is synchronous.
|
|
42
|
+
|
|
43
|
+
> **What happens after the retry limit is reached?**
|
|
44
|
+
> The last exception is re-raised.
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- Bounded retry loops over a synchronous `call_next` callable.
|
|
49
|
+
- Exponential backoff using `initial_wait`.
|
|
50
|
+
- Log messages for processing, retry attempts, and success.
|
|
51
|
+
- Swarmauri `MiddlewareBase` integration for reusable resilience flows.
|
|
52
|
+
- Supports Python 3.10, 3.11, 3.12, 3.13, and 3.14.
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
uv add swarmauri_middleware_ratepolicy
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install swarmauri_middleware_ratepolicy
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
68
|
+
|
|
69
|
+
retry = RetryPolicyMiddleware(max_retries=3, initial_wait=0.5)
|
|
70
|
+
|
|
71
|
+
class RequestEnvelope:
|
|
72
|
+
def __init__(self, payload: str):
|
|
73
|
+
self.payload = payload
|
|
74
|
+
|
|
75
|
+
request = RequestEnvelope("work-item-123")
|
|
76
|
+
|
|
77
|
+
def call_next(req):
|
|
78
|
+
raise RuntimeError("Simulated upstream failure")
|
|
79
|
+
|
|
80
|
+
retry.dispatch(request, call_next)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Examples
|
|
84
|
+
|
|
85
|
+
### Retry a failing operation
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import logging
|
|
89
|
+
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
90
|
+
|
|
91
|
+
logging.basicConfig(level=logging.INFO)
|
|
92
|
+
|
|
93
|
+
retry = RetryPolicyMiddleware(max_retries=3, initial_wait=0.25)
|
|
94
|
+
|
|
95
|
+
def unstable(_request):
|
|
96
|
+
raise RuntimeError("Temporary failure")
|
|
97
|
+
|
|
98
|
+
retry.dispatch({"task": "sync"}, unstable)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Wrap an external API call
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
import httpx
|
|
105
|
+
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
106
|
+
|
|
107
|
+
retry = RetryPolicyMiddleware(max_retries=4, initial_wait=0.25)
|
|
108
|
+
|
|
109
|
+
class RequestWrapper:
|
|
110
|
+
def __init__(self, url: str):
|
|
111
|
+
self.url = url
|
|
112
|
+
|
|
113
|
+
response = retry.dispatch(
|
|
114
|
+
RequestWrapper("https://api.example.com/data"),
|
|
115
|
+
lambda req: httpx.get(req.url, timeout=5),
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
print(response.status_code)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Register in a larger middleware stack
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
125
|
+
|
|
126
|
+
middleware = RetryPolicyMiddleware(max_retries=2, initial_wait=1.0)
|
|
127
|
+
print(middleware.type)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Related Packages
|
|
131
|
+
|
|
132
|
+
- [swarmauri_middleware_circuitbreaker](https://pypi.org/project/swarmauri_middleware_circuitbreaker/)
|
|
133
|
+
- [swarmauri_state_clipboard](https://pypi.org/project/swarmauri_state_clipboard/)
|
|
134
|
+
- [swarmauri_middleware_ratepolicy](https://pypi.org/project/swarmauri_middleware_ratepolicy/)
|
|
135
|
+
|
|
136
|
+
## Swarmauri Foundations
|
|
137
|
+
|
|
138
|
+
- [swarmauri](https://pypi.org/project/swarmauri/)
|
|
139
|
+
- [swarmauri_core](https://pypi.org/project/swarmauri_core/)
|
|
140
|
+
- [swarmauri_base](https://pypi.org/project/swarmauri_base/)
|
|
141
|
+
- [swarmauri_standard](https://pypi.org/project/swarmauri_standard/)
|
|
142
|
+
|
|
143
|
+
## More Documentation
|
|
144
|
+
|
|
145
|
+
- [Tenacity documentation](https://tenacity.readthedocs.io/en/stable/index.html)
|
|
146
|
+
|
|
147
|
+
## Best Practices
|
|
148
|
+
|
|
149
|
+
- Keep retry counts small for latency-sensitive user requests.
|
|
150
|
+
- Use circuit breakers when a dependency is consistently unhealthy instead of
|
|
151
|
+
only increasing retries.
|
|
152
|
+
- Apply retries around idempotent operations whenever possible.
|
|
153
|
+
- Convert async flows deliberately if you need to wrap them with this
|
|
154
|
+
synchronous middleware surface.
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
This project is licensed under the Apache-2.0 License.
|
|
159
|
+
|
|
160
|
+
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "swarmauri_middleware_ratepolicy"
|
|
3
|
-
version = "0.
|
|
4
|
-
description = "
|
|
3
|
+
version = "0.11.0.dev1"
|
|
4
|
+
description = "Synchronous retry-policy middleware for Swarmauri with bounded attempts and exponential backoff."
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
readme = "README.md"
|
|
7
|
-
repository = "http://github.com/swarmauri/swarmauri-sdk
|
|
7
|
+
repository = "http://github.com/swarmauri/swarmauri-sdk"
|
|
8
8
|
requires-python = ">=3.10,<3.15"
|
|
9
9
|
classifiers = [
|
|
10
10
|
"License :: OSI Approved :: Apache Software License",
|
|
11
11
|
"Natural Language :: English",
|
|
12
12
|
"Development Status :: 3 - Alpha",
|
|
13
13
|
"Intended Audience :: Developers",
|
|
14
|
+
"Intended Audience :: System Administrators",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
17
|
+
"Topic :: Software Development :: Libraries",
|
|
14
18
|
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
15
19
|
"Programming Language :: Python",
|
|
16
20
|
"Programming Language :: Python :: 3",
|
|
@@ -34,13 +38,11 @@ keywords = [
|
|
|
34
38
|
"ratepolicy",
|
|
35
39
|
"retry",
|
|
36
40
|
"tenacity",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"policy",
|
|
43
|
-
"logic",
|
|
41
|
+
"backoff",
|
|
42
|
+
"resilience",
|
|
43
|
+
"fault tolerance",
|
|
44
|
+
"request middleware",
|
|
45
|
+
"retry policy",
|
|
44
46
|
]
|
|
45
47
|
|
|
46
48
|
[tool.uv.sources]
|
|
@@ -80,7 +82,7 @@ dev = [
|
|
|
80
82
|
"pytest-mock>=3.12.0",
|
|
81
83
|
"pytest-json-report>=1.5.0",
|
|
82
84
|
"python-dotenv",
|
|
83
|
-
"
|
|
85
|
+
"httpx>=0.27",
|
|
84
86
|
"flake8>=7.0",
|
|
85
87
|
"pytest-timeout>=2.3.1",
|
|
86
88
|
"ruff>=0.9.9",
|
|
@@ -88,4 +90,4 @@ dev = [
|
|
|
88
90
|
]
|
|
89
91
|
|
|
90
92
|
[project.entry-points.'swarmauri.middlewares']
|
|
91
|
-
RetryPolicyMiddleware = "swarmauri_middleware_ratepolicy:RetryPolicyMiddleware"
|
|
93
|
+
RetryPolicyMiddleware = "swarmauri_middleware_ratepolicy:RetryPolicyMiddleware"
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: swarmauri_middleware_ratepolicy
|
|
3
|
-
Version: 0.8.4.dev3
|
|
4
|
-
Summary: A middleware implementing rate policy and retry logic for Swarmauri
|
|
5
|
-
License-Expression: Apache-2.0
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Keywords: swarmauri,middleware,ratepolicy,retry,tenacity,async,api,framework,implementing,rate,policy,logic
|
|
8
|
-
Author: Jacob Stewart
|
|
9
|
-
Author-email: jacob@swarmauri.com
|
|
10
|
-
Requires-Python: >=3.10,<3.15
|
|
11
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
-
Classifier: Natural Language :: English
|
|
13
|
-
Classifier: Development Status :: 3 - Alpha
|
|
14
|
-
Classifier: Intended Audience :: Developers
|
|
15
|
-
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
16
|
-
Classifier: Programming Language :: Python
|
|
17
|
-
Classifier: Programming Language :: Python :: 3
|
|
18
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
-
Requires-Dist: swarmauri_base
|
|
25
|
-
Requires-Dist: swarmauri_core
|
|
26
|
-
Requires-Dist: swarmauri_standard
|
|
27
|
-
Requires-Dist: tenacity
|
|
28
|
-
Description-Content-Type: text/markdown
|
|
29
|
-
|
|
30
|
-

|
|
31
|
-
|
|
32
|
-
<p align="center">
|
|
33
|
-
<a href="https://pepy.tech/project/swarmauri_middleware_ratepolicy/">
|
|
34
|
-
<img src="https://static.pepy.tech/badge/swarmauri_middleware_ratepolicy/month" alt="PyPI - Downloads"/></a>
|
|
35
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_middleware_ratepolicy/">
|
|
36
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_middleware_ratepolicy.svg"/></a>
|
|
37
|
-
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
38
|
-
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
39
|
-
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
40
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_middleware_ratepolicy" alt="PyPI - License"/></a>
|
|
41
|
-
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
42
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_middleware_ratepolicy?label=swarmauri_middleware_ratepolicy&color=green" alt="PyPI - swarmauri_middleware_ratepolicy"/></a>
|
|
43
|
-
</p>
|
|
44
|
-
|
|
45
|
-
# Swarmauri Middleware Ratepolicy
|
|
46
|
-
|
|
47
|
-
Retry-policy middleware for Swarmauri services. Provides exponential backoff with configurable retry attempts and wait intervals so unreliable upstream calls can be retried transparently.
|
|
48
|
-
|
|
49
|
-
## Features
|
|
50
|
-
|
|
51
|
-
- Implements Swarmauri's `MiddlewareBase` contract; wrap any callable sequence (FastAPI routes, job runners, etc.).
|
|
52
|
-
- Configurable `max_retries` and `initial_wait` seconds. Wait time doubles on each retry (`initial_wait * 2**attempt`).
|
|
53
|
-
- Emits structured logs on retry attempts and successes for observability.
|
|
54
|
-
- Simple synchronous dispatch; wrap async callables by providing a sync shim that executes the coroutine (see example below).
|
|
55
|
-
|
|
56
|
-
## Prerequisites
|
|
57
|
-
|
|
58
|
-
- Python 3.10 or newer.
|
|
59
|
-
- A Swarmauri application or FastAPI project that supports middleware registration.
|
|
60
|
-
|
|
61
|
-
## Installation
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
# pip
|
|
65
|
-
pip install swarmauri_middleware_ratepolicy
|
|
66
|
-
|
|
67
|
-
# poetry
|
|
68
|
-
poetry add swarmauri_middleware_ratepolicy
|
|
69
|
-
|
|
70
|
-
# uv (pyproject-based projects)
|
|
71
|
-
uv add swarmauri_middleware_ratepolicy
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Quickstart
|
|
75
|
-
|
|
76
|
-
```python
|
|
77
|
-
import logging
|
|
78
|
-
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
79
|
-
|
|
80
|
-
logging.basicConfig(level=logging.INFO)
|
|
81
|
-
|
|
82
|
-
retry_middleware = RetryPolicyMiddleware(max_retries=3, initial_wait=0.5)
|
|
83
|
-
|
|
84
|
-
class RequestEnvelope:
|
|
85
|
-
def __init__(self, payload: str):
|
|
86
|
-
self.payload = payload
|
|
87
|
-
|
|
88
|
-
request = RequestEnvelope("work-item-123")
|
|
89
|
-
|
|
90
|
-
def call_next(req: RequestEnvelope):
|
|
91
|
-
raise RuntimeError("Simulated upstream failure")
|
|
92
|
-
|
|
93
|
-
retry_middleware.dispatch(request, call_next)
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
With Swarmauri's middleware stack (or FastAPI), register it just like other Swarmauri middleware:
|
|
97
|
-
|
|
98
|
-
```python
|
|
99
|
-
from swarmauri_app.middleware import middleware_stack
|
|
100
|
-
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
101
|
-
|
|
102
|
-
middleware_stack.add_middleware(
|
|
103
|
-
RetryPolicyMiddleware,
|
|
104
|
-
max_retries=4,
|
|
105
|
-
initial_wait=0.25,
|
|
106
|
-
)
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
## Example: Wrapping an External API Call
|
|
110
|
-
|
|
111
|
-
```python
|
|
112
|
-
import logging
|
|
113
|
-
import requests
|
|
114
|
-
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
115
|
-
|
|
116
|
-
logging.basicConfig(level=logging.INFO)
|
|
117
|
-
|
|
118
|
-
retry = RetryPolicyMiddleware(max_retries=4, initial_wait=0.25)
|
|
119
|
-
|
|
120
|
-
class RequestWrapper:
|
|
121
|
-
def __init__(self, url: str):
|
|
122
|
-
self.url = url
|
|
123
|
-
|
|
124
|
-
wrapper = RequestWrapper("https://api.example.com/data")
|
|
125
|
-
|
|
126
|
-
response = retry.dispatch(
|
|
127
|
-
wrapper,
|
|
128
|
-
lambda req: requests.get(req.url, timeout=5),
|
|
129
|
-
)
|
|
130
|
-
print(response.status_code)
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## Tips
|
|
134
|
-
|
|
135
|
-
- Keep `max_retries` small for user-facing endpoints to avoid long wait chains; rely on background queues for bulk retries.
|
|
136
|
-
- Combine with the circuit breaker middleware for layered resilience (circuit breaker opens when repeated retries fail).
|
|
137
|
-
- When wrapping async callables, convert them to sync functions using `asyncio.run` or `anyio.from_thread` to fit the middleware signature.
|
|
138
|
-
- Capture logs at INFO level to trace retry attempts in production.
|
|
139
|
-
|
|
140
|
-
## Want to help?
|
|
141
|
-
|
|
142
|
-
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
143
|
-
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<a href="https://pepy.tech/project/swarmauri_middleware_ratepolicy/">
|
|
5
|
-
<img src="https://static.pepy.tech/badge/swarmauri_middleware_ratepolicy/month" alt="PyPI - Downloads"/></a>
|
|
6
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_middleware_ratepolicy/">
|
|
7
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_middleware_ratepolicy.svg"/></a>
|
|
8
|
-
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
9
|
-
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
10
|
-
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
11
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_middleware_ratepolicy" alt="PyPI - License"/></a>
|
|
12
|
-
<a href="https://pypi.org/project/swarmauri_middleware_ratepolicy/">
|
|
13
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_middleware_ratepolicy?label=swarmauri_middleware_ratepolicy&color=green" alt="PyPI - swarmauri_middleware_ratepolicy"/></a>
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
# Swarmauri Middleware Ratepolicy
|
|
17
|
-
|
|
18
|
-
Retry-policy middleware for Swarmauri services. Provides exponential backoff with configurable retry attempts and wait intervals so unreliable upstream calls can be retried transparently.
|
|
19
|
-
|
|
20
|
-
## Features
|
|
21
|
-
|
|
22
|
-
- Implements Swarmauri's `MiddlewareBase` contract; wrap any callable sequence (FastAPI routes, job runners, etc.).
|
|
23
|
-
- Configurable `max_retries` and `initial_wait` seconds. Wait time doubles on each retry (`initial_wait * 2**attempt`).
|
|
24
|
-
- Emits structured logs on retry attempts and successes for observability.
|
|
25
|
-
- Simple synchronous dispatch; wrap async callables by providing a sync shim that executes the coroutine (see example below).
|
|
26
|
-
|
|
27
|
-
## Prerequisites
|
|
28
|
-
|
|
29
|
-
- Python 3.10 or newer.
|
|
30
|
-
- A Swarmauri application or FastAPI project that supports middleware registration.
|
|
31
|
-
|
|
32
|
-
## Installation
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
# pip
|
|
36
|
-
pip install swarmauri_middleware_ratepolicy
|
|
37
|
-
|
|
38
|
-
# poetry
|
|
39
|
-
poetry add swarmauri_middleware_ratepolicy
|
|
40
|
-
|
|
41
|
-
# uv (pyproject-based projects)
|
|
42
|
-
uv add swarmauri_middleware_ratepolicy
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Quickstart
|
|
46
|
-
|
|
47
|
-
```python
|
|
48
|
-
import logging
|
|
49
|
-
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
50
|
-
|
|
51
|
-
logging.basicConfig(level=logging.INFO)
|
|
52
|
-
|
|
53
|
-
retry_middleware = RetryPolicyMiddleware(max_retries=3, initial_wait=0.5)
|
|
54
|
-
|
|
55
|
-
class RequestEnvelope:
|
|
56
|
-
def __init__(self, payload: str):
|
|
57
|
-
self.payload = payload
|
|
58
|
-
|
|
59
|
-
request = RequestEnvelope("work-item-123")
|
|
60
|
-
|
|
61
|
-
def call_next(req: RequestEnvelope):
|
|
62
|
-
raise RuntimeError("Simulated upstream failure")
|
|
63
|
-
|
|
64
|
-
retry_middleware.dispatch(request, call_next)
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
With Swarmauri's middleware stack (or FastAPI), register it just like other Swarmauri middleware:
|
|
68
|
-
|
|
69
|
-
```python
|
|
70
|
-
from swarmauri_app.middleware import middleware_stack
|
|
71
|
-
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
72
|
-
|
|
73
|
-
middleware_stack.add_middleware(
|
|
74
|
-
RetryPolicyMiddleware,
|
|
75
|
-
max_retries=4,
|
|
76
|
-
initial_wait=0.25,
|
|
77
|
-
)
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## Example: Wrapping an External API Call
|
|
81
|
-
|
|
82
|
-
```python
|
|
83
|
-
import logging
|
|
84
|
-
import requests
|
|
85
|
-
from swarmauri_middleware_ratepolicy import RetryPolicyMiddleware
|
|
86
|
-
|
|
87
|
-
logging.basicConfig(level=logging.INFO)
|
|
88
|
-
|
|
89
|
-
retry = RetryPolicyMiddleware(max_retries=4, initial_wait=0.25)
|
|
90
|
-
|
|
91
|
-
class RequestWrapper:
|
|
92
|
-
def __init__(self, url: str):
|
|
93
|
-
self.url = url
|
|
94
|
-
|
|
95
|
-
wrapper = RequestWrapper("https://api.example.com/data")
|
|
96
|
-
|
|
97
|
-
response = retry.dispatch(
|
|
98
|
-
wrapper,
|
|
99
|
-
lambda req: requests.get(req.url, timeout=5),
|
|
100
|
-
)
|
|
101
|
-
print(response.status_code)
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## Tips
|
|
105
|
-
|
|
106
|
-
- Keep `max_retries` small for user-facing endpoints to avoid long wait chains; rely on background queues for bulk retries.
|
|
107
|
-
- Combine with the circuit breaker middleware for layered resilience (circuit breaker opens when repeated retries fail).
|
|
108
|
-
- When wrapping async callables, convert them to sync functions using `asyncio.run` or `anyio.from_thread` to fit the middleware signature.
|
|
109
|
-
- Capture logs at INFO level to trace retry attempts in production.
|
|
110
|
-
|
|
111
|
-
## Want to help?
|
|
112
|
-
|
|
113
|
-
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
{swarmauri_middleware_ratepolicy-0.8.4.dev3 → swarmauri_middleware_ratepolicy-0.11.0.dev1}/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|