33from postgrest_py import PostgrestClient
44
55from supabase_py .lib .auth_client import SupabaseAuthClient
6+ from supabase_py .lib .constants import DEFAULT_HEADERS
67from supabase_py .lib .query_builder import SupabaseQueryBuilder
78from supabase_py .lib .realtime_client import SupabaseRealtimeClient
89from supabase_py .lib .storage_client import SupabaseStorageClient
1314 "persist_session" : True ,
1415 "detect_session_in_url" : True ,
1516 "local_storage" : {},
17+ "headers" : DEFAULT_HEADERS ,
1618}
1719
1820
@@ -44,17 +46,15 @@ def __init__(
4446 raise Exception ("supabase_key is required" )
4547 self .supabase_url = supabase_url
4648 self .supabase_key = supabase_key
47- # Start with defaults, write headers and prioritise user overwrites.
48- settings : Dict [str , Any ] = {
49- ** DEFAULT_OPTIONS ,
50- "headers" : self ._get_auth_headers (),
51- ** options ,
52- }
49+
50+ settings = {** DEFAULT_OPTIONS , ** options }
51+ settings ["headers" ].update (self ._get_auth_headers ())
5352 self .rest_url : str = f"{ supabase_url } /rest/v1"
5453 self .realtime_url : str = f"{ supabase_url } /realtime/v1" .replace ("http" , "ws" )
5554 self .auth_url : str = f"{ supabase_url } /auth/v1"
5655 self .storage_url = f"{ supabase_url } /storage/v1"
5756 self .schema : str = settings .pop ("schema" )
57+
5858 # Instantiate clients.
5959 self .auth : SupabaseAuthClient = self ._init_supabase_auth_client (
6060 auth_url = self .auth_url ,
@@ -69,7 +69,8 @@ def __init__(
6969 self .realtime = None
7070 self .postgrest : PostgrestClient = self ._init_postgrest_client (
7171 rest_url = self .rest_url ,
72- supabase_key = supabase_key ,
72+ supabase_key = self .supabase_key ,
73+ ** settings ,
7374 )
7475
7576 def storage (self ):
@@ -174,9 +175,14 @@ def _init_supabase_auth_client(
174175 )
175176
176177 @staticmethod
177- def _init_postgrest_client (rest_url : str , supabase_key : str ) -> PostgrestClient :
178+ def _init_postgrest_client (
179+ rest_url : str ,
180+ supabase_key : str ,
181+ headers : Dict [str , str ],
182+ ** kwargs , # other unused settings
183+ ) -> PostgrestClient :
178184 """Private helper for creating an instance of the Postgrest client."""
179- client = PostgrestClient (rest_url )
185+ client = PostgrestClient (rest_url , headers = headers )
180186 client .auth (token = supabase_key )
181187 return client
182188
0 commit comments