Skip to content

Commit

Permalink
Merge pull request #7 from supabase/feature/update-to-latest-gotrue-py
Browse files Browse the repository at this point in the history
Update to latest gotrue-py, monkey patch for sync behaviour, add working tests
  • Loading branch information
awalias authored Apr 1, 2021
2 parents 23b944b + 1b0ebda commit fd842a1
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 306 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
poetry install
- name: Test with Pytest
run: |
poetry run pytest
SUPABASE_TEST_URL="https://tfsatoopsijgjhrqplra.supabase.co" SUPABASE_TEST_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYxMjYwOTMyMiwiZXhwIjoxOTI4MTg1MzIyfQ.XL9W5I_VRQ4iyQHVQmjG0BkwRfx6eVyYB3uAKcesukg" poetry run pytest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
poetry.lock

tags
## Vim stuff
# Swap
Expand Down
242 changes: 0 additions & 242 deletions poetry.lock

This file was deleted.

11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
[tool.poetry]
name = "supabase-py"
version = "0.0.1"
version = "0.0.2"
description = "Supabase client for Python."
authors = ["Joel Lee <[email protected]>"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.7.1"
postgrest-py = "^0.3.2"
realtime-py="^0.1.2"
gotrue="0.1.2"
pytest="6.2.2"
postgrest-py = "0.4.0"
realtime-py = "^0.1.2"
gotrue = "0.2.0"
pytest = "^6"
requests = "2.25.1"

[tool.poetry.dev-dependencies]

Expand Down
29 changes: 15 additions & 14 deletions supabase_py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"schema": "public",
"auto_refresh_token": True,
"persist_session": True,
"detect_session_url": True,
"detect_session_in_url": True,
"local_storage": {},
}

Expand Down Expand Up @@ -60,7 +60,8 @@ def __init__(
# )
self.realtime = None
self.postgrest: PostgrestClient = self._init_postgrest_client(
rest_url=self.rest_url
rest_url=self.rest_url,
supabase_key=supabase_key,
)

def table(self, table_name: str) -> SupabaseQueryBuilder:
Expand All @@ -70,20 +71,21 @@ def table(self, table_name: str) -> SupabaseQueryBuilder:
this is a reserved keyword so we have elected to use the name `table`.
Alternatively you can use the `._from()` method.
"""
return self._from(table_name)
return self.from_(table_name)

def _from(self, table_name: str) -> SupabaseQueryBuilder:
def from_(self, table_name: str) -> SupabaseQueryBuilder:
"""Perform a table operation.
See the `table` method.
"""
return SupabaseQueryBuilder(
query_builder = SupabaseQueryBuilder(
url=f"{self.rest_url}/{table_name}",
headers=self._get_auth_headers(),
schema=self.schema,
realtime=self.realtime,
table=table_name,
)
return query_builder.from_(table_name)

def rpc(self, fn, params):
"""Performs a stored procedure call.
Expand Down Expand Up @@ -143,28 +145,28 @@ def _init_realtime_client(
def _init_supabase_auth_client(
auth_url: str,
supabase_key: str,
detect_session_url: bool,
detect_session_in_url: bool,
auto_refresh_token: bool,
persist_session: bool,
local_storage: Dict[str, Any],
headers: Dict[str, str],
) -> SupabaseAuthClient:
"""
Private helper method for creating a wrapped instance of the GoTrue Client.
"""
"""Creates a wrapped instance of the GoTrue Client."""
return SupabaseAuthClient(
auth_url=auth_url,
url=auth_url,
auto_refresh_token=auto_refresh_token,
detect_session_url=detect_session_url,
detect_session_in_url=detect_session_in_url,
persist_session=persist_session,
local_storage=local_storage,
headers=headers,
)

@staticmethod
def _init_postgrest_client(rest_url: str) -> PostgrestClient:
def _init_postgrest_client(rest_url: str, supabase_key: str) -> PostgrestClient:
"""Private helper for creating an instance of the Postgrest client."""
return PostgrestClient(rest_url)
client = PostgrestClient(rest_url)
client.auth(token=supabase_key)
return client

def _get_auth_headers(self) -> Dict[str, str]:
"""Helper method to get auth headers."""
Expand Down Expand Up @@ -204,4 +206,3 @@ def create_client(supabase_url: str, supabase_key: str, **options) -> Client:
Client
"""
return Client(supabase_url=supabase_url, supabase_key=supabase_key, **options)

Loading

0 comments on commit fd842a1

Please sign in to comment.