Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "freeplay"
version = "0.5.7"
version = "0.5.8"
Comment thread
nicot marked this conversation as resolved.
description = ""
authors = [
{name = "Freeplay Engineering", email = "support@freeplay.ai"},
Expand Down
21 changes: 14 additions & 7 deletions src/freeplay/api_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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
)

Expand All @@ -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),
)
Expand All @@ -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)
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.