supabase 2.32.0__tar.gz → 2.34.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: supabase
3
- Version: 2.32.0
3
+ Version: 2.34.0
4
4
  Summary: Supabase client for Python.
5
5
  Author: Joel Lee, Leon Fedden, Daniel Reinón García, Leynier Gutiérrez González, Anand, Andrew Smith
6
6
  Author-email: Joel Lee <joel@joellee.org>, Leon Fedden <leonfedden@gmail.com>, Daniel Reinón García <danielreinon@outlook.com>, Leynier Gutiérrez González <leynier41@gmail.com>, Andrew Smith <a.smith@silentworks.co.uk>
@@ -8,17 +8,17 @@ License-Expression: MIT
8
8
  License-File: LICENSE
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Dist: realtime==2.32.0
12
- Requires-Dist: supabase-functions==2.32.0
13
- Requires-Dist: storage3==2.32.0
14
- Requires-Dist: supabase-auth==2.32.0
15
- Requires-Dist: postgrest==2.32.0
11
+ Requires-Dist: realtime==2.34.0
12
+ Requires-Dist: supabase-functions==2.34.0
13
+ Requires-Dist: storage3==2.34.0
14
+ Requires-Dist: supabase-auth==2.34.0
15
+ Requires-Dist: postgrest==2.34.0
16
16
  Requires-Dist: httpx>=0.26,<0.29
17
17
  Requires-Dist: yarl>=1.22.0
18
- Requires-Dist: storage3[iceberg]==2.32.0 ; extra == 'iceberg'
18
+ Requires-Dist: storage3[iceberg]==2.34.0 ; extra == 'iceberg'
19
19
  Maintainer: Leonardo Santiago
20
20
  Maintainer-email: Leonardo Santiago <leonardo.santiago@supabase.io>
21
- Requires-Python: >=3.9
21
+ Requires-Python: >=3.11
22
22
  Project-URL: changelog, https://github.com/supabase/supabase-py/tree/main/CHANGELOG.md
23
23
  Project-URL: documentation, https://github.com/supabase/supabase-py/src/supabase
24
24
  Project-URL: homepage, https://github.com/supabase/supabase-py
