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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.14.2] - 2025-08-04
### Fixed
- added back Api attributes removed in a previous release, this should fix potential breaking changes introduced in 1.14.1;

## [1.14.1] - 2025-07-25
### Added
- Session mechanism for significantly decrease number of an http load on data-api for apps with intensive calling
Expand Down
2 changes: 1 addition & 1 deletion docs/antora-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ content:
start_path: docs
branches: []
# branches: HEAD # Use this for local development
tags: [v1.14.1]
tags: [v1.14.2]
asciidoc:
attributes:
page-toclevels: 5
Expand Down
2 changes: 1 addition & 1 deletion docs/antora.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: corva-sdk
version: ~
version: 1.14.2
nav: [modules/ROOT/nav.adoc]
29 changes: 26 additions & 3 deletions src/corva/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from corva.api_utils import get_requests_session, get_retry_strategy
from corva.configuration import SETTINGS
from corva.logger import CORVA_LOGGER


class Api:
Expand All @@ -16,6 +17,8 @@ class Api:
convenient URL usage and reasonable timeouts to API requests.
"""

TIMEOUT_LIMITS = (3, 30) # seconds

def __init__(
self,
*,
Expand All @@ -24,20 +27,23 @@ def __init__(
api_key: str,
app_key: str,
app_connection_id: Optional[int] = None,
max_retries: Optional[int] = 3,
max_retries: Optional[int] = 0,
backoff_factor_retries: Optional[float] = 1,
pool_conn_count: Optional[int] = None,
pool_max_size: Optional[int] = None,
pool_block: Optional[bool] = None,
timeout: Optional[int] = None,
):
self.api_url = api_url
self.data_api_url = data_api_url
self.api_key = api_key
self.app_key = app_key
self.app_connection_id = app_connection_id
self.timeout = timeout or self.TIMEOUT_LIMITS[1]
self._max_retries = max_retries or SETTINGS.MAX_RETRY_COUNT
self._session = get_requests_session(
retry_strategy=get_retry_strategy(
max_retries=max_retries or SETTINGS.MAX_RETRY_COUNT,
max_retries=self._max_retries,
backoff_factor=backoff_factor_retries or SETTINGS.BACKOFF_FACTOR,
),
pool_connections_count=(pool_conn_count or SETTINGS.POOL_CONNECTIONS_COUNT),
Expand All @@ -52,6 +58,22 @@ def default_headers(self):
"X-Corva-App": self.app_key,
}

@property
def max_retries(self) -> int:
return self._max_retries

@max_retries.setter
def max_retries(self, value: int):
"""
max_retries are passed into Session object, so modifying it here won't have
any effect, raise warning and quit
"""
CORVA_LOGGER.warning(
"Do not modify max_retries attribute in existing object, create new Api "
"object with your custom max_retries param or set MAX_RETRY_COUNT env "
"variable in your environment"
)

def get(self, path: str, **kwargs):
return self._request("GET", path, **kwargs)

Expand Down Expand Up @@ -113,14 +135,15 @@ def _execute_request(
Returns:
requests.Response instance.
"""
_timeout = timeout or self.timeout

return self._session.request(
method=method,
url=url,
params=params,
json=data,
headers=headers,
timeout=timeout,
timeout=_timeout,
)

def _request(
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "1.14.1"
VERSION = "1.14.2"