Skip to content
Open
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
1 change: 1 addition & 0 deletions src/supabase/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies = [
"supabase_auth == 2.25.1", # x-release-please-version
"postgrest == 2.25.1", # x-release-please-version
"httpx >=0.26,<0.29",
"yarl>=1.22.0",
]

[project.urls]
Expand Down
31 changes: 19 additions & 12 deletions src/supabase/src/supabase/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from supabase_auth import AsyncMemoryStorage
from supabase_auth.types import AuthChangeEvent, Session
from supabase_functions import AsyncFunctionsClient
from yarl import URL

from ..lib.client_options import AsyncClientOptions as ClientOptions
from ..lib.client_options import AsyncHttpxClient
Expand Down Expand Up @@ -65,23 +66,27 @@ def __init__(
if options is None:
options = ClientOptions(storage=AsyncMemoryStorage())

self.supabase_url = supabase_url
self.supabase_url = (
URL(supabase_url) if supabase_url.endswith("/") else URL(supabase_url + "/")
)
self.supabase_key = supabase_key
self.options = copy.copy(options)
self.options.headers = {
**options.headers,
**self._get_auth_headers(),
}

self.rest_url = f"{supabase_url}/rest/v1"
self.realtime_url = f"{supabase_url}/realtime/v1".replace("http", "ws")
self.auth_url = f"{supabase_url}/auth/v1"
self.storage_url = f"{supabase_url}/storage/v1/"
self.functions_url = f"{supabase_url}/functions/v1"
self.rest_url = self.supabase_url.joinpath("rest", "v1")
self.realtime_url = self.supabase_url.joinpath("realtime", "v1").with_scheme(
"wss" if self.supabase_url.scheme == "https" else "ws"
)
self.auth_url = self.supabase_url.joinpath("auth", "v1")
self.storage_url = self.supabase_url.joinpath("storage", "v1")
self.functions_url = self.supabase_url.joinpath("functions", "v1")

# Instantiate clients.
self.auth = self._init_supabase_auth_client(
auth_url=self.auth_url,
auth_url=str(self.auth_url),
client_options=self.options,
)
self.realtime = self._init_realtime_client(
Expand Down Expand Up @@ -178,7 +183,7 @@ def rpc(
def postgrest(self) -> AsyncPostgrestClient:
if self._postgrest is None:
self._postgrest = self._init_postgrest_client(
rest_url=self.rest_url,
rest_url=str(self.rest_url),
headers=self.options.headers,
schema=self.options.schema,
timeout=self.options.postgrest_client_timeout,
Expand All @@ -191,7 +196,7 @@ def postgrest(self) -> AsyncPostgrestClient:
def storage(self) -> AsyncStorageClient:
if self._storage is None:
self._storage = self._init_storage_client(
storage_url=self.storage_url,
storage_url=str(self.storage_url),
headers=self.options.headers,
storage_client_timeout=self.options.storage_client_timeout,
http_client=self.options.httpx_client,
Expand All @@ -202,7 +207,7 @@ def storage(self) -> AsyncStorageClient:
def functions(self) -> AsyncFunctionsClient:
if self._functions is None:
self._functions = AsyncFunctionsClient(
url=self.functions_url,
url=str(self.functions_url),
headers=self.options.headers,
timeout=(
self.options.function_client_timeout
Expand Down Expand Up @@ -233,13 +238,15 @@ async def remove_all_channels(self) -> None:

@staticmethod
def _init_realtime_client(
realtime_url: str,
realtime_url: URL,
supabase_key: str,
options: Optional[RealtimeClientOptions] = None,
) -> AsyncRealtimeClient:
realtime_options = options or {}
"""Private method for creating an instance of the realtime-py client."""
return AsyncRealtimeClient(realtime_url, token=supabase_key, **realtime_options)
return AsyncRealtimeClient(
str(realtime_url), token=supabase_key, **realtime_options
)

@staticmethod
def _init_storage_client(
Expand Down
31 changes: 19 additions & 12 deletions src/supabase/src/supabase/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from supabase_auth import SyncMemoryStorage
from supabase_auth.types import AuthChangeEvent, Session
from supabase_functions import SyncFunctionsClient
from yarl import URL

from ..lib.client_options import SyncClientOptions as ClientOptions
from ..lib.client_options import SyncHttpxClient
Expand Down Expand Up @@ -64,23 +65,27 @@ def __init__(
if options is None:
options = ClientOptions(storage=SyncMemoryStorage())

self.supabase_url = supabase_url
self.supabase_url = (
URL(supabase_url) if supabase_url.endswith("/") else URL(supabase_url + "/")
)
self.supabase_key = supabase_key
self.options = copy.copy(options)
self.options.headers = {
**options.headers,
**self._get_auth_headers(),
}

self.rest_url = f"{supabase_url}/rest/v1"
self.realtime_url = f"{supabase_url}/realtime/v1".replace("http", "ws")
self.auth_url = f"{supabase_url}/auth/v1"
self.storage_url = f"{supabase_url}/storage/v1/"
self.functions_url = f"{supabase_url}/functions/v1"
self.rest_url = self.supabase_url.joinpath("rest", "v1")
self.realtime_url = self.supabase_url.joinpath("realtime", "v1").with_scheme(
"wss" if self.supabase_url.scheme == "https" else "ws"
)
self.auth_url = self.supabase_url.joinpath("auth", "v1")
self.storage_url = self.supabase_url.joinpath("storage", "v1")
self.functions_url = self.supabase_url.joinpath("functions", "v1")

# Instantiate clients.
self.auth = self._init_supabase_auth_client(
auth_url=self.auth_url,
auth_url=str(self.auth_url),
client_options=self.options,
)
self.realtime = self._init_realtime_client(
Expand Down Expand Up @@ -177,7 +182,7 @@ def rpc(
def postgrest(self) -> SyncPostgrestClient:
if self._postgrest is None:
self._postgrest = self._init_postgrest_client(
rest_url=self.rest_url,
rest_url=str(self.rest_url),
headers=self.options.headers,
schema=self.options.schema,
timeout=self.options.postgrest_client_timeout,
Expand All @@ -190,7 +195,7 @@ def postgrest(self) -> SyncPostgrestClient:
def storage(self) -> SyncStorageClient:
if self._storage is None:
self._storage = self._init_storage_client(
storage_url=self.storage_url,
storage_url=str(self.storage_url),
headers=self.options.headers,
storage_client_timeout=self.options.storage_client_timeout,
http_client=self.options.httpx_client,
Expand All @@ -201,7 +206,7 @@ def storage(self) -> SyncStorageClient:
def functions(self) -> SyncFunctionsClient:
if self._functions is None:
self._functions = SyncFunctionsClient(
url=self.functions_url,
url=str(self.functions_url),
headers=self.options.headers,
timeout=(
self.options.function_client_timeout
Expand Down Expand Up @@ -232,13 +237,15 @@ def remove_all_channels(self) -> None:

@staticmethod
def _init_realtime_client(
realtime_url: str,
realtime_url: URL,
supabase_key: str,
options: Optional[RealtimeClientOptions] = None,
) -> SyncRealtimeClient:
realtime_options = options or {}
"""Private method for creating an instance of the realtime-py client."""
return SyncRealtimeClient(realtime_url, token=supabase_key, **realtime_options)
return SyncRealtimeClient(
str(realtime_url), token=supabase_key, **realtime_options
)

@staticmethod
def _init_storage_client(
Expand Down
4 changes: 2 additions & 2 deletions src/supabase/tests/test_function_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def test_functions_client_initialization() -> None:
# Sample JWT Key
key = "xxxxxxxxxxxxxx.xxxxxxxxxxxxxxx.xxxxxxxxxxxxxxx"
sp = supabase.Client(url, key)
assert sp.functions_url == f"https://{ref}.supabase.co/functions/v1"
assert str(sp.functions_url) == f"https://{ref}.supabase.co/functions/v1"

url = "https://localhost:54322"
sp_local = supabase.Client(url, key)
assert sp_local.functions_url == f"{url}/functions/v1"
assert str(sp_local.functions_url) == f"{url}/functions/v1"
4 changes: 2 additions & 2 deletions src/supabase/tests/test_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def test_realtime_client_initialization() -> None:
# Sample JWT Key
key = "xxxxxxxxxxxxxx.xxxxxxxxxxxxxxx.xxxxxxxxxxxxxxx"
sp = supabase.Client(url, key)
assert sp.realtime_url == f"wss://{ref}.supabase.co/realtime/v1"
assert str(sp.realtime_url) == f"wss://{ref}.supabase.co/realtime/v1"

url = "http://localhost:54322"
sp_local = supabase.Client(url, key)
assert sp_local.realtime_url == "ws://localhost:54322/realtime/v1"
assert str(sp_local.realtime_url) == "ws://localhost:54322/realtime/v1"
16 changes: 10 additions & 6 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.