Skip to content

feat: allow injection of httpx client #1117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions supabase/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from supafunc import AsyncFunctionsClient

from ..lib.client_options import AsyncClientOptions as ClientOptions
from ..lib.client_options import AsyncHttpxClient
from .auth_client import AsyncSupabaseAuthClient


Expand Down Expand Up @@ -175,6 +176,7 @@ def postgrest(self):
headers=self.options.headers,
schema=self.options.schema,
timeout=self.options.postgrest_client_timeout,
client=self.options.httpx_client,
)

return self._postgrest
Expand Down Expand Up @@ -265,6 +267,7 @@ def _init_postgrest_client(
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
verify: bool = True,
proxy: Optional[str] = None,
client: Union[AsyncHttpxClient, None] = None,
) -> AsyncPostgrestClient:
"""Private helper for creating an instance of the Postgrest client."""
return AsyncPostgrestClient(
Expand All @@ -274,6 +277,7 @@ def _init_postgrest_client(
timeout=timeout,
verify=verify,
proxy=proxy,
client=client,
)

def _create_auth_header(self, token: str):
Expand Down
4 changes: 4 additions & 0 deletions supabase/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from supafunc import SyncFunctionsClient

from ..lib.client_options import SyncClientOptions as ClientOptions
from ..lib.client_options import SyncHttpxClient
from .auth_client import SyncSupabaseAuthClient


Expand Down Expand Up @@ -174,6 +175,7 @@ def postgrest(self):
headers=self.options.headers,
schema=self.options.schema,
timeout=self.options.postgrest_client_timeout,
client=self.options.httpx_client,
)

return self._postgrest
Expand Down Expand Up @@ -264,6 +266,7 @@ def _init_postgrest_client(
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
verify: bool = True,
proxy: Optional[str] = None,
client: Union[SyncHttpxClient, None] = None,
) -> SyncPostgrestClient:
"""Private helper for creating an instance of the Postgrest client."""
return SyncPostgrestClient(
Expand All @@ -273,6 +276,7 @@ def _init_postgrest_client(
timeout=timeout,
verify=verify,
proxy=proxy,
client=client,
)

def _create_auth_header(self, token: str):
Expand Down
11 changes: 11 additions & 0 deletions supabase/lib/client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
SyncMemoryStorage,
SyncSupportedStorage,
)
from httpx import AsyncClient as AsyncHttpxClient
from httpx import Client as SyncHttpxClient
from httpx import Timeout
from postgrest.constants import DEFAULT_POSTGREST_CLIENT_TIMEOUT
from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT
Expand Down Expand Up @@ -43,6 +45,9 @@ class ClientOptions:
realtime: Optional[RealtimeClientOptions] = None
"""Options passed to the realtime-py instance"""

httpx_client: Union[SyncHttpxClient] = None
"""Options passed to the realtime-py instance"""

postgrest_client_timeout: Union[int, float, Timeout] = (
DEFAULT_POSTGREST_CLIENT_TIMEOUT
)
Expand All @@ -67,6 +72,7 @@ def replace(
persist_session: Optional[bool] = None,
storage: Optional[SyncSupportedStorage] = None,
realtime: Optional[RealtimeClientOptions] = None,
httpx_client: Optional[SyncHttpxClient] = None,
postgrest_client_timeout: Union[
int, float, Timeout
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
Expand All @@ -85,6 +91,7 @@ def replace(
client_options.persist_session = persist_session or self.persist_session
client_options.storage = storage or self.storage
client_options.realtime = realtime or self.realtime
client_options.httpx_client = httpx_client or self.httpx_client
client_options.postgrest_client_timeout = (
postgrest_client_timeout or self.postgrest_client_timeout
)
Expand All @@ -108,6 +115,7 @@ def replace(
persist_session: Optional[bool] = None,
storage: Optional[AsyncSupportedStorage] = None,
realtime: Optional[RealtimeClientOptions] = None,
httpx_client: Optional[AsyncHttpxClient] = None,
postgrest_client_timeout: Union[
int, float, Timeout
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
Expand All @@ -126,6 +134,7 @@ def replace(
client_options.persist_session = persist_session or self.persist_session
client_options.storage = storage or self.storage
client_options.realtime = realtime or self.realtime
client_options.httpx_client = httpx_client or self.httpx_client
client_options.postgrest_client_timeout = (
postgrest_client_timeout or self.postgrest_client_timeout
)
Expand All @@ -146,6 +155,7 @@ def replace(
persist_session: Optional[bool] = None,
storage: Optional[SyncSupportedStorage] = None,
realtime: Optional[RealtimeClientOptions] = None,
httpx_client: Optional[SyncHttpxClient] = None,
postgrest_client_timeout: Union[
int, float, Timeout
] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
Expand All @@ -164,6 +174,7 @@ def replace(
client_options.persist_session = persist_session or self.persist_session
client_options.storage = storage or self.storage
client_options.realtime = realtime or self.realtime
client_options.httpx_client = httpx_client or self.httpx_client
client_options.postgrest_client_timeout = (
postgrest_client_timeout or self.postgrest_client_timeout
)
Expand Down
Loading