From 9c6107ca89a538f5cb97924376f4330a2ca1e730 Mon Sep 17 00:00:00 2001 From: Nico Tonozzi Date: Thu, 19 Feb 2026 20:13:13 +0000 Subject: [PATCH 1/2] Add retries for connect failures --- pyproject.toml | 2 +- src/freeplay/api_support.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b767285..7ca377d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "freeplay" -version = "0.5.7" +version = "0.5.8" description = "" authors = [ {name = "Freeplay Engineering", email = "support@freeplay.ai"}, diff --git a/src/freeplay/api_support.py b/src/freeplay/api_support.py index 345f8f4..d803fa3 100644 --- a/src/freeplay/api_support.py +++ b/src/freeplay/api_support.py @@ -6,9 +6,16 @@ import dacite import requests from requests import Response +from requests.adapters import HTTPAdapter +from urllib3.util.retry import Retry from freeplay.utils import build_request_header +_retry = Retry(connect=3, backoff_factor=0.5) +_session = requests.Session() +_session.mount("https://", HTTPAdapter(max_retries=_retry)) +_session.mount("http://", HTTPAdapter(max_retries=_retry)) + T = t.TypeVar("T") logger = logging.getLogger(__name__) @@ -33,7 +40,7 @@ def post( url: str, payload: t.Optional[Dict[str, str]] = None, ) -> T: - response = requests.post( + response = _session.post( url=url, headers=build_request_header(api_key), json=payload ) @@ -52,30 +59,30 @@ def post( def put_raw( api_key: str, url: str, payload: t.Optional[Dict[str, t.Any]] = None ) -> Response: - return requests.put(url=url, headers=build_request_header(api_key), json=payload) + return _session.put(url=url, headers=build_request_header(api_key), json=payload) def patch_raw( api_key: str, url: str, payload: t.Optional[Dict[str, t.Any]] = None ) -> Response: - return requests.patch(url=url, headers=build_request_header(api_key), json=payload) + return _session.patch(url=url, headers=build_request_header(api_key), json=payload) def post_raw( api_key: str, url: str, payload: t.Optional[Dict[str, t.Any]] = None ) -> Response: - return requests.post(url=url, headers=build_request_header(api_key), json=payload) + return _session.post(url=url, headers=build_request_header(api_key), json=payload) def delete_raw(api_key: str, url: str) -> Response: - return requests.delete( + return _session.delete( url=url, headers=build_request_header(api_key), ) def get(target_type: t.Type[T], api_key: str, url: str) -> T: - response = requests.get( + response = _session.get( url=url, headers=build_request_header(api_key), ) @@ -95,4 +102,4 @@ def get(target_type: t.Type[T], api_key: str, url: str) -> T: def get_raw( api_key: str, url: str, params: t.Optional[Dict[str, str]] = None ) -> Response: - return requests.get(url=url, headers=build_request_header(api_key), params=params) + return _session.get(url=url, headers=build_request_header(api_key), params=params) From 113763c845ca42dcfc7e6d82ad09aec6eee94224 Mon Sep 17 00:00:00 2001 From: Nico Tonozzi Date: Thu, 19 Feb 2026 21:07:32 +0000 Subject: [PATCH 2/2] Bump uv lock and update changelog --- CHANGELOG.md | 6 ++++++ uv.lock | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a44091..8835cd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ Notable additions, fixes, or breaking changes to the Freeplay SDK. +## [0.5.8] + +### Fixed + +- Added automatic retries for transient connection failures on HTTP requests. + ## [0.5.7] ### Added diff --git a/uv.lock b/uv.lock index 51dc2c6..9601078 100644 --- a/uv.lock +++ b/uv.lock @@ -353,7 +353,7 @@ wheels = [ [[package]] name = "freeplay" -version = "0.5.7" +version = "0.5.8" source = { editable = "." } dependencies = [ { name = "click", version = "8.1.8", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.10'" },