diff --git a/supabase_py/__init__.py b/supabase_py/__init__.py index fc4e4f5d..1a36b6ee 100644 --- a/supabase_py/__init__.py +++ b/supabase_py/__init__.py @@ -1,2 +1,2 @@ from .src import * -from .client import Client \ No newline at end of file +from .client import Client diff --git a/supabase_py/client.py b/supabase_py/client.py index d9a79647..bab3e0f2 100644 --- a/supabase_py/client.py +++ b/supabase_py/client.py @@ -6,25 +6,26 @@ from .src.SupabaseQueryBuilder import SupabaseQueryBuilder +DEFAULT_OPTIONS = { + "schema": "public", + "auto_refresh_token": True, + "persist_session": True, + "detect_session_in_url": True, + "headers": {}, +} + + class Client: def __init__(self, supabaseUrl: str, supabaseKey: str): - if not supabaseUrl or not supabaseKey: - raise("supabaseUrl is required") - DEFAULT_HEADERS = {} - - SETTINGS = { - "schema": "public", - "autoRefreshToken": True, - "persistSession": True, - "detectSessionInUrl": True, - # TODO: Verify if the localStorage parameter is relevant in the python implementation - "localStorage": None, - "headers": DEFAULT_HEADERS, - } + if not supabaseUrl: + raise Exception("supabaseUrl is required") + if not supabaseKey: + raise Exception("supabaseKey is required") + + settings = {**DEFAULT_OPTIONS, **options} self.restUrl = f"{supabaseUrl}/rest/v1" - self.realtimeUrl = f"{supabaseUrl}/realtime/v1".replace('http', 'ws') + self.realtimeUrl = f"{supabaseUrl}/realtime/v1".replace("http", "ws") self.authUrl = f"{supabaseUrl}/auth/v1" - # TODO: Allow user to pass in schema. This is hardcoded self.schema = SETTINGS["schema"] self.supabaseUrl = supabaseUrl self.supabaseKey = supabaseKey @@ -43,10 +44,9 @@ def rpc(self, fn, params): rest = self._initPostgrestClient() return rest.rpc(fn, params) - def removeSubscription(self): pass - + def _closeSubscription(self, subscription): pass @@ -56,21 +56,27 @@ def getSubscriptions(self): def _initRealtimeClient(self): pass - def _initSupabaseAuthClient(self, autoRefreshToken, persistSession, - detectSessionInUrl,localStorage): - return SupabaseAuthClient(self.authUrl, autoRefreshToken, persistSession, detectSessionInUrl, localStorage) - + def _initSupabaseAuthClient( + self, autoRefreshToken, persistSession, detectSessionInUrl, localStorage + ): + return SupabaseAuthClient( + self.authUrl, + autoRefreshToken, + persistSession, + detectSessionInUrl, + localStorage, + ) + def _initPostgrestClient(self): return PostgrestClient(self.restUrl) - - def _getAuthHeaders(self): + + def _getAuthHeaders(self): headers = {} # What's the corresponding method to get the token # authBearer = self.auth.session().token if self.auth.session().token else self.supabaseKey - headers['apiKey'] = self.supabaseKey - headers['Authorization'] = f"Bearer {self.supabaseKey}" + headers["apiKey"] = self.supabaseKey + headers["Authorization"] = f"Bearer {self.supabaseKey}" return headers - + def _closeChannel(self): pass - diff --git a/supabase_py/src/SupabaseAuthClient.py b/supabase_py/src/SupabaseAuthClient.py index 84a95701..7d84c1ec 100644 --- a/supabase_py/src/SupabaseAuthClient.py +++ b/supabase_py/src/SupabaseAuthClient.py @@ -1,9 +1,19 @@ import gotrue + + class SupabaseAuthClient(gotrue.Client): - def __init__(self,authURL, headers=None, detectSessionInUrl=False, autoRefreshToken=False, persistSession=False, localStorage=None): + def __init__( + self, + authURL, + headers=None, + detectSessionInUrl=False, + autoRefreshToken=False, + persistSession=False, + localStorage=None, + ): super().__init__(authURL) self.headers = headers self.detectSessionInUrl = detectSessionInUrl self.autoRefreshToken = autoRefreshToken self.persistSession = persistSession - self.localStorage = localStorage \ No newline at end of file + self.localStorage = localStorage diff --git a/supabase_py/src/SupabaseQueryBuilder.py b/supabase_py/src/SupabaseQueryBuilder.py index dd7422f5..83217f33 100644 --- a/supabase_py/src/SupabaseQueryBuilder.py +++ b/supabase_py/src/SupabaseQueryBuilder.py @@ -1,7 +1,10 @@ -from postgrest_py import PostgrestClient -class SupabaseQueryBuilder: - def __init__(self): +from postgrest_py.request_builder import RequestBuilder + + +class SupabaseQueryBuilder(RequestBuilder): + def __init__(self, session: AsyncClient, path: str): + super().__init__(session, path) pass def on(self): - pass \ No newline at end of file + pass diff --git a/supabase_py/src/SupabaseRealtimeClient.py b/supabase_py/src/SupabaseRealtimeClient.py index c42b599a..dcffb6e4 100644 --- a/supabase_py/src/SupabaseRealtimeClient.py +++ b/supabase_py/src/SupabaseRealtimeClient.py @@ -4,6 +4,6 @@ def __init__(self): def on(self): pass - + def subscribe(self): - pass \ No newline at end of file + pass