smoothapi-py 1.3.1__tar.gz → 1.3.3__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.3.3/CHANGELOG.md +5 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/PKG-INFO +5 -2
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/pyproject.toml +7 -2
- smoothapi_py-1.3.3/tests/test_backoff.py +20 -0
- smoothapi_py-1.3.3/tests/test_deprecation.py +12 -0
- smoothapi_py-1.3.3/tests/test_edge_cases.py +52 -0
- smoothapi_py-1.3.3/tests/test_mock_response.py +30 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/.gitignore +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/LICENSE +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/README.md +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/smooth_api/__init__.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/smooth_api/config.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/smooth_api/dedup.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/smooth_api/state.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/smooth_api/utils.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/tests/conftest.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/tests/test_concurrency.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/tests/test_deduplication.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/tests/test_exceptions.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/tests/test_isolation.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/tests/test_resilience.py +0 -0
- {smoothapi_py-1.3.1 → smoothapi_py-1.3.3}/tests/test_timeout.py +0 -0
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: smoothapi-py
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.3
|
|
4
4
|
Summary: API protection library — exponential backoff and circuit breaker
|
|
5
|
+
Project-URL: Homepage, https://smoothapi.org
|
|
6
|
+
Project-URL: Issues, https://github.com/AryanSharma48/smoothAPI/issues
|
|
7
|
+
Project-URL: Repository, https://github.com/AryanSharma48/smoothAPI.git
|
|
5
8
|
License: MIT
|
|
6
9
|
License-File: LICENSE
|
|
7
|
-
Keywords: backoff,circuit-breaker,http,
|
|
10
|
+
Keywords: backoff,circuit-breaker,http,retry,robustness
|
|
8
11
|
Requires-Python: >=3.10
|
|
9
12
|
Provides-Extra: dev
|
|
10
13
|
Requires-Dist: httpx>=0.24; extra == 'dev'
|
|
@@ -4,14 +4,19 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "smoothapi-py"
|
|
7
|
-
version = "1.3.
|
|
7
|
+
version = "1.3.3"
|
|
8
8
|
description = "API protection library — exponential backoff and circuit breaker"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
license = { text = "MIT" }
|
|
12
|
-
keywords = ["
|
|
12
|
+
keywords = ["robustness", "circuit-breaker", "retry", "backoff", "http"]
|
|
13
13
|
dependencies = []
|
|
14
14
|
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://smoothapi.org"
|
|
17
|
+
Issues = "https://github.com/AryanSharma48/smoothAPI/issues"
|
|
18
|
+
Repository = "https://github.com/AryanSharma48/smoothAPI.git"
|
|
19
|
+
|
|
15
20
|
[project.optional-dependencies]
|
|
16
21
|
dev = [
|
|
17
22
|
"pytest>=7.0",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Unit tests for backoff and jitter calculation in smooth_api."""
|
|
2
|
+
import pytest
|
|
3
|
+
from smooth_api.config import BackoffConfig
|
|
4
|
+
from smooth_api.utils import calculate_backoff
|
|
5
|
+
|
|
6
|
+
def test_backoff_respects_max_delay_boundaries():
|
|
7
|
+
config = BackoffConfig(base_delay=0.1, max_delay=5.0, max_retries=5)
|
|
8
|
+
for _ in range(100):
|
|
9
|
+
delay = calculate_backoff(10, config)
|
|
10
|
+
assert 0.0 <= delay <= 5.0
|
|
11
|
+
|
|
12
|
+
def test_backoff_exhibits_jitter_distribution():
|
|
13
|
+
config = BackoffConfig(base_delay=0.1, max_delay=5.0, max_retries=3)
|
|
14
|
+
delays = set()
|
|
15
|
+
for _ in range(20):
|
|
16
|
+
delay = calculate_backoff(2, config)
|
|
17
|
+
assert 0.0 <= delay <= 0.4
|
|
18
|
+
delays.add(delay)
|
|
19
|
+
|
|
20
|
+
assert len(delays) > 1, "Backoff jitter did not produce variable delays"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from smooth_api import resilient_api, SmoothConfig, ResilientConfig
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_resilient_api_warning():
|
|
6
|
+
with pytest.warns(DeprecationWarning, match="resilient_api"):
|
|
7
|
+
resilient_api(SmoothConfig())
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_resilient_config_warning():
|
|
11
|
+
with pytest.warns(DeprecationWarning, match="ResilientConfig"):
|
|
12
|
+
ResilientConfig()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Unit tests for domain sweeper memory cap and edge case header handling in smooth_api."""
|
|
2
|
+
import pytest
|
|
3
|
+
import requests
|
|
4
|
+
from smooth_api.state import CircuitBreakerState
|
|
5
|
+
from smooth_api import smooth_api, SmoothConfig
|
|
6
|
+
from smooth_api.config import BackoffConfig, CircuitBreakerConfig
|
|
7
|
+
|
|
8
|
+
def test_circuit_breaker_domain_memory_cleanup():
|
|
9
|
+
breaker = CircuitBreakerState(CircuitBreakerConfig())
|
|
10
|
+
|
|
11
|
+
# Add 1050 healthy CLOSED domains
|
|
12
|
+
for i in range(1050):
|
|
13
|
+
breaker.can_request(f"domain-{i}.com")
|
|
14
|
+
|
|
15
|
+
# Trigger cleanup by checking a new domain
|
|
16
|
+
breaker.can_request("trigger-cleanup.com")
|
|
17
|
+
|
|
18
|
+
# Check that state querying domain-0.com returns CLOSED gracefully
|
|
19
|
+
state = breaker.get_state("domain-0.com")
|
|
20
|
+
assert state == "CLOSED"
|
|
21
|
+
|
|
22
|
+
def test_malformed_retry_after_header_handling():
|
|
23
|
+
class MockResponseInvalid:
|
|
24
|
+
status_code = 429
|
|
25
|
+
headers = {"Retry-After": "not-a-number"}
|
|
26
|
+
reason = "Too Many Requests"
|
|
27
|
+
|
|
28
|
+
class MockResponseSuccess:
|
|
29
|
+
status_code = 200
|
|
30
|
+
headers = {}
|
|
31
|
+
reason = "OK"
|
|
32
|
+
def json(self):
|
|
33
|
+
return {"success": True}
|
|
34
|
+
|
|
35
|
+
call_count = [0]
|
|
36
|
+
config = SmoothConfig(
|
|
37
|
+
backoff=BackoffConfig(base_delay=0.01, max_delay=0.05, max_retries=1),
|
|
38
|
+
retry_on=[429]
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
@smooth_api(config)
|
|
42
|
+
def get_data():
|
|
43
|
+
call_count[0] += 1
|
|
44
|
+
if call_count[0] == 1:
|
|
45
|
+
err = requests.exceptions.HTTPError("429")
|
|
46
|
+
err.response = MockResponseInvalid()
|
|
47
|
+
raise err
|
|
48
|
+
return MockResponseSuccess()
|
|
49
|
+
|
|
50
|
+
res = get_data()
|
|
51
|
+
assert call_count[0] == 2
|
|
52
|
+
assert res.status_code == 200
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from smooth_api import MockResponse
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_mock_response_json():
|
|
5
|
+
content = {"message": "circuit is open"}
|
|
6
|
+
response = MockResponse(status_code=503, content=content)
|
|
7
|
+
|
|
8
|
+
assert response.json() == content
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_mock_response_text():
|
|
12
|
+
import json
|
|
13
|
+
|
|
14
|
+
content = {"message": "circuit is open"}
|
|
15
|
+
response = MockResponse(status_code=503, content=content)
|
|
16
|
+
|
|
17
|
+
assert json.loads(response.text) == content
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_mock_response_ok():
|
|
21
|
+
assert MockResponse(status_code=200, content={}).ok is True
|
|
22
|
+
assert MockResponse(status_code=399, content={}).ok is True
|
|
23
|
+
assert MockResponse(status_code=400, content={}).ok is False
|
|
24
|
+
assert MockResponse(status_code=503, content={}).ok is False
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_mock_response_status_code():
|
|
28
|
+
response = MockResponse(status_code=503, content={})
|
|
29
|
+
|
|
30
|
+
assert response.status_code == 503
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|