supabase_functions 0.8.0__tar.gz → 0.9.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.1
2
2
  Name: supabase_functions
3
- Version: 0.8.0
3
+ Version: 0.9.0
4
4
  Summary: Library for Supabase Functions
5
5
  Home-page: https://github.com/supabase/functions-py
6
6
  License: MIT
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Requires-Dist: httpx[http2] (>=0.26,<0.28)
17
+ Requires-Dist: strenum (>=0.4.15,<0.5.0)
17
18
  Project-URL: Repository, https://github.com/supabase/functions-py
18
19
  Description-Content-Type: text/markdown
19
20
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "supabase_functions"
3
- version = "0.8.0" # {x-release-please-version}
3
+ version = "0.9.0" # {x-release-please-version}
4
4
  description = "Library for Supabase Functions"
5
5
  authors = [
6
6
  "Joel Lee <joel@joellee.org>",
@@ -13,6 +13,7 @@ repository = "https://github.com/supabase/functions-py"
13
13
  [tool.poetry.dependencies]
14
14
  python = "^3.9"
15
15
  httpx = {version = ">=0.26,<0.28", extras = ["http2"]}
16
+ strenum = "^0.4.15"
16
17
 
17
18
  [tool.poetry.group.dev.dependencies]
18
19
  black = ">=23.9.1,<25.0.0"
@@ -4,6 +4,7 @@ from typing import Literal, Optional, Union, overload
4
4
 
5
5
  from ._async.functions_client import AsyncFunctionsClient
6
6
  from ._sync.functions_client import SyncFunctionsClient
7
+ from .utils import FunctionRegion
7
8
 
8
9
  __all__ = ["create_client"]
9
10
 
@@ -1,9 +1,16 @@
1
1
  from typing import Any, Dict, Literal, Optional, Union
2
+ from warnings import warn
2
3
 
3
4
  from httpx import HTTPError, Response
4
5
 
5
6
  from ..errors import FunctionsHttpError, FunctionsRelayError
6
- from ..utils import AsyncClient, is_http_url, is_valid_jwt, is_valid_str_arg
7
+ from ..utils import (
8
+ AsyncClient,
9
+ FunctionRegion,
10
+ is_http_url,
11
+ is_valid_jwt,
12
+ is_valid_str_arg,
13
+ )
7
14
  from ..version import __version__
8
15
 
9
16
 
@@ -88,8 +95,13 @@ class AsyncFunctionsClient:
88
95
  response_type = invoke_options.get("responseType", "text/plain")
89
96
 
90
97
  region = invoke_options.get("region")
91
- if region and isinstance(region, str) and region != "any":
92
- headers["x-region"] = region.lower().strip()
98
+ if region:
99
+ if not isinstance(region, FunctionRegion):
100
+ warn(f"Use FunctionRegion({region})")
101
+ region = FunctionRegion(region)
102
+
103
+ if region.value != "any":
104
+ headers["x-region"] = region.value
93
105
 
94
106
  body = invoke_options.get("body")
95
107
  if isinstance(body, str):
@@ -1,9 +1,16 @@
1
1
  from typing import Any, Dict, Literal, Optional, Union
2
+ from warnings import warn
2
3
 
3
4
  from httpx import HTTPError, Response
4
5
 
5
6
  from ..errors import FunctionsHttpError, FunctionsRelayError
6
- from ..utils import SyncClient, is_http_url, is_valid_jwt, is_valid_str_arg
7
+ from ..utils import (
8
+ FunctionRegion,
9
+ SyncClient,
10
+ is_http_url,
11
+ is_valid_jwt,
12
+ is_valid_str_arg,
13
+ )
7
14
  from ..version import __version__
8
15
 
9
16
 
@@ -88,8 +95,13 @@ class SyncFunctionsClient:
88
95
  response_type = invoke_options.get("responseType", "text/plain")
89
96
 
90
97
  region = invoke_options.get("region")
91
- if region and isinstance(region, str) and region != "any":
92
- headers["x-region"] = region.lower().strip()
98
+ if region:
99
+ if not isinstance(region, FunctionRegion):
100
+ warn(f"Use FunctionRegion({region})")
101
+ region = FunctionRegion(region)
102
+
103
+ if region.value != "any":
104
+ headers["x-region"] = region.value
93
105
 
94
106
  body = invoke_options.get("body")
95
107
  if isinstance(body, str):
@@ -1,13 +1,38 @@
1
1
  import re
2
+ import sys
2
3
  from urllib.parse import urlparse
3
4
 
4
5
  from httpx import AsyncClient as AsyncClient # noqa: F401
5
6
  from httpx import Client as BaseClient
6
7
 
8
+ if sys.version_info >= (3, 11):
9
+ from enum import StrEnum
10
+ else:
11
+ from strenum import StrEnum
12
+
13
+
7
14
  DEFAULT_FUNCTION_CLIENT_TIMEOUT = 5
8
15
  BASE64URL_REGEX = r"^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$"
9
16
 
10
17
 
18
+ class FunctionRegion(StrEnum):
19
+ Any = "any"
20
+ ApNortheast1 = "ap-northeast-1"
21
+ ApNortheast2 = "ap-northeast-2"
22
+ ApSouth1 = "ap-south-1"
23
+ ApSoutheast1 = "ap-southeast-1"
24
+ ApSoutheast2 = "ap-southeast-2"
25
+ CaCentral1 = "ca-central-1"
26
+ EuCentral1 = "eu-central-1"
27
+ EuWest1 = "eu-west-1"
28
+ EuWest2 = "eu-west-2"
29
+ EuWest3 = "eu-west-3"
30
+ SaEast1 = "sa-east-1"
31
+ UsEast1 = "us-east-1"
32
+ UsWest1 = "us-west-1"
33
+ UsWest2 = "us-west-2"
34
+
35
+
11
36
  class SyncClient(BaseClient):
12
37
  def aclose(self) -> None:
13
38
  self.close()
@@ -0,0 +1 @@
1
+ __version__ = "0.9.0" # {x-release-please-version}
@@ -1 +0,0 @@
1
- __version__ = "0.8.0" # {x-release-please-version}