diff --git a/supabase/_async/client.py b/supabase/_async/client.py index 885e3ac4..737f2abc 100644 --- a/supabase/_async/client.py +++ b/supabase/_async/client.py @@ -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 @@ -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 @@ -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( @@ -274,6 +277,7 @@ def _init_postgrest_client( timeout=timeout, verify=verify, proxy=proxy, + client=client, ) def _create_auth_header(self, token: str): diff --git a/supabase/_sync/client.py b/supabase/_sync/client.py index e728a9ec..8854047c 100644 --- a/supabase/_sync/client.py +++ b/supabase/_sync/client.py @@ -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 @@ -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 @@ -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( @@ -273,6 +276,7 @@ def _init_postgrest_client( timeout=timeout, verify=verify, proxy=proxy, + client=client, ) def _create_auth_header(self, token: str): diff --git a/supabase/lib/client_options.py b/supabase/lib/client_options.py index 47498c13..37c17424 100644 --- a/supabase/lib/client_options.py +++ b/supabase/lib/client_options.py @@ -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 @@ -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 ) @@ -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, @@ -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 ) @@ -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, @@ -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 ) @@ -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, @@ -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 )