Skip to content
Closed
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
13 changes: 9 additions & 4 deletions supabase/client.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import Any, Dict
from typing import Any, Dict, Union

from httpx import Timeout
from postgrest import SyncFilterRequestBuilder, SyncPostgrestClient, SyncRequestBuilder
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT

from .lib.auth_client import SupabaseAuthClient
from .lib.client_options import ClientOptions
from .lib.storage_client import SupabaseStorageClient


class Client:
"""Supabase client class."""

Expand Down Expand Up @@ -152,10 +153,14 @@ def _init_supabase_auth_client(

@staticmethod
def _init_postgrest_client(
rest_url: str, supabase_key: str, headers: Dict[str, str], schema: str
rest_url: str,
supabase_key: str,
headers: Dict[str, str],
schema: str,
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT
) -> SyncPostgrestClient:
"""Private helper for creating an instance of the Postgrest client."""
client = SyncPostgrestClient(rest_url, headers=headers, schema=schema)
client = SyncPostgrestClient(rest_url, headers=headers, schema=schema, timeout=timeout)
client.auth(token=supabase_key)
return client

Expand Down
9 changes: 8 additions & 1 deletion supabase/lib/client_options.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, Optional
from typing import Any, Callable, Dict, Optional, Union

from gotrue import SyncMemoryStorage, SyncSupportedStorage
from httpx import Timeout
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT

from supabase import __version__

Expand Down Expand Up @@ -34,6 +36,9 @@ class ClientOptions:
fetch: Optional[Callable] = None
"""A custom `fetch` implementation."""

timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT
"""Timeout passed to the SyncPostgrestClient instance."""

def replace(
self,
schema: Optional[str] = None,
Expand All @@ -43,6 +48,7 @@ def replace(
local_storage: Optional[SyncSupportedStorage] = None,
realtime: Optional[Dict[str, Any]] = None,
fetch: Optional[Callable] = None,
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT
) -> "ClientOptions":
"""Create a new SupabaseClientOptions with changes"""
client_options = ClientOptions()
Expand All @@ -55,4 +61,5 @@ def replace(
client_options.local_storage = local_storage or self.local_storage
client_options.realtime = realtime or self.realtime
client_options.fetch = fetch or self.fetch
client_options.timeout = timeout or self.timeout
return client_options
2 changes: 2 additions & 0 deletions tests/test_client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test__client_options__replace__returns_updated_options():
persist_session=False,
local_storage=local_storage,
realtime={"key": "value"},
timeout=5
)

actual = options.replace(schema="new schema")
Expand All @@ -23,6 +24,7 @@ def test__client_options__replace__returns_updated_options():
persist_session=False,
local_storage=local_storage,
realtime={"key": "value"},
timeout=5
)

assert actual == expected
Expand Down