smoothapi-py 1.2.0__tar.gz → 1.2.2__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.
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/PKG-INFO +2 -1
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/README.md +1 -0
- smoothapi_py-1.2.2/out.txt +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/pyproject.toml +1 -1
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/smooth_api/__init__.py +5 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/smooth_api/state.py +12 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/.gitignore +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/LICENSE +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/smooth_api/config.py +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/smooth_api/dedup.py +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/smooth_api/utils.py +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/tests/conftest.py +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/tests/test_concurrency.py +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/tests/test_deduplication.py +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/tests/test_exceptions.py +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/tests/test_isolation.py +0 -0
- {smoothapi_py-1.2.0 → smoothapi_py-1.2.2}/tests/test_resilience.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: smoothapi-py
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Summary: API protection library — exponential backoff and circuit breaker
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -202,6 +202,7 @@ config = SmoothConfig(
|
|
|
202
202
|
2. **Circuit Check:** Before execution, the breaker checks the state. If it's `OPEN`, the request is blocked instantly (returning your fallback, or raising `RuntimeError`).
|
|
203
203
|
3. **Execution & Retries:** If an exception is raised, it attempts to extract the HTTP status code (supports `requests` and `httpx`). If the status is in `retry_on`, it's counted as a failure and the thread sleeps with backoff.
|
|
204
204
|
4. **Recovery:** After `cooldown_ms`, the breaker enters `HALF_OPEN`. The next execution acts as a probe. If it succeeds, the circuit closes. If it fails, it snaps back to `OPEN` immediately.
|
|
205
|
+
5. **Memory Management:** The circuit breaker cache is capped at 1,000 domains. When exceeded, `CLOSED` circuits with zero failures are swept to prevent memory leaks in dynamic environments.
|
|
205
206
|
|
|
206
207
|
## License
|
|
207
208
|
|
|
@@ -187,6 +187,7 @@ config = SmoothConfig(
|
|
|
187
187
|
2. **Circuit Check:** Before execution, the breaker checks the state. If it's `OPEN`, the request is blocked instantly (returning your fallback, or raising `RuntimeError`).
|
|
188
188
|
3. **Execution & Retries:** If an exception is raised, it attempts to extract the HTTP status code (supports `requests` and `httpx`). If the status is in `retry_on`, it's counted as a failure and the thread sleeps with backoff.
|
|
189
189
|
4. **Recovery:** After `cooldown_ms`, the breaker enters `HALF_OPEN`. The next execution acts as a probe. If it succeeds, the circuit closes. If it fails, it snaps back to `OPEN` immediately.
|
|
190
|
+
5. **Memory Management:** The circuit breaker cache is capped at 1,000 domains. When exceeded, `CLOSED` circuits with zero failures are swept to prevent memory leaks in dynamic environments.
|
|
190
191
|
|
|
191
192
|
## License
|
|
192
193
|
|
|
Binary file
|
|
@@ -139,6 +139,11 @@ def smooth_api(config: SmoothConfig):
|
|
|
139
139
|
return wrapper
|
|
140
140
|
|
|
141
141
|
else:
|
|
142
|
+
if deduplicator is not None:
|
|
143
|
+
import warnings
|
|
144
|
+
# Sync deduplication requires a thread-safe lock manager, which is currently unsupported
|
|
145
|
+
warnings.warn("Synchronous deduplication is not supported. Deduplication will be ignored for this function.", UserWarning, stacklevel=2)
|
|
146
|
+
|
|
142
147
|
@functools.wraps(fn)
|
|
143
148
|
def wrapper(*args, **kwargs): # type: ignore[misc]
|
|
144
149
|
fallback = kwargs.pop('fallback', config.fallback)
|
|
@@ -25,6 +25,7 @@ class CircuitBreakerState:
|
|
|
25
25
|
# No lock needed here
|
|
26
26
|
def _get_or_create(self, domain: str) -> CircuitEntry:
|
|
27
27
|
if domain not in self._map:
|
|
28
|
+
self._cleanup()
|
|
28
29
|
self._map[domain] = CircuitEntry(
|
|
29
30
|
state='CLOSED',
|
|
30
31
|
failure_count=0,
|
|
@@ -32,6 +33,17 @@ class CircuitBreakerState:
|
|
|
32
33
|
)
|
|
33
34
|
return self._map[domain]
|
|
34
35
|
|
|
36
|
+
def _cleanup(self) -> None:
|
|
37
|
+
# Enforce a strict domain limit to bound memory usage
|
|
38
|
+
if len(self._map) <= 1000:
|
|
39
|
+
return
|
|
40
|
+
keys_to_delete = [
|
|
41
|
+
k for k, v in self._map.items()
|
|
42
|
+
if v.state == 'CLOSED' and v.failure_count == 0
|
|
43
|
+
]
|
|
44
|
+
for k in keys_to_delete:
|
|
45
|
+
del self._map[k]
|
|
46
|
+
|
|
35
47
|
def can_request(self, domain: str) -> bool:
|
|
36
48
|
with self._lock:
|
|
37
49
|
entry = self._get_or_create(domain)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|