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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v1.17.2
- Added configurable request timeout to `ParclLabsClient`. Defaults to 10s connect / 90s read. Customizable via the `timeout` parameter on client instantiation.

### v1.17.1
- Fix mutable default parameters in `property.search.retrieve` and `property_v2.search.retrieve` functions.

Expand Down
2 changes: 1 addition & 1 deletion parcllabs/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "1.17.1"
VERSION = "1.17.2"
2 changes: 2 additions & 0 deletions parcllabs/parcllabs_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(
api_url: str = api_base,
limit: int | None = None,
num_workers: int | None = None,
timeout: tuple[float, float] | float | None = (10, 90),
) -> None:
if not api_key:
raise ValueError(NO_API_KEY_ERROR)
Expand All @@ -53,6 +54,7 @@ def __init__(
self.account_info = {"est_session_credits_used": 0}
self.num_workers = num_workers
self.limit = limit
self.timeout = timeout

self._initialize_services()

Expand Down
11 changes: 7 additions & 4 deletions parcllabs/services/parcllabs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ def _make_request(self, method: str, url: str, **kwargs: dict) -> requests.Respo
if method == GET_METHOD:
params = kwargs.get("params", {})
kwargs["params"] = params

response = requests.request(method, url, headers=self.headers, **kwargs) # noqa: S113
response = requests.request(
method,
url,
headers=self.headers,
timeout=self.client.timeout,
**kwargs,
)
response.raise_for_status()
except requests.exceptions.HTTPError:
self.error_handling(response)
Expand Down Expand Up @@ -175,8 +180,6 @@ def _fetch(
data = {"parcl_id": [str(pid) for pid in parcl_ids], **params}
params = {"limit": params["limit"]} if params.get("limit") else {}

print(f"data: {data}, params: {params}")

return self._fetch_post(params, data, auto_paginate)
if params.get("limit"):
params["limit"] = self._validate_limit(GET_METHOD, params["limit"])
Expand Down
1 change: 1 addition & 0 deletions tests/test_parcl_labs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self) -> None:
self.api_url = "https://api.example.com/"
self.api_key = "test_api_key"
self.account_info = {"est_session_credits_used": 0}
self.timeout = (10, 90)


@pytest.fixture
Expand Down
3 changes: 3 additions & 0 deletions tests/test_price_feed_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def service(self) -> ParclLabsService:
mock_client.api_key = "test_api_key"
mock_client.turbo_mode = False
mock_client.estimated_session_credit_usage = 0
mock_client.timeout = (10, 90)
return ParclLabsService("/test", mock_client)

def test_init(self, service: ParclLabsService) -> None:
Expand Down Expand Up @@ -53,6 +54,7 @@ def test_make_request_get(self, mock_request: Mock, service: ParclLabsService) -
"https://api.example.com/test",
headers=service.headers,
params={},
timeout=(10, 90),
)

@patch("requests.request")
Expand All @@ -71,6 +73,7 @@ def test_make_request_post(self, mock_request: Mock, service: ParclLabsService)
"https://api.example.com/test",
headers=service.headers,
json={"data": "test"},
timeout=(10, 90),
)

@patch("requests.request")
Expand Down
Loading