@@ -37,7 +37,7 @@ Python client for [Supabase](https://supabase.com)
37
37
 
38
38
  ### PyPI installation
39
39
 
40
- Install the package (for Python >= 3.9):
40
+ Install the package (for Python >= 3.11):
41
41
 
42
42
  ```bash
43
43
  # with pip
@@ -50,6 +50,22 @@ uv add supabase
50
50
  conda install -c conda-forge supabase
51
51
  ```
52
52
 
53
+ ## Supabase Service Compatibility
54
+
55
+ `supabase` only guarantees compatibility with the latest release of each Supabase service, unless a minimum supported version is explicitly listed below.
56
+
57
+ Older service releases are supported on a best-effort basis, but compatibility is not guaranteed.
58
+
59
+ If you self-host Supabase, we recommend upgrading your services to their latest releases when upgrading the SDK.
60
+
61
+ | Service | SDK package | Server releases | Lowest supported version |
62
+ | --------- | ------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------ |
63
+ | Auth | [`supabase_auth`](https://pypi.org/project/supabase_auth) | [supabase/auth](https://github.com/supabase/auth/releases) | Latest release |
64
+ | Storage | [`storage3`](https://pypi.org/project/storage3) | [supabase/storage](https://github.com/supabase/storage/releases) | Latest release |
65
+ | Functions | [`supabase_functions`](https://pypi.org/project/supabase_functions) | [supabase/edge-runtime](https://github.com/supabase/edge-runtime/releases) | Latest release |
66
+ | PostgREST | [`postgrest`](https://pypi.org/project/postgrest) | [PostgREST/postgrest](https://github.com/PostgREST/postgrest/releases) | Latest release |
67
+ | Realtime | [`realtime`](https://pypi.org/project/realtime) | [supabase/realtime](https://github.com/supabase/realtime/releases) | Latest release |
68
+
53
69
  ## Usage
54
70
 
55
71
  Set your Supabase environment variables in a dotenv file, or using the shell:
@@ -9,7 +9,7 @@ Python client for [Supabase](https://supabase.com)
9
9
 
10
10
  ### PyPI installation
11
11
 
12
- Install the package (for Python >= 3.9):
12
+ Install the package (for Python >= 3.11):
13
13
 
14
14
  ```bash
15
15
  # with pip
@@ -22,6 +22,22 @@ uv add supabase
22
22
  conda install -c conda-forge supabase
23
23
  ```
24
24
 
25
+ ## Supabase Service Compatibility
26
+
27
+ `supabase` only guarantees compatibility with the latest release of each Supabase service, unless a minimum supported version is explicitly listed below.
28
+
29
+ Older service releases are supported on a best-effort basis, but compatibility is not guaranteed.
30
+
31
+ If you self-host Supabase, we recommend upgrading your services to their latest releases when upgrading the SDK.
32
+
33
+ | Service | SDK package | Server releases | Lowest supported version |
34
+ | --------- | ------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------ |
35
+ | Auth | [`supabase_auth`](https://pypi.org/project/supabase_auth) | [supabase/auth](https://github.com/supabase/auth/releases) | Latest release |
36
+ | Storage | [`storage3`](https://pypi.org/project/storage3) | [supabase/storage](https://github.com/supabase/storage/releases) | Latest release |
37
+ | Functions | [`supabase_functions`](https://pypi.org/project/supabase_functions) | [supabase/edge-runtime](https://github.com/supabase/edge-runtime/releases) | Latest release |
38
+ | PostgREST | [`postgrest`](https://pypi.org/project/postgrest) | [PostgREST/postgrest](https://github.com/PostgREST/postgrest/releases) | Latest release |
39
+ | Realtime | [`realtime`](https://pypi.org/project/realtime) | [supabase/realtime](https://github.com/supabase/realtime/releases) | Latest release |
40
+
25
41
  ## Usage
26
42
 
27
43
  Set your Supabase environment variables in a dotenv file, or using the shell:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "supabase"
3
- version = "2.32.0" # {x-release-please-version}
3
+ version = "2.34.0" # {x-release-please-version}
4
4
  description = "Supabase client for Python."
5
5
  authors = [
6
6
  { name = "Joel Lee", email = "joel@joellee.org" },
@@ -20,13 +20,13 @@ classifiers = [
20
20
  "Programming Language :: Python :: 3",
21
21
  "Operating System :: OS Independent"
22
22
  ]
23
- requires-python = ">=3.9"
23
+ requires-python = ">=3.11"
24
24
  dependencies = [
25
- "realtime == 2.32.0", # x-release-please-version
26
- "supabase_functions == 2.32.0", # x-release-please-version
27
- "storage3 == 2.32.0", # x-release-please-version
28
- "supabase_auth == 2.32.0", # x-release-please-version
29
- "postgrest == 2.32.0", # x-release-please-version
25
+ "realtime == 2.34.0", # x-release-please-version
26
+ "supabase_functions == 2.34.0", # x-release-please-version
27
+ "storage3 == 2.34.0", # x-release-please-version
28
+ "supabase_auth == 2.34.0", # x-release-please-version
29
+ "postgrest == 2.34.0", # x-release-please-version
30
30
  "httpx >=0.26,<0.29",
31
31
  "yarl>=1.22.0",
32
32
  ]
@@ -39,7 +39,7 @@ changelog = "https://github.com/supabase/supabase-py/tree/main/CHANGELOG.md"
39
39
 
40
40
  [project.optional-dependencies]
41
41
  iceberg = [
42
- "storage3[iceberg] == 2.32.0", # x-release-please-version
42
+ "storage3[iceberg] == 2.34.0", # x-release-please-version
43
43
  ]
44
44
 
45
45
  [dependency-groups]
@@ -50,7 +50,7 @@ dev = [
50
50
  tests = [
51
51
  "pytest >= 8.4.1",
52
52
  "pytest-cov >= 6.2.1",
53
- "pytest-asyncio >=0.24,<1.1",
53
+ "pytest-asyncio >=1.3.0",
54
54
  "python-dotenv >= 1.1.1",
55
55
  "mypy>=1.18.2",
56
56
  ]
@@ -62,24 +62,8 @@ lints = [
62
62
  [tool.uv]
63
63
  default-groups = [ "dev" ]
64
64
 
65
- [tool.ruff.lint]
66
- select = [
67
- # pycodestyle
68
- "E",
69
- # Pyflakes
70
- "F",
71
- # pyupgrade
72
- "UP",
73
- # flake8-bugbear
74
- "B",
75
- # flake8-simplify
76
- # "SIM",
77
- # isort
78
- "I",
79
- "ANN2"
80
- ]
81
- ignore = ["F403", "E501", "E402", "UP006", "UP035"]
82
-
65
+ [tool.ruff]
66
+ extend = "../../pyproject.toml"
83
67
 
84
68
  [build-system]
85
69
  requires = ["uv_build>=0.8.3,<0.9.0"]
@@ -1,5 +1,3 @@
1
- from typing import Dict, Optional
2
-
3
1
  from httpx import AsyncClient
4
2
  from supabase_auth import (
5
3
  AsyncGoTrueClient,
@@ -15,15 +13,15 @@ class AsyncSupabaseAuthClient(AsyncGoTrueClient):
15
13
  self,
16
14
  *,
17
15
  url: str,
18
- headers: Optional[Dict[str, str]] = None,
19
- storage_key: Optional[str] = None,
16
+ headers: dict[str, str] | None = None,
17
+ storage_key: str | None = None,
20
18
  auto_refresh_token: bool = True,
21
19
  persist_session: bool = True,
22
- storage: Optional[AsyncSupportedStorage] = None,
23
- http_client: Optional[AsyncClient] = None,
20
+ storage: AsyncSupportedStorage | None = None,
21
+ http_client: AsyncClient | None = None,
24
22
  flow_type: AuthFlowType = "implicit",
25
23
  verify: bool = True,
26
- proxy: Optional[str] = None,
24
+ proxy: str | None = None,
27
25
  ) -> None:
28
26
  """
29
27
  Instantiate a SupabaseAuthClient instance.
@@ -1,7 +1,7 @@
1
1
  import asyncio
2
2
  import copy
3
3
  import re
4
- from typing import Any, Dict, List, Optional, Union
4
+ from typing import Any
5
5
 
6
6
  from httpx import Timeout
7
7
  from postgrest import (
@@ -32,6 +32,13 @@ class SupabaseException(Exception):
32
32
  super().__init__(self.message)
33
33
 
34
34
 
35
+ def _validate_str_arg(name: str, value: object) -> None:
36
+ if value is not None and not isinstance(value, str):
37
+ raise SupabaseException(f"{name} must be a string, got {type(value).__name__}")
38
+ if not value:
39
+ raise SupabaseException(f"{name} is required")
40
+
41
+
35
42
  class AsyncClient:
36
43
  """Supabase client class."""
37
44
 
@@ -39,7 +46,7 @@ class AsyncClient:
39
46
  self,
40
47
  supabase_url: str,
41
48
  supabase_key: str,
42
- options: Optional[ClientOptions] = None,
49
+ options: ClientOptions | None = None,
43
50
  ) -> None:
44
51
  """Instantiate the client.
45
52
 
@@ -54,10 +61,8 @@ class AsyncClient:
54
61
  `DEFAULT_OPTIONS` dict.
55
62
  """
56
63
 
57
- if not supabase_url:
58
- raise SupabaseException("supabase_url is required")
59
- if not supabase_key:
60
- raise SupabaseException("supabase_key is required")
64
+ _validate_str_arg("supabase_url", supabase_url)
65
+ _validate_str_arg("supabase_key", supabase_key)
61
66
 
62
67
  # Check if the url and key are valid
63
68
  if not re.match(r"^(https?)://.+", supabase_url):
@@ -94,9 +99,10 @@ class AsyncClient:
94
99
  supabase_key=self.supabase_key,
95
100
  options=self.options.realtime if self.options else None,
96
101
  )
97
- self._postgrest: Optional[AsyncPostgrestClient] = None
98
- self._storage: Optional[AsyncStorageClient] = None
99
- self._functions: Optional[AsyncFunctionsClient] = None
102
+ self._postgrest: AsyncPostgrestClient | None = None
103
+ self._storage: AsyncStorageClient | None = None
104
+ self._functions: AsyncFunctionsClient | None = None
105
+ self._background_tasks: set[asyncio.Task[None]] = set()
100
106
  self.auth.on_auth_state_change(self._listen_to_auth_events)
101
107
 
102
108
  @classmethod
@@ -104,7 +110,7 @@ class AsyncClient:
104
110
  cls,
105
111
  supabase_url: str,
106
112
  supabase_key: str,
107
- options: Optional[ClientOptions] = None,
113
+ options: ClientOptions | None = None,
108
114
  ) -> "AsyncClient":
109
115
  auth_header = options.headers.get("Authorization") if options else None
110
116
  client = cls(supabase_url, supabase_key, options)
@@ -152,8 +158,8 @@ class AsyncClient:
152
158
  def rpc(
153
159
  self,
154
160
  fn: str,
155
- params: Optional[Dict[Any, Any]] = None,
156
- count: Optional[CountMethod] = None,
161
+ params: dict[Any, Any] | None = None,
162
+ count: CountMethod | None = None,
157
163
  head: bool = False,
158
164
  get: bool = False,
159
165
  ) -> AsyncRPCFilterRequestBuilder:
@@ -187,6 +193,7 @@ class AsyncClient:
187
193
  headers=self.options.headers,
188
194
  schema=self.options.schema,
189
195
  timeout=self.options.postgrest_client_timeout,
196
+ retry_enabled=self.options.postgrest_client_retry,
190
197
  http_client=self.options.httpx_client,
191
198
  )
192
199
 
@@ -219,12 +226,12 @@ class AsyncClient:
219
226
  return self._functions
220
227
 
221
228
  def channel(
222
- self, topic: str, params: Optional[RealtimeChannelOptions] = None
229
+ self, topic: str, params: RealtimeChannelOptions | None = None
223
230
  ) -> AsyncRealtimeChannel:
224
231
  """Creates a Realtime channel with Broadcast, Presence, and Postgres Changes."""
225
232
  return self.realtime.channel(topic, params or {})
226
233
 
227
- def get_channels(self) -> List[AsyncRealtimeChannel]:
234
+ def get_channels(self) -> list[AsyncRealtimeChannel]:
228
235
  """Returns all realtime channels."""
229
236
  return self.realtime.get_channels()
230
237
 
@@ -240,7 +247,7 @@ class AsyncClient:
240
247
  def _init_realtime_client(
241
248
  realtime_url: URL,
242
249
  supabase_key: str,
243
- options: Optional[RealtimeClientOptions] = None,
250
+ options: RealtimeClientOptions | None = None,
244
251
  ) -> AsyncRealtimeClient:
245
252
  realtime_options = options or {}
246
253
  """Private method for creating an instance of the realtime-py client."""
@@ -251,11 +258,11 @@ class AsyncClient:
251
258
  @staticmethod
252
259
  def _init_storage_client(
253
260
  storage_url: str,
254
- headers: Dict[str, str],
261
+ headers: dict[str, str],
255
262
  storage_client_timeout: int = DEFAULT_STORAGE_CLIENT_TIMEOUT,
256
263
  verify: bool = True,
257
- proxy: Optional[str] = None,
258
- http_client: Union[AsyncHttpxClient, None] = None,
264
+ proxy: str | None = None,
265
+ http_client: AsyncHttpxClient | None = None,
259
266
  ) -> AsyncStorageClient:
260
267
  if http_client is not None:
261
268
  # If an http client is provided, use it
@@ -276,7 +283,7 @@ class AsyncClient:
276
283
  auth_url: str,
277
284
  client_options: ClientOptions,
278
285
  verify: bool = True,
279
- proxy: Optional[str] = None,
286
+ proxy: str | None = None,
280
287
  ) -> AsyncSupabaseAuthClient:
281
288
  """Creates a wrapped instance of the GoTrue Client."""
282
289
  return AsyncSupabaseAuthClient(
@@ -294,18 +301,23 @@ class AsyncClient:
294
301
  @staticmethod
295
302
  def _init_postgrest_client(
296
303
  rest_url: str,
297
- headers: Dict[str, str],
304
+ headers: dict[str, str],
298
305
  schema: str,
299
- timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
306
+ timeout: int | float | Timeout = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
300
307
  verify: bool = True,
301
- proxy: Optional[str] = None,
302
- http_client: Union[AsyncHttpxClient, None] = None,
308
+ proxy: str | None = None,
309
+ http_client: AsyncHttpxClient | None = None,
310
+ retry_enabled: bool = True,
303
311
  ) -> AsyncPostgrestClient:
304
312
  """Private helper for creating an instance of the Postgrest client."""
305
313
  if http_client is not None:
306
314
  # If an http client is provided, use it
307
315
  return AsyncPostgrestClient(
308
- rest_url, headers=headers, schema=schema, http_client=http_client
316
+ rest_url,
317
+ headers=headers,
318
+ schema=schema,
319
+ http_client=http_client,
320
+ retry_enabled=retry_enabled,
309
321
  )
310
322
  return AsyncPostgrestClient(
311
323
  rest_url,
@@ -315,12 +327,13 @@ class AsyncClient:
315
327
  verify=verify,
316
328
  proxy=proxy,
317
329
  http_client=None,
330
+ retry_enabled=retry_enabled,
318
331
  )
319
332
 
320
333
  def _create_auth_header(self, token: str) -> str:
321
334
  return f"Bearer {token}"
322
335
 
323
- def _get_auth_headers(self, authorization: Optional[str] = None) -> Dict[str, str]:
336
+ def _get_auth_headers(self, authorization: str | None = None) -> dict[str, str]:
324
337
  if authorization is None:
325
338
  authorization = self.options.headers.get(
326
339
  "Authorization", self._create_auth_header(self.supabase_key)
@@ -333,25 +346,26 @@ class AsyncClient:
333
346
  }
334
347
 
335
348
  def _listen_to_auth_events(
336
- self, event: AuthChangeEvent, session: Optional[Session]
349
+ self, event: AuthChangeEvent, session: Session | None
337
350
  ) -> None:
338
- access_token = self.supabase_key
339
- if event in ["SIGNED_IN", "TOKEN_REFRESHED", "SIGNED_OUT"]:
340
- # reset postgrest and storage instance on event change
341
- self._postgrest = None
342
- self._storage = None
343
- self._functions = None
344
- access_token = session.access_token if session else self.supabase_key
351
+ # Every event except SIGNED_OUT carries the current session, including
352
+ # USER_UPDATED and MFA_CHALLENGE_VERIFIED, whose token can carry new claims (aal2).
353
+ self._postgrest = None
354
+ self._storage = None
355
+ self._functions = None
356
+ access_token = session.access_token if session else self.supabase_key
345
357
  auth_header = self._create_auth_header(access_token)
346
358
  self.options.headers["Authorization"] = auth_header
347
359
  self.auth._headers["Authorization"] = auth_header
348
- asyncio.create_task(self.realtime.set_auth(access_token))
360
+ task = asyncio.create_task(self.realtime.set_auth(access_token))
361
+ self._background_tasks.add(task)
362
+ task.add_done_callback(self._background_tasks.discard)
349
363
 
350
364
 
351
365
  async def create_client(
352
366
  supabase_url: str,
353
367
  supabase_key: str,
354
- options: Optional[ClientOptions] = None,
368
+ options: ClientOptions | None = None,
355
369
  ) -> AsyncClient:
356
370
  """Create client function to instantiate supabase client like JS runtime.
357
371
 
@@ -1,5 +1,3 @@
1
- from typing import Dict, Optional
2
-
3
1
  from httpx import Client
4
2
  from supabase_auth import (
5
3
  AuthFlowType,
@@ -15,15 +13,15 @@ class SyncSupabaseAuthClient(SyncGoTrueClient):
15
13
  self,
16
14
  *,
17
15
  url: str,
18
- headers: Optional[Dict[str, str]] = None,
19
- storage_key: Optional[str] = None,
16
+ headers: dict[str, str] | None = None,
17
+ storage_key: str | None = None,
20
18
  auto_refresh_token: bool = True,
21
19
  persist_session: bool = True,
22
- storage: Optional[SyncSupportedStorage] = None,
23
- http_client: Optional[Client] = None,
20
+ storage: SyncSupportedStorage | None = None,
21
+ http_client: Client | None = None,
24
22
  flow_type: AuthFlowType = "implicit",
25
23
  verify: bool = True,
26
- proxy: Optional[str] = None,
24
+ proxy: str | None = None,
27
25
  ) -> None:
28
26
  """
29
27
  Instantiate a SupabaseAuthClient instance.
@@ -1,6 +1,6 @@
1
1
  import copy
2
2
  import re
3
- from typing import Any, Dict, List, Optional, Union
3
+ from typing import Any
4
4
 
5
5
  from httpx import Timeout
6
6
  from postgrest import (
@@ -31,6 +31,13 @@ class SupabaseException(Exception):
31
31
  super().__init__(self.message)
32
32
 
33
33
 
34
+ def _validate_str_arg(name: str, value: object) -> None:
35
+ if value is not None and not isinstance(value, str):
36
+ raise SupabaseException(f"{name} must be a string, got {type(value).__name__}")
37
+ if not value:
38
+ raise SupabaseException(f"{name} is required")
39
+
40
+
34
41
  class Client:
35
42
  """Supabase client class."""
36
43
 
@@ -38,7 +45,7 @@ class Client:
38
45
  self,
39
46
  supabase_url: str,
40
47
  supabase_key: str,
41
- options: Optional[ClientOptions] = None,
48
+ options: ClientOptions | None = None,
42
49
  ) -> None:
43
50
  """Instantiate the client.
44
51
 
@@ -53,10 +60,8 @@ class Client:
53
60
  `DEFAULT_OPTIONS` dict.
54
61
  """
55
62
 
56
- if not supabase_url:
57
- raise SupabaseException("supabase_url is required")
58
- if not supabase_key:
59
- raise SupabaseException("supabase_key is required")
63
+ _validate_str_arg("supabase_url", supabase_url)
64
+ _validate_str_arg("supabase_key", supabase_key)
60
65
 
61
66
  # Check if the url and key are valid
62
67
  if not re.match(r"^(https?)://.+", supabase_url):
@@ -93,9 +98,9 @@ class Client:
93
98
  supabase_key=self.supabase_key,
94
99
  options=self.options.realtime if self.options else None,
95
100
  )
96
- self._postgrest: Optional[SyncPostgrestClient] = None
97
- self._storage: Optional[SyncStorageClient] = None
98
- self._functions: Optional[SyncFunctionsClient] = None
101
+ self._postgrest: SyncPostgrestClient | None = None
102
+ self._storage: SyncStorageClient | None = None
103
+ self._functions: SyncFunctionsClient | None = None
99
104
  self.auth.on_auth_state_change(self._listen_to_auth_events)
100
105
 
101
106
  @classmethod
@@ -103,7 +108,7 @@ class Client:
103
108
  cls,
104
109
  supabase_url: str,
105
110
  supabase_key: str,
106
- options: Optional[ClientOptions] = None,
111
+ options: ClientOptions | None = None,
107
112
  ) -> "Client":
108
113
  auth_header = options.headers.get("Authorization") if options else None
109
114
  client = cls(supabase_url, supabase_key, options)
@@ -151,8 +156,8 @@ class Client:
151
156
  def rpc(
152
157
  self,
153
158
  fn: str,
154
- params: Optional[Dict[Any, Any]] = None,
155
- count: Optional[CountMethod] = None,
159
+ params: dict[Any, Any] | None = None,
160
+ count: CountMethod | None = None,
156
161
  head: bool = False,
157
162
  get: bool = False,
158
163
  ) -> SyncRPCFilterRequestBuilder:
@@ -186,6 +191,7 @@ class Client:
186
191
  headers=self.options.headers,
187
192
  schema=self.options.schema,
188
193
  timeout=self.options.postgrest_client_timeout,
194
+ retry_enabled=self.options.postgrest_client_retry,
189
195
  http_client=self.options.httpx_client,
190
196
  )
191
197
 
@@ -218,12 +224,12 @@ class Client:
218
224
  return self._functions
219
225
 
220
226
  def channel(
221
- self, topic: str, params: Optional[RealtimeChannelOptions] = None
227
+ self, topic: str, params: RealtimeChannelOptions | None = None
222
228
  ) -> SyncRealtimeChannel:
223
229
  """Creates a Realtime channel with Broadcast, Presence, and Postgres Changes."""
224
230
  return self.realtime.channel(topic, params or {})
225
231
 
226
- def get_channels(self) -> List[SyncRealtimeChannel]:
232
+ def get_channels(self) -> list[SyncRealtimeChannel]:
227
233
  """Returns all realtime channels."""
228
234
  return self.realtime.get_channels()
229
235
 
@@ -239,7 +245,7 @@ class Client:
239
245
  def _init_realtime_client(
240
246
  realtime_url: URL,
241
247
  supabase_key: str,
242
- options: Optional[RealtimeClientOptions] = None,
248
+ options: RealtimeClientOptions | None = None,
243
249
  ) -> SyncRealtimeClient:
244
250
  realtime_options = options or {}
245
251
  """Private method for creating an instance of the realtime-py client."""
@@ -250,11 +256,11 @@ class Client:
250
256
  @staticmethod
251
257
  def _init_storage_client(
252
258
  storage_url: str,
253
- headers: Dict[str, str],
259
+ headers: dict[str, str],
254
260
  storage_client_timeout: int = DEFAULT_STORAGE_CLIENT_TIMEOUT,
255
261
  verify: bool = True,
256
- proxy: Optional[str] = None,
257
- http_client: Union[SyncHttpxClient, None] = None,
262
+ proxy: str | None = None,
263
+ http_client: SyncHttpxClient | None = None,
258
264
  ) -> SyncStorageClient:
259
265
  if http_client is not None:
260
266
  # If an http client is provided, use it
@@ -275,7 +281,7 @@ class Client:
275
281
  auth_url: str,
276
282
  client_options: ClientOptions,
277
283
  verify: bool = True,
278
- proxy: Optional[str] = None,
284
+ proxy: str | None = None,
279
285
  ) -> SyncSupabaseAuthClient:
280
286
  """Creates a wrapped instance of the GoTrue Client."""
281
287
  return SyncSupabaseAuthClient(
@@ -293,18 +299,23 @@ class Client:
293
299
  @staticmethod
294
300
  def _init_postgrest_client(
295
301
  rest_url: str,
296
- headers: Dict[str, str],
302
+ headers: dict[str, str],
297
303
  schema: str,
298
- timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
304
+ timeout: int | float | Timeout = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
299
305
  verify: bool = True,
300
- proxy: Optional[str] = None,
301
- http_client: Union[SyncHttpxClient, None] = None,
306
+ proxy: str | None = None,
307
+ http_client: SyncHttpxClient | None = None,
308
+ retry_enabled: bool = True,
302
309
  ) -> SyncPostgrestClient:
303
310
  """Private helper for creating an instance of the Postgrest client."""
304
311
  if http_client is not None:
305
312
  # If an http client is provided, use it
306
313
  return SyncPostgrestClient(
307
- rest_url, headers=headers, schema=schema, http_client=http_client
314
+ rest_url,
315
+ headers=headers,
316
+ schema=schema,
317
+ http_client=http_client,
318
+ retry_enabled=retry_enabled,
308
319
  )
309
320
  return SyncPostgrestClient(
310
321
  rest_url,
@@ -314,12 +325,13 @@ class Client:
314
325
  verify=verify,
315
326
  proxy=proxy,
316
327
  http_client=None,
328
+ retry_enabled=retry_enabled,
317
329
  )
318
330
 
319
331
  def _create_auth_header(self, token: str) -> str:
320
332
  return f"Bearer {token}"
321
333
 
322
- def _get_auth_headers(self, authorization: Optional[str] = None) -> Dict[str, str]:
334
+ def _get_auth_headers(self, authorization: str | None = None) -> dict[str, str]:
323
335
  if authorization is None:
324
336
  authorization = self.options.headers.get(
325
337
  "Authorization", self._create_auth_header(self.supabase_key)
@@ -332,15 +344,14 @@ class Client:
332
344
  }
333
345
 
334
346
  def _listen_to_auth_events(
335
- self, event: AuthChangeEvent, session: Optional[Session]
347
+ self, event: AuthChangeEvent, session: Session | None
336
348
  ) -> None:
337
- access_token = self.supabase_key
338
- if event in ["SIGNED_IN", "TOKEN_REFRESHED", "SIGNED_OUT"]:
339
- # reset postgrest and storage instance on event change
340
- self._postgrest = None
341
- self._storage = None
342
- self._functions = None
343
- access_token = session.access_token if session else self.supabase_key
349
+ # Every event except SIGNED_OUT carries the current session, including
350
+ # USER_UPDATED and MFA_CHALLENGE_VERIFIED, whose token can carry new claims (aal2).
351
+ self._postgrest = None
352
+ self._storage = None
353
+ self._functions = None
354
+ access_token = session.access_token if session else self.supabase_key
344
355
  auth_header = self._create_auth_header(access_token)
345
356
  self.options.headers["Authorization"] = auth_header
346
357
  self.auth._headers["Authorization"] = auth_header
@@ -349,7 +360,7 @@ class Client:
349
360
  def create_client(
350
361
  supabase_url: str,
351
362
  supabase_key: str,
352
- options: Optional[ClientOptions] = None,
363
+ options: ClientOptions | None = None,
353
364
  ) -> Client:
354
365
  """Create client function to instantiate supabase client like JS runtime.
355
366
 
@@ -0,0 +1,12 @@
1
+ import supabase as _package
2
+
3
+ from . import *
4
+ from ._async.auth_client import AsyncSupabaseAuthClient as AsyncSupabaseAuthClient
5
+ from ._async.client import AsyncStorageClient as _AsyncStorageClient
6
+
7
+ AsyncSupabaseStorageClient = _AsyncStorageClient
8
+
9
+ __all__ = _package.__all__ + (
10
+ "AsyncSupabaseAuthClient",
11
+ "AsyncSupabaseStorageClient",
12
+ )
@@ -1,6 +1,5 @@
1
1
  import platform
2
2
  from dataclasses import dataclass, field
3
- from typing import Dict, Optional, Union
4
3
 
5
4
  from httpx import AsyncClient as AsyncHttpxClient
6
5
  from httpx import Client as SyncHttpxClient
@@ -39,7 +38,7 @@ class ClientOptions:
39
38
  Must be on the list of exposed schemas in Supabase. Defaults to 'public'.
40
39
  """
41
40
 
42
- headers: Dict[str, str] = field(default_factory=DEFAULT_HEADERS.copy)
41
+ headers: dict[str, str] = field(default_factory=DEFAULT_HEADERS.copy)
43
42
  """Optional headers for initializing the client."""
44
43
 
45
44
  auto_refresh_token: bool = True
@@ -48,14 +47,15 @@ class ClientOptions:
48
47
  persist_session: bool = True
49
48
  """Whether to persist a logged in session to storage."""
50
49
 
51
- realtime: Optional[RealtimeClientOptions] = None
50
+ realtime: RealtimeClientOptions | None = None
52
51
  """Options passed to the realtime-py instance"""
53
52
 
54
- postgrest_client_timeout: Union[int, float, Timeout] = (
55
- DEFAULT_POSTGREST_CLIENT_TIMEOUT
56
- )
53
+ postgrest_client_timeout: int | float | Timeout = DEFAULT_POSTGREST_CLIENT_TIMEOUT
57
54
  """Timeout passed to the SyncPostgrestClient instance."""
58
55
 
56
+ postgrest_client_retry: bool = True
57
+ """Automatically retry transient PostgREST errors. Passed to the SyncPostgrestClient instance."""
58
+
59
59
  storage_client_timeout: int = DEFAULT_STORAGE_CLIENT_TIMEOUT
60
60
  """Timeout passed to the SyncStorageClient instance"""
61
61
 
@@ -71,23 +71,23 @@ class AsyncClientOptions(ClientOptions):
71
71
  storage: AsyncSupportedStorage = field(default_factory=AsyncMemoryStorage)
72
72
  """A storage provider. Used to store the logged in session."""
73
73
 
74
- httpx_client: Optional[AsyncHttpxClient] = None
74
+ httpx_client: AsyncHttpxClient | None = None
75
75
  """httpx client instance to be used by the PostgREST, functions, auth and storage clients."""
76
76
 
77
77
  def replace(
78
78
  self,
79
- schema: Optional[str] = None,
80
- headers: Optional[Dict[str, str]] = None,
81
- auto_refresh_token: Optional[bool] = None,
82
- persist_session: Optional[bool] = None,
83
- storage: Optional[AsyncSupportedStorage] = None,
84
- realtime: Optional[RealtimeClientOptions] = None,
85
- httpx_client: Optional[AsyncHttpxClient] = None,
86
- postgrest_client_timeout: Union[
87
- int, float, Timeout
88
- ] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
89
- storage_client_timeout: int = DEFAULT_STORAGE_CLIENT_TIMEOUT,
90
- flow_type: Optional[AuthFlowType] = None,
79
+ schema: str | None = None,
80
+ headers: dict[str, str] | None = None,
81
+ auto_refresh_token: bool | None = None,
82
+ persist_session: bool | None = None,
83
+ storage: AsyncSupportedStorage | None = None,
84
+ realtime: RealtimeClientOptions | None = None,
85
+ httpx_client: AsyncHttpxClient | None = None,
86
+ postgrest_client_timeout: int | float | Timeout | None = None,
87
+ postgrest_client_retry: bool | None = None,
88
+ storage_client_timeout: int | None = None,
89
+ flow_type: AuthFlowType | None = None,
90
+ function_client_timeout: int | None = None,
91
91
  ) -> "AsyncClientOptions":
92
92
  """Create a new SupabaseClientOptions with changes"""
93
93
  client_options = AsyncClientOptions()
@@ -105,12 +105,26 @@ class AsyncClientOptions(ClientOptions):
105
105
  client_options.realtime = realtime or self.realtime
106
106
  client_options.httpx_client = httpx_client or self.httpx_client
107
107
  client_options.postgrest_client_timeout = (
108
- postgrest_client_timeout or self.postgrest_client_timeout
108
+ postgrest_client_timeout
109
+ if postgrest_client_timeout is not None
110
+ else self.postgrest_client_timeout
111
+ )
112
+ client_options.postgrest_client_retry = (
113
+ postgrest_client_retry
114
+ if postgrest_client_retry is not None
115
+ else self.postgrest_client_retry
109
116
  )
110
117
  client_options.storage_client_timeout = (
111
- storage_client_timeout or self.storage_client_timeout
118
+ storage_client_timeout
119
+ if storage_client_timeout is not None
120
+ else self.storage_client_timeout
112
121
  )
113
122
  client_options.flow_type = flow_type or self.flow_type
123
+ client_options.function_client_timeout = (
124
+ function_client_timeout
125
+ if function_client_timeout is not None
126
+ else self.function_client_timeout
127
+ )
114
128
  return client_options
115
129
 
116
130
 
@@ -118,23 +132,23 @@ class AsyncClientOptions(ClientOptions):
118
132
  class SyncClientOptions(ClientOptions):
119
133
  storage: SyncSupportedStorage = field(default_factory=SyncMemoryStorage)
120
134
  """A storage provider. Used to store the logged in session."""
121
- httpx_client: Optional[SyncHttpxClient] = None
135
+ httpx_client: SyncHttpxClient | None = None
122
136
  """httpx client instance to be used by the PostgREST, functions, auth and storage clients."""
123
137
 
124
138
  def replace(
125
139
  self,
126
- schema: Optional[str] = None,
127
- headers: Optional[Dict[str, str]] = None,
128
- auto_refresh_token: Optional[bool] = None,
129
- persist_session: Optional[bool] = None,
130
- storage: Optional[SyncSupportedStorage] = None,
131
- realtime: Optional[RealtimeClientOptions] = None,
132
- httpx_client: Optional[SyncHttpxClient] = None,
133
- postgrest_client_timeout: Union[
134
- int, float, Timeout
135
- ] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
136
- storage_client_timeout: int = DEFAULT_STORAGE_CLIENT_TIMEOUT,
137
- flow_type: Optional[AuthFlowType] = None,
140
+ schema: str | None = None,
141
+ headers: dict[str, str] | None = None,
142
+ auto_refresh_token: bool | None = None,
143
+ persist_session: bool | None = None,
144
+ storage: SyncSupportedStorage | None = None,
145
+ realtime: RealtimeClientOptions | None = None,
146
+ httpx_client: SyncHttpxClient | None = None,
147
+ postgrest_client_timeout: int | float | Timeout | None = None,
148
+ postgrest_client_retry: bool | None = None,
149
+ storage_client_timeout: int | None = None,
150
+ flow_type: AuthFlowType | None = None,
151
+ function_client_timeout: int | None = None,
138
152
  ) -> "SyncClientOptions":
139
153
  """Create a new SupabaseClientOptions with changes"""
140
154
  client_options = SyncClientOptions()
@@ -152,10 +166,24 @@ class SyncClientOptions(ClientOptions):
152
166
  client_options.realtime = realtime or self.realtime
153
167
  client_options.httpx_client = httpx_client or self.httpx_client
154
168
  client_options.postgrest_client_timeout = (
155
- postgrest_client_timeout or self.postgrest_client_timeout
169
+ postgrest_client_timeout
170
+ if postgrest_client_timeout is not None
171
+ else self.postgrest_client_timeout
172
+ )
173
+ client_options.postgrest_client_retry = (
174
+ postgrest_client_retry
175
+ if postgrest_client_retry is not None
176
+ else self.postgrest_client_retry
156
177
  )
157
178
  client_options.storage_client_timeout = (
158
- storage_client_timeout or self.storage_client_timeout
179
+ storage_client_timeout
180
+ if storage_client_timeout is not None
181
+ else self.storage_client_timeout
159
182
  )
160
183
  client_options.flow_type = flow_type or self.flow_type
184
+ client_options.function_client_timeout = (
185
+ function_client_timeout
186
+ if function_client_timeout is not None
187
+ else self.function_client_timeout
188
+ )
161
189
  return client_options
@@ -0,0 +1 @@
1
+ __version__ = "2.34.0" # {x-release-please-version}
@@ -1,71 +0,0 @@
1
- from postgrest import APIError as PostgrestAPIError
2
- from postgrest import APIResponse as PostgrestAPIResponse
3
- from realtime import AuthorizationError, NotConnectedError
4
- from storage3.utils import StorageException
5
- from supabase_auth.errors import (
6
- AuthApiError,
7
- AuthError,
8
- AuthImplicitGrantRedirectError,
9
- AuthInvalidCredentialsError,
10
- AuthRetryableError,
11
- AuthSessionMissingError,
12
- AuthUnknownError,
13
- AuthWeakPasswordError,
14
- )
15
- from supabase_functions.errors import (
16
- FunctionsError,
17
- FunctionsHttpError,
18
- FunctionsRelayError,
19
- )
20
-
21
- # Async Client
22
- from ._async.auth_client import AsyncSupabaseAuthClient
23
- from ._async.client import AsyncClient
24
- from ._async.client import AsyncStorageClient as AsyncSupabaseStorageClient
25
- from ._async.client import create_client as acreate_client
26
- from ._async.client import create_client as create_async_client
27
-
28
- # Sync Client
29
- from ._sync.auth_client import SyncSupabaseAuthClient as SupabaseAuthClient
30
- from ._sync.client import Client, create_client
31
- from ._sync.client import SyncStorageClient as SupabaseStorageClient
32
-
33
- # Lib
34
- from .lib.client_options import AsyncClientOptions
35
- from .lib.client_options import AsyncClientOptions as AClientOptions
36
- from .lib.client_options import SyncClientOptions as ClientOptions
37
-
38
- # Version
39
- from .version import __version__
40
-
41
- __all__ = [
42
- "AsyncSupabaseAuthClient",
43
- "acreate_client",
44
- "create_async_client",
45
- "AClientOptions",
46
- "AsyncClient",
47
- "AsyncClientOptions",
48
- "AsyncSupabaseStorageClient",
49
- "SupabaseAuthClient",
50
- "create_client",
51
- "Client",
52
- "ClientOptions",
53
- "SupabaseStorageClient",
54
- "PostgrestAPIError",
55
- "PostgrestAPIResponse",
56
- "StorageException",
57
- "__version__",
58
- "AuthApiError",
59
- "AuthError",
60
- "AuthImplicitGrantRedirectError",
61
- "AuthInvalidCredentialsError",
62
- "AuthRetryableError",
63
- "AuthSessionMissingError",
64
- "AuthWeakPasswordError",
65
- "AuthUnknownError",
66
- "FunctionsHttpError",
67
- "FunctionsRelayError",
68
- "FunctionsError",
69
- "AuthorizationError",
70
- "NotConnectedError",
71
- ]
@@ -1 +0,0 @@
1
- __version__ = "2.32.0" # {x-release-please-version}
File without changes