Skip to content

Commit 8217323

Browse files
adamtheturtleclaude
andcommitted
Accept tuple for request_timeout_seconds to match requests API
The timeout parameter now accepts either a float (applied to both connect and read timeouts) or a (connect, read) tuple, matching the requests library's timeout interface. Updated docstrings to reference requests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a0b073d commit 8217323

File tree

4 files changed

+67
-10
lines changed

4 files changed

+67
-10
lines changed

src/vws/query.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ def __init__(
4949
client_access_key: str,
5050
client_secret_key: str,
5151
base_vwq_url: str = "https://cloudreco.vuforia.com",
52-
request_timeout_seconds: float = 30.0,
52+
request_timeout_seconds: float | tuple[float, float] = 30.0,
5353
) -> None:
5454
"""
5555
Args:
5656
client_access_key: A VWS client access key.
5757
client_secret_key: A VWS client secret key.
5858
base_vwq_url: The base URL for the VWQ API.
59-
request_timeout_seconds: The timeout in seconds for each HTTP
60-
request made to the Cloud Reco API.
59+
request_timeout_seconds: The timeout for each HTTP request, as
60+
used by ``requests.request``. This can be a float to set
61+
both the connect and read timeouts, or a (connect, read)
62+
tuple.
6163
"""
6264
self._client_access_key = client_access_key
6365
self._client_secret_key = client_secret_key

src/vws/vws.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _target_api_request(
6868
data: bytes,
6969
request_path: str,
7070
base_vws_url: str,
71-
request_timeout_seconds: float,
71+
request_timeout_seconds: float | tuple[float, float],
7272
) -> Response:
7373
"""Make a request to the Vuforia Target API.
7474
@@ -83,7 +83,9 @@ def _target_api_request(
8383
request_path: The path to the endpoint which will be used in the
8484
request.
8585
base_vws_url: The base URL for the VWS API.
86-
request_timeout_seconds: The timeout in seconds for the request.
86+
request_timeout_seconds: The timeout for the request, as used by
87+
``requests.request``. This can be a float to set both the
88+
connect and read timeouts, or a (connect, read) tuple.
8789
8890
Returns:
8991
The response to the request made by `requests`.
@@ -135,15 +137,17 @@ def __init__(
135137
server_access_key: str,
136138
server_secret_key: str,
137139
base_vws_url: str = "https://vws.vuforia.com",
138-
request_timeout_seconds: float = 30.0,
140+
request_timeout_seconds: float | tuple[float, float] = 30.0,
139141
) -> None:
140142
"""
141143
Args:
142144
server_access_key: A VWS server access key.
143145
server_secret_key: A VWS server secret key.
144146
base_vws_url: The base URL for the VWS API.
145-
request_timeout_seconds: The timeout in seconds for each HTTP
146-
request made to the VWS API.
147+
request_timeout_seconds: The timeout for each HTTP request, as
148+
used by ``requests.request``. This can be a float to set
149+
both the connect and read timeouts, or a (connect, read)
150+
tuple.
147151
"""
148152
self._server_access_key = server_access_key
149153
self._server_secret_key = server_secret_key

tests/test_query.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_default_timeout() -> None:
6565

6666
@staticmethod
6767
def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:
68-
"""It is possible to set a custom request timeout."""
68+
"""It is possible to set a custom request timeout as a float."""
6969
with MockVWS() as mock:
7070
database = VuforiaDatabase()
7171
mock.add_database(database=database)
@@ -93,6 +93,35 @@ def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:
9393
matches = cloud_reco_client.query(image=image)
9494
assert len(matches) == 1
9595

96+
@staticmethod
97+
def test_custom_timeout_tuple(image: io.BytesIO | BinaryIO) -> None:
98+
"""It is possible to set separate connect and read timeouts."""
99+
with MockVWS() as mock:
100+
database = VuforiaDatabase()
101+
mock.add_database(database=database)
102+
vws_client = VWS(
103+
server_access_key=database.server_access_key,
104+
server_secret_key=database.server_secret_key,
105+
)
106+
custom_timeout = (5.0, 30.0)
107+
cloud_reco_client = CloudRecoService(
108+
client_access_key=database.client_access_key,
109+
client_secret_key=database.client_secret_key,
110+
request_timeout_seconds=custom_timeout,
111+
)
112+
assert cloud_reco_client.request_timeout_seconds == custom_timeout
113+
114+
target_id = vws_client.add_target(
115+
name="x",
116+
width=1,
117+
image=image,
118+
active_flag=True,
119+
application_metadata=None,
120+
)
121+
vws_client.wait_for_target_processed(target_id=target_id)
122+
matches = cloud_reco_client.query(image=image)
123+
assert len(matches) == 1
124+
96125
@staticmethod
97126
def test_timeout_raises_on_slow_response(
98127
image: io.BytesIO | BinaryIO,

tests/test_vws.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_default_timeout() -> None:
114114

115115
@staticmethod
116116
def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:
117-
"""It is possible to set a custom request timeout."""
117+
"""It is possible to set a custom request timeout as a float."""
118118
with MockVWS() as mock:
119119
database = VuforiaDatabase()
120120
mock.add_database(database=database)
@@ -135,6 +135,28 @@ def test_custom_timeout(image: io.BytesIO | BinaryIO) -> None:
135135
application_metadata=None,
136136
)
137137

138+
@staticmethod
139+
def test_custom_timeout_tuple(image: io.BytesIO | BinaryIO) -> None:
140+
"""It is possible to set separate connect and read timeouts."""
141+
with MockVWS() as mock:
142+
database = VuforiaDatabase()
143+
mock.add_database(database=database)
144+
custom_timeout = (5.0, 30.0)
145+
vws_client = VWS(
146+
server_access_key=database.server_access_key,
147+
server_secret_key=database.server_secret_key,
148+
request_timeout_seconds=custom_timeout,
149+
)
150+
assert vws_client.request_timeout_seconds == custom_timeout
151+
152+
vws_client.add_target(
153+
name="x",
154+
width=1,
155+
image=image,
156+
active_flag=True,
157+
application_metadata=None,
158+
)
159+
138160
@staticmethod
139161
def test_timeout_raises_on_slow_response(
140162
image: io.BytesIO | BinaryIO,

0 commit comments

Comments
 (0)