Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
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
7 changes: 4 additions & 3 deletions storage3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from storage3._async import AsyncStorageClient
from storage3._sync import SyncStorageClient
from storage3.constants import DEFAULT_TIMEOUT
from storage3.utils import __version__

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


def create_client(
url: str, headers: dict[str, str], *, is_async: bool
url: str, headers: dict[str, str], *, is_async: bool, timeout: int = DEFAULT_TIMEOUT
) -> Union[AsyncStorageClient, SyncStorageClient]:
if is_async:
return AsyncStorageClient(url, headers)
return AsyncStorageClient(url, headers, timeout)
else:
return SyncStorageClient(url, headers)
return SyncStorageClient(url, headers, timeout)
17 changes: 6 additions & 11 deletions storage3/_async/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from storage3.constants import DEFAULT_TIMEOUT

from ..utils import AsyncClient, __version__
from .bucket import AsyncStorageBucketAPI
from .file_api import AsyncBucketProxy
Expand All @@ -13,26 +15,19 @@ class AsyncStorageClient(AsyncStorageBucketAPI):
"""Manage storage buckets and files."""

def __init__(
self,
url: str,
headers: dict[str, str],
self, url: str, headers: dict[str, str], timeout: int = DEFAULT_TIMEOUT
) -> None:
headers = {
"User-Agent": f"supabase-py/storage3 v{__version__}",
**headers,
}
self.session = self._create_session(url, headers)
self.session = self._create_session(url, headers, timeout)
super().__init__(self.session)

def _create_session(
self,
base_url: str,
headers: dict[str, str],
self, base_url: str, headers: dict[str, str], timeout: int
) -> AsyncClient:
return AsyncClient(
base_url=base_url,
headers=headers,
)
return AsyncClient(base_url=base_url, headers=headers, timeout=timeout)

async def __aenter__(self) -> AsyncStorageClient:
return self
Expand Down
17 changes: 6 additions & 11 deletions storage3/_sync/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from storage3.constants import DEFAULT_TIMEOUT

from ..utils import SyncClient, __version__
from .bucket import SyncStorageBucketAPI
from .file_api import SyncBucketProxy
Expand All @@ -13,26 +15,19 @@ class SyncStorageClient(SyncStorageBucketAPI):
"""Manage storage buckets and files."""

def __init__(
self,
url: str,
headers: dict[str, str],
self, url: str, headers: dict[str, str], timeout: int = DEFAULT_TIMEOUT
) -> None:
headers = {
"User-Agent": f"supabase-py/storage3 v{__version__}",
**headers,
}
self.session = self._create_session(url, headers)
self.session = self._create_session(url, headers, timeout)
super().__init__(self.session)

def _create_session(
self,
base_url: str,
headers: dict[str, str],
self, base_url: str, headers: dict[str, str], timeout: int
) -> SyncClient:
return SyncClient(
base_url=base_url,
headers=headers,
)
return SyncClient(base_url=base_url, headers=headers, timeout=timeout)

def __enter__(self) -> SyncStorageClient:
return self
Expand Down
2 changes: 2 additions & 0 deletions storage3/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
"content-type": "text/plain;charset=UTF-8",
"x-upsert": "false",
}

DEFAULT_TIMEOUT = 20