supabase_functions 2.32.0__tar.gz → 2.33.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-functions
3
- Version: 2.32.0
3
+ Version: 2.33.0
4
4
  Summary: Library for Supabase Functions
5
5
  Author: Joel Lee, Andrew Smith
6
6
  Author-email: Joel Lee <joel@joellee.org>, Andrew Smith <a.smith@silentworks.co.uk>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "supabase_functions"
3
- version = "2.32.0" # {x-release-please-version}
3
+ version = "2.33.0" # {x-release-please-version}
4
4
  description = "Library for Supabase Functions"
5
5
  authors = [
6
6
  { name = "Joel Lee", email = "joel@joellee.org" },
@@ -26,7 +26,7 @@ changelog = "https://github.com/supabase/supabase-py/tree/main/CHANGELOG.md"
26
26
 
27
27
  [dependency-groups]
28
28
  tests = [
29
- "pyjwt >=2.8.0",
29
+ "pyjwt>=2.15.0",
30
30
  "pytest >=7.4.2,<9.0.0",
31
31
  "pytest-cov >=4,<7",
32
32
  "pytest-asyncio >=0.21.1,<1.2.0",
@@ -16,13 +16,21 @@ __all__ = [
16
16
 
17
17
  @overload
18
18
  def create_client(
19
- url: str, headers: dict[str, str], *, is_async: Literal[True], verify: bool
19
+ url: str,
20
+ headers: dict[str, str],
21
+ *,
22
+ is_async: Literal[True],
23
+ verify: bool = ...,
20
24
  ) -> AsyncFunctionsClient: ...
21
25
 
22
26
 
23
27
  @overload
24
28
  def create_client(
25
- url: str, headers: dict[str, str], *, is_async: Literal[False], verify: bool
29
+ url: str,
30
+ headers: dict[str, str],
31
+ *,
32
+ is_async: Literal[False],
33
+ verify: bool = ...,
26
34
  ) -> SyncFunctionsClient: ...
27
35
 
28
36
 
@@ -34,6 +42,6 @@ def create_client(
34
42
  verify: bool = True,
35
43
  ) -> Union[AsyncFunctionsClient, SyncFunctionsClient]:
36
44
  if is_async:
37
- return AsyncFunctionsClient(url, headers, verify)
45
+ return AsyncFunctionsClient(url, headers, verify=verify)
38
46
  else:
39
- return SyncFunctionsClient(url, headers, verify)
47
+ return SyncFunctionsClient(url, headers, verify=verify)
@@ -3,7 +3,7 @@ import sys
3
3
  from typing import Any, Dict, Literal, Optional, Union
4
4
  from warnings import warn
5
5
 
6
- from httpx import AsyncClient, HTTPError, QueryParams, Response
6
+ from httpx import AsyncClient, Headers, HTTPError, QueryParams, Response
7
7
  from yarl import URL
8
8
 
9
9
  from ..errors import FunctionsHttpError, FunctionsRelayError, _error_message_from
@@ -30,16 +30,18 @@ class AsyncFunctionsClient:
30
30
  if not is_http_url(url):
31
31
  raise ValueError("url must be a valid HTTP URL string")
32
32
  self.url = URL(url)
33
- self.headers = {
34
- "X-Client-Info": (
35
- f"supabase-py/supabase_functions v{__version__}"
36
- f"; platform={platform.system()}"
37
- f"; platform-version={platform.release()}"
38
- f"; runtime=python"
39
- f"; runtime-version={platform.python_version()}"
40
- ),
41
- **headers,
42
- }
33
+ self.headers = Headers(
34
+ {
35
+ "X-Client-Info": (
36
+ f"supabase-py/supabase_functions v{__version__}"
37
+ f"; platform={platform.system()}"
38
+ f"; platform-version={platform.release()}"
39
+ f"; runtime=python"
40
+ f"; runtime-version={platform.python_version()}"
41
+ )
42
+ }
43
+ )
44
+ self.headers.update(headers)
43
45
 
44
46
  if sys.version_info < (3, 10):
45
47
  warn(
@@ -81,12 +83,11 @@ class AsyncFunctionsClient:
81
83
  self,
82
84
  method: HTTPMethod,
83
85
  path: list[str],
84
- headers: Optional[Dict[str, str]] = None,
86
+ headers: Headers,
85
87
  json: Optional[Union[Dict[Any, Any], str, bytes]] = None,
86
88
  params: Optional[QueryParams] = None,
87
89
  ) -> Response:
88
90
  url = self.url.joinpath(*path)
89
- headers = {**self.headers, **(headers or {})}
90
91
  response = (
91
92
  await self._client.request(
92
93
  method, str(url), content=json, headers=headers, params=params
@@ -96,6 +97,9 @@ class AsyncFunctionsClient:
96
97
  method, str(url), json=json, headers=headers, params=params
97
98
  )
98
99
  )
100
+ # Relay failures set this header even on non-2xx responses.
101
+ if response.headers.get("x-relay-error") == "true":
102
+ raise FunctionsRelayError(response.text, response.status_code)
99
103
  try:
100
104
  response.raise_for_status()
101
105
  except HTTPError as exc:
@@ -138,7 +142,7 @@ class AsyncFunctionsClient:
138
142
  """
139
143
  if not is_valid_str_arg(function_name):
140
144
  raise ValueError("function_name must a valid string value.")
141
- headers: Dict[str, str] = {}
145
+ headers = Headers(self.headers)
142
146
  params = QueryParams()
143
147
  body = None
144
148
  method: HTTPMethod = "POST"
@@ -161,24 +165,17 @@ class AsyncFunctionsClient:
161
165
  params = params.set("forceFunctionRegion", region.value)
162
166
 
163
167
  body = invoke_options.get("body")
164
- if isinstance(body, str):
165
- headers["Content-Type"] = "text/plain"
166
- elif isinstance(body, dict):
167
- headers["Content-Type"] = "application/json"
168
- elif isinstance(body, bytes):
169
- headers["Content-Type"] = "application/octet-stream"
168
+ if headers.get("content-type", None) is None:
169
+ if isinstance(body, str):
170
+ headers["Content-Type"] = "text/plain"
171
+ elif isinstance(body, dict):
172
+ headers["Content-Type"] = "application/json"
173
+ elif isinstance(body, bytes):
174
+ headers["Content-Type"] = "application/octet-stream"
170
175
 
171
176
  response = await self._request(
172
177
  method, [function_name], headers=headers, json=body, params=params
173
178
  )
174
- is_relay_error = response.headers.get("x-relay-header")
175
-
176
- if is_relay_error and is_relay_error == "true":
177
- raise FunctionsRelayError(
178
- _error_message_from(response)
179
- or "An error occurred while relaying your edge function request."
180
- )
181
-
182
179
  if response_type == "json":
183
180
  data = response.json()
184
181
  else:
@@ -3,7 +3,7 @@ import sys
3
3
  from typing import Any, Dict, Literal, Optional, Union
4
4
  from warnings import warn
5
5
 
6
- from httpx import Client, HTTPError, QueryParams, Response
6
+ from httpx import Client, Headers, HTTPError, QueryParams, Response
7
7
  from yarl import URL
8
8
 
9
9
  from ..errors import FunctionsHttpError, FunctionsRelayError, _error_message_from
@@ -30,16 +30,18 @@ class SyncFunctionsClient:
30
30
  if not is_http_url(url):
31
31
  raise ValueError("url must be a valid HTTP URL string")
32
32
  self.url = URL(url)
33
- self.headers = {
34
- "X-Client-Info": (
35
- f"supabase-py/supabase_functions v{__version__}"
36
- f"; platform={platform.system()}"
37
- f"; platform-version={platform.release()}"
38
- f"; runtime=python"
39
- f"; runtime-version={platform.python_version()}"
40
- ),
41
- **headers,
42
- }
33
+ self.headers = Headers(
34
+ {
35
+ "X-Client-Info": (
36
+ f"supabase-py/supabase_functions v{__version__}"
37
+ f"; platform={platform.system()}"
38
+ f"; platform-version={platform.release()}"
39
+ f"; runtime=python"
40
+ f"; runtime-version={platform.python_version()}"
41
+ )
42
+ }
43
+ )
44
+ self.headers.update(headers)
43
45
 
44
46
  if sys.version_info < (3, 10):
45
47
  warn(
@@ -81,12 +83,11 @@ class SyncFunctionsClient:
81
83
  self,
82
84
  method: HTTPMethod,
83
85
  path: list[str],
84
- headers: Optional[Dict[str, str]] = None,
86
+ headers: Headers,
85
87
  json: Optional[Union[Dict[Any, Any], str, bytes]] = None,
86
88
  params: Optional[QueryParams] = None,
87
89
  ) -> Response:
88
90
  url = self.url.joinpath(*path)
89
- headers = {**self.headers, **(headers or {})}
90
91
  response = (
91
92
  self._client.request(
92
93
  method, str(url), content=json, headers=headers, params=params
@@ -96,6 +97,9 @@ class SyncFunctionsClient:
96
97
  method, str(url), json=json, headers=headers, params=params
97
98
  )
98
99
  )
100
+ # Relay failures set this header even on non-2xx responses.
101
+ if response.headers.get("x-relay-error") == "true":
102
+ raise FunctionsRelayError(response.text, response.status_code)
99
103
  try:
100
104
  response.raise_for_status()
101
105
  except HTTPError as exc:
@@ -138,7 +142,7 @@ class SyncFunctionsClient:
138
142
  """
139
143
  if not is_valid_str_arg(function_name):
140
144
  raise ValueError("function_name must a valid string value.")
141
- headers: Dict[str, str] = {}
145
+ headers = Headers(self.headers)
142
146
  params = QueryParams()
143
147
  body = None
144
148
  method: HTTPMethod = "POST"
@@ -161,24 +165,17 @@ class SyncFunctionsClient:
161
165
  params = params.set("forceFunctionRegion", region.value)
162
166
 
163
167
  body = invoke_options.get("body")
164
- if isinstance(body, str):
165
- headers["Content-Type"] = "text/plain"
166
- elif isinstance(body, dict):
167
- headers["Content-Type"] = "application/json"
168
- elif isinstance(body, bytes):
169
- headers["Content-Type"] = "application/octet-stream"
168
+ if headers.get("content-type", None) is None:
169
+ if isinstance(body, str):
170
+ headers["Content-Type"] = "text/plain"
171
+ elif isinstance(body, dict):
172
+ headers["Content-Type"] = "application/json"
173
+ elif isinstance(body, bytes):
174
+ headers["Content-Type"] = "application/octet-stream"
170
175
 
171
176
  response = self._request(
172
177
  method, [function_name], headers=headers, json=body, params=params
173
178
  )
174
- is_relay_error = response.headers.get("x-relay-header")
175
-
176
- if is_relay_error and is_relay_error == "true":
177
- raise FunctionsRelayError(
178
- _error_message_from(response)
179
- or "An error occurred while relaying your edge function request."
180
- )
181
-
182
179
  if response_type == "json":
183
180
  data = response.json()
184
181
  else:
@@ -0,0 +1 @@
1
+ __version__ = "2.33.0" # {x-release-please-version}
@@ -1 +0,0 @@
1
- __version__ = "2.32.0" # {x-release-please-version}