Skip to content

Continuation of Pr/234: ran isort and black for tests #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 7, 2022
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
14 changes: 11 additions & 3 deletions supabase/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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
Expand Down Expand Up @@ -152,10 +154,16 @@ 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