Skip to content

Commit 1e02178

Browse files
authored
fix: async client options default values (#937)
1 parent e1e0fb2 commit 1e02178

File tree

7 files changed

+127
-9
lines changed

7 files changed

+127
-9
lines changed

supabase/__init__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
# Async Client
1818
from ._async.auth_client import AsyncSupabaseAuthClient as ASupabaseAuthClient
19+
from ._async.client import AsyncClient
1920
from ._async.client import AsyncClient as AClient
2021
from ._async.client import AsyncStorageClient as ASupabaseStorageClient
21-
from ._async.client import ClientOptions as AClientOptions
2222
from ._async.client import create_client as acreate_client
2323
from ._async.client import create_client as create_async_client
2424

@@ -29,7 +29,9 @@
2929
from ._sync.client import create_client
3030

3131
# Lib
32-
from .lib.client_options import ClientOptions
32+
from .lib.client_options import AsyncClientOptions
33+
from .lib.client_options import AsyncClientOptions as AClientOptions
34+
from .lib.client_options import SyncClientOptions as ClientOptions
3335

3436
# Version
3537
from .version import __version__
@@ -41,6 +43,8 @@
4143
"ASupabaseAuthClient",
4244
"ASupabaseStorageClient",
4345
"AClientOptions",
46+
"AsyncClient",
47+
"AsyncClientOptions",
4448
"create_client",
4549
"Client",
4650
"SupabaseAuthClient",

supabase/_async/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
1717
from supafunc import AsyncFunctionsClient
1818

19-
from ..lib.client_options import ClientOptions
19+
from ..lib.client_options import AsyncClientOptions as ClientOptions
2020
from .auth_client import AsyncSupabaseAuthClient
2121

2222

supabase/_sync/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
1616
from supafunc import SyncFunctionsClient
1717

18-
from ..lib.client_options import ClientOptions
18+
from ..lib.client_options import SyncClientOptions as ClientOptions
1919
from .auth_client import SyncSupabaseAuthClient
2020

2121

supabase/client.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
from gotrue.errors import (
2+
AuthApiError,
3+
AuthError,
4+
AuthImplicitGrantRedirectError,
5+
AuthInvalidCredentialsError,
6+
AuthRetryableError,
7+
AuthSessionMissingError,
8+
AuthUnknownError,
9+
AuthWeakPasswordError,
10+
)
111
from postgrest import APIError as PostgrestAPIError
212
from postgrest import APIResponse as PostgrestAPIResponse
13+
from realtime import AuthorizationError, NotConnectedError
314
from storage3.utils import StorageException
15+
from supafunc.errors import FunctionsError, FunctionsHttpError, FunctionsRelayError
416

517
# Async Client
618
from ._async.auth_client import AsyncSupabaseAuthClient
719
from ._async.client import AsyncClient
820
from ._async.client import AsyncStorageClient as AsyncSupabaseStorageClient
21+
from ._async.client import create_client as acreate_client
922
from ._async.client import create_client as create_async_client
1023

1124
# Sync Client
@@ -15,15 +28,20 @@
1528
from ._sync.client import create_client
1629

1730
# Lib
18-
from .lib.client_options import ClientOptions
31+
from .lib.client_options import AsyncClientOptions
32+
from .lib.client_options import AsyncClientOptions as AClientOptions
33+
from .lib.client_options import SyncClientOptions as ClientOptions
1934

2035
# Version
2136
from .version import __version__
2237

2338
__all__ = [
2439
"AsyncSupabaseAuthClient",
40+
"acreate_client",
2541
"create_async_client",
42+
"AClientOptions",
2643
"AsyncClient",
44+
"AsyncClientOptions",
2745
"AsyncSupabaseStorageClient",
2846
"SupabaseAuthClient",
2947
"create_client",
@@ -34,4 +52,17 @@
3452
"PostgrestAPIResponse",
3553
"StorageException",
3654
"__version__",
55+
"AuthApiError",
56+
"AuthError",
57+
"AuthImplicitGrantRedirectError",
58+
"AuthInvalidCredentialsError",
59+
"AuthRetryableError",
60+
"AuthSessionMissingError",
61+
"AuthWeakPasswordError",
62+
"AuthUnknownError",
63+
"FunctionsHttpError",
64+
"FunctionsRelayError",
65+
"FunctionsError",
66+
"AuthorizationError",
67+
"NotConnectedError",
3768
]

supabase/lib/client_options.py

+85-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
from dataclasses import dataclass, field
22
from typing import Any, Dict, Optional, Union
33

4-
from gotrue import AuthFlowType, SyncMemoryStorage, SyncSupportedStorage
4+
from gotrue import (
5+
AsyncMemoryStorage,
6+
AuthFlowType,
7+
SyncMemoryStorage,
8+
SyncSupportedStorage,
9+
)
510
from httpx import Timeout
611
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
712
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
@@ -85,3 +90,82 @@ def replace(
8590
)
8691
client_options.flow_type = flow_type or self.flow_type
8792
return client_options
93+
94+
95+
@dataclass
96+
class AsyncClientOptions(ClientOptions):
97+
storage: SyncSupportedStorage = field(default_factory=AsyncMemoryStorage)
98+
"""A storage provider. Used to store the logged in session."""
99+
100+
def replace(
101+
self,
102+
schema: Optional[str] = None,
103+
headers: Optional[Dict[str, str]] = None,
104+
auto_refresh_token: Optional[bool] = None,
105+
persist_session: Optional[bool] = None,
106+
storage: Optional[SyncSupportedStorage] = None,
107+
realtime: Optional[Dict[str, Any]] = None,
108+
postgrest_client_timeout: Union[
109+
int, float, Timeout
110+
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
111+
storage_client_timeout: Union[
112+
int, float, Timeout
113+
] = DEFAULT_STORAGE_CLIENT_TIMEOUT,
114+
flow_type: Optional[AuthFlowType] = None,
115+
) -> "AsyncClientOptions":
116+
"""Create a new SupabaseClientOptions with changes"""
117+
client_options = AsyncClientOptions()
118+
client_options.schema = schema or self.schema
119+
client_options.headers = headers or self.headers
120+
client_options.auto_refresh_token = (
121+
auto_refresh_token or self.auto_refresh_token
122+
)
123+
client_options.persist_session = persist_session or self.persist_session
124+
client_options.storage = storage or self.storage
125+
client_options.realtime = realtime or self.realtime
126+
client_options.postgrest_client_timeout = (
127+
postgrest_client_timeout or self.postgrest_client_timeout
128+
)
129+
client_options.storage_client_timeout = (
130+
storage_client_timeout or self.storage_client_timeout
131+
)
132+
client_options.flow_type = flow_type or self.flow_type
133+
return client_options
134+
135+
136+
@dataclass
137+
class SyncClientOptions(ClientOptions):
138+
def replace(
139+
self,
140+
schema: Optional[str] = None,
141+
headers: Optional[Dict[str, str]] = None,
142+
auto_refresh_token: Optional[bool] = None,
143+
persist_session: Optional[bool] = None,
144+
storage: Optional[SyncSupportedStorage] = None,
145+
realtime: Optional[Dict[str, Any]] = None,
146+
postgrest_client_timeout: Union[
147+
int, float, Timeout
148+
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
149+
storage_client_timeout: Union[
150+
int, float, Timeout
151+
] = DEFAULT_STORAGE_CLIENT_TIMEOUT,
152+
flow_type: Optional[AuthFlowType] = None,
153+
) -> "SyncClientOptions":
154+
"""Create a new SupabaseClientOptions with changes"""
155+
client_options = SyncClientOptions()
156+
client_options.schema = schema or self.schema
157+
client_options.headers = headers or self.headers
158+
client_options.auto_refresh_token = (
159+
auto_refresh_token or self.auto_refresh_token
160+
)
161+
client_options.persist_session = persist_session or self.persist_session
162+
client_options.storage = storage or self.storage
163+
client_options.realtime = realtime or self.realtime
164+
client_options.postgrest_client_timeout = (
165+
postgrest_client_timeout or self.postgrest_client_timeout
166+
)
167+
client_options.storage_client_timeout = (
168+
storage_client_timeout or self.storage_client_timeout
169+
)
170+
client_options.flow_type = flow_type or self.flow_type
171+
return client_options

tests/test_client.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
import pytest
88

9-
from supabase import Client, create_client
10-
from supabase.lib.client_options import ClientOptions
9+
from supabase import Client, ClientOptions, create_client
1110

1211

1312
@pytest.mark.xfail(

tests/test_client_options.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from gotrue import SyncMemoryStorage
22

3-
from supabase.lib.client_options import ClientOptions
3+
from supabase import ClientOptions
44

55

66
class TestClientOptions:

0 commit comments

Comments
 (0)