diff --git a/supabase/_async/client.py b/supabase/_async/client.py index 7fc722f6..3778ebdf 100644 --- a/supabase/_async/client.py +++ b/supabase/_async/client.py @@ -81,6 +81,11 @@ def __init__( self.auth = self._init_supabase_auth_client( auth_url=self.auth_url, client_options=options, + verify=( + options.httpx_options.get("verify") + if options.httpx_options is not None + else True + ), ) self.realtime = self._init_realtime_client( realtime_url=self.realtime_url, @@ -168,6 +173,11 @@ def postgrest(self): headers=self.options.headers, schema=self.options.schema, timeout=self.options.postgrest_client_timeout, + verify=( + self.options.httpx_options.get("verify") + if self.options.httpx_options is not None + else True + ), ) return self._postgrest @@ -179,6 +189,11 @@ def storage(self): storage_url=self.storage_url, headers=self.options.headers, storage_client_timeout=self.options.storage_client_timeout, + verify=( + self.options.httpx_options.get("verify") + if self.options.httpx_options is not None + else True + ), ) return self._storage @@ -189,6 +204,11 @@ def functions(self): self.functions_url, self.options.headers, self.options.function_client_timeout, + verify=( + self.options.httpx_options.get("verify") + if self.options.httpx_options is not None + else True + ), ) return self._functions diff --git a/supabase/_sync/client.py b/supabase/_sync/client.py index d8da3a09..dc3fade0 100644 --- a/supabase/_sync/client.py +++ b/supabase/_sync/client.py @@ -80,6 +80,11 @@ def __init__( self.auth = self._init_supabase_auth_client( auth_url=self.auth_url, client_options=options, + verify=( + options.httpx_options.get("verify") + if options.httpx_options is not None + else True + ), ) self.realtime = self._init_realtime_client( realtime_url=self.realtime_url, @@ -167,6 +172,11 @@ def postgrest(self): headers=self.options.headers, schema=self.options.schema, timeout=self.options.postgrest_client_timeout, + verify=( + self.options.httpx_options.get("verify") + if self.options.httpx_options is not None + else True + ), ) return self._postgrest @@ -178,6 +188,11 @@ def storage(self): storage_url=self.storage_url, headers=self.options.headers, storage_client_timeout=self.options.storage_client_timeout, + verify=( + self.options.httpx_options.get("verify") + if self.options.httpx_options is not None + else True + ), ) return self._storage @@ -188,6 +203,11 @@ def functions(self): self.functions_url, self.options.headers, self.options.function_client_timeout, + verify=( + self.options.httpx_options.get("verify") + if self.options.httpx_options is not None + else True + ), ) return self._functions diff --git a/supabase/lib/client_options.py b/supabase/lib/client_options.py index 47498c13..623f092d 100644 --- a/supabase/lib/client_options.py +++ b/supabase/lib/client_options.py @@ -13,7 +13,7 @@ from storage3.constants import DEFAULT_TIMEOUT as DEFAULT_STORAGE_CLIENT_TIMEOUT from supafunc.utils import DEFAULT_FUNCTION_CLIENT_TIMEOUT -from supabase.types import RealtimeClientOptions +from supabase.types import HttpxOptions, RealtimeClientOptions from ..version import __version__ @@ -40,6 +40,9 @@ class ClientOptions: storage: SyncSupportedStorage = field(default_factory=SyncMemoryStorage) """A storage provider. Used to store the logged in session.""" + httpx_options: Optional[HttpxOptions] = None + """Options passed to httpx when making requests""" + realtime: Optional[RealtimeClientOptions] = None """Options passed to the realtime-py instance""" @@ -74,6 +77,7 @@ def replace( int, float, Timeout ] = DEFAULT_STORAGE_CLIENT_TIMEOUT, flow_type: Optional[AuthFlowType] = None, + httpx_options: Optional[HttpxOptions] = None, ) -> "ClientOptions": """Create a new SupabaseClientOptions with changes""" client_options = ClientOptions() @@ -85,6 +89,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_options = httpx_options or self.httpx_options client_options.postgrest_client_timeout = ( postgrest_client_timeout or self.postgrest_client_timeout ) @@ -115,6 +120,7 @@ def replace( int, float, Timeout ] = DEFAULT_STORAGE_CLIENT_TIMEOUT, flow_type: Optional[AuthFlowType] = None, + httpx_options: Optional[HttpxOptions] = None, ) -> "AsyncClientOptions": """Create a new SupabaseClientOptions with changes""" client_options = AsyncClientOptions() @@ -126,6 +132,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_options = httpx_options or self.httpx_options client_options.postgrest_client_timeout = ( postgrest_client_timeout or self.postgrest_client_timeout ) @@ -153,6 +160,7 @@ def replace( int, float, Timeout ] = DEFAULT_STORAGE_CLIENT_TIMEOUT, flow_type: Optional[AuthFlowType] = None, + httpx_options: Optional[HttpxOptions] = None, ) -> "SyncClientOptions": """Create a new SupabaseClientOptions with changes""" client_options = SyncClientOptions() @@ -164,6 +172,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_options = httpx_options or self.httpx_options client_options.postgrest_client_timeout = ( postgrest_client_timeout or self.postgrest_client_timeout ) diff --git a/supabase/types.py b/supabase/types.py index 4f774531..314bfdd2 100644 --- a/supabase/types.py +++ b/supabase/types.py @@ -6,3 +6,8 @@ class RealtimeClientOptions(TypedDict, total=False): hb_interval: int max_retries: int initial_backoff: float + + +class HttpxOptions(TypedDict, total=False): + verify: bool = True + """Either `True` to use an SSL context with the default CA bundle, `False` to disable verification."""