Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 436121f

Browse files
authored
Merge pull request #66 from supabase-community/j0/add_timeout
fix: add configurable timeout
2 parents afb57e7 + 2edbd6b commit 436121f

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

storage3/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from storage3._async import AsyncStorageClient
88
from storage3._sync import SyncStorageClient
9+
from storage3.constants import DEFAULT_TIMEOUT
910
from storage3.utils import __version__
1011

1112
__all__ = ["create_client", "__version__"]
@@ -26,9 +27,9 @@ def create_client(
2627

2728

2829
def create_client(
29-
url: str, headers: dict[str, str], *, is_async: bool
30+
url: str, headers: dict[str, str], *, is_async: bool, timeout: int = DEFAULT_TIMEOUT
3031
) -> Union[AsyncStorageClient, SyncStorageClient]:
3132
if is_async:
32-
return AsyncStorageClient(url, headers)
33+
return AsyncStorageClient(url, headers, timeout)
3334
else:
34-
return SyncStorageClient(url, headers)
35+
return SyncStorageClient(url, headers, timeout)

storage3/_async/client.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from storage3.constants import DEFAULT_TIMEOUT
4+
35
from ..utils import AsyncClient, __version__
46
from .bucket import AsyncStorageBucketAPI
57
from .file_api import AsyncBucketProxy
@@ -13,26 +15,19 @@ class AsyncStorageClient(AsyncStorageBucketAPI):
1315
"""Manage storage buckets and files."""
1416

1517
def __init__(
16-
self,
17-
url: str,
18-
headers: dict[str, str],
18+
self, url: str, headers: dict[str, str], timeout: int = DEFAULT_TIMEOUT
1919
) -> None:
2020
headers = {
2121
"User-Agent": f"supabase-py/storage3 v{__version__}",
2222
**headers,
2323
}
24-
self.session = self._create_session(url, headers)
24+
self.session = self._create_session(url, headers, timeout)
2525
super().__init__(self.session)
2626

2727
def _create_session(
28-
self,
29-
base_url: str,
30-
headers: dict[str, str],
28+
self, base_url: str, headers: dict[str, str], timeout: int
3129
) -> AsyncClient:
32-
return AsyncClient(
33-
base_url=base_url,
34-
headers=headers,
35-
)
30+
return AsyncClient(base_url=base_url, headers=headers, timeout=timeout)
3631

3732
async def __aenter__(self) -> AsyncStorageClient:
3833
return self

storage3/_sync/client.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from storage3.constants import DEFAULT_TIMEOUT
4+
35
from ..utils import SyncClient, __version__
46
from .bucket import SyncStorageBucketAPI
57
from .file_api import SyncBucketProxy
@@ -13,26 +15,19 @@ class SyncStorageClient(SyncStorageBucketAPI):
1315
"""Manage storage buckets and files."""
1416

1517
def __init__(
16-
self,
17-
url: str,
18-
headers: dict[str, str],
18+
self, url: str, headers: dict[str, str], timeout: int = DEFAULT_TIMEOUT
1919
) -> None:
2020
headers = {
2121
"User-Agent": f"supabase-py/storage3 v{__version__}",
2222
**headers,
2323
}
24-
self.session = self._create_session(url, headers)
24+
self.session = self._create_session(url, headers, timeout)
2525
super().__init__(self.session)
2626

2727
def _create_session(
28-
self,
29-
base_url: str,
30-
headers: dict[str, str],
28+
self, base_url: str, headers: dict[str, str], timeout: int
3129
) -> SyncClient:
32-
return SyncClient(
33-
base_url=base_url,
34-
headers=headers,
35-
)
30+
return SyncClient(base_url=base_url, headers=headers, timeout=timeout)
3631

3732
def __enter__(self) -> SyncStorageClient:
3833
return self

storage3/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
"content-type": "text/plain;charset=UTF-8",
1212
"x-upsert": "false",
1313
}
14+
15+
DEFAULT_TIMEOUT = 20

0 commit comments

Comments
 (0)