Skip to content

Commit

Permalink
fix: Merge pull request #139 from Atticuszz/work-with-supabase-py
Browse files Browse the repository at this point in the history
fix: remove supabase-py-async with supabase-py
  • Loading branch information
AtticusZeller authored Sep 18, 2024
2 parents 4f4a7f1 + a0c0143 commit 4864352
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 397 deletions.
122 changes: 61 additions & 61 deletions .vscode/PythonImportHelper-v2-Completion.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,74 +278,74 @@
},
{
"label": "AsyncClient",
"importPath": "supabase_py_async",
"description": "supabase_py_async",
"importPath": "supabase._async.client",
"description": "supabase._async.client",
"isExtraImport": true,
"detail": "supabase_py_async",
"detail": "supabase._async.client",
"documentation": {}
},
{
"label": "create_client",
"importPath": "supabase_py_async",
"description": "supabase_py_async",
"importPath": "supabase._async.client",
"description": "supabase._async.client",
"isExtraImport": true,
"detail": "supabase_py_async",
"detail": "supabase._async.client",
"documentation": {}
},
{
"label": "AsyncClient",
"importPath": "supabase_py_async",
"description": "supabase_py_async",
"importPath": "supabase._async.client",
"description": "supabase._async.client",
"isExtraImport": true,
"detail": "supabase_py_async",
"detail": "supabase._async.client",
"documentation": {}
},
{
"label": "AsyncClient",
"importPath": "supabase_py_async",
"description": "supabase_py_async",
"importPath": "supabase._async.client",
"description": "supabase._async.client",
"isExtraImport": true,
"detail": "supabase_py_async",
"detail": "supabase._async.client",
"documentation": {}
},
{
"label": "AsyncClient",
"importPath": "supabase_py_async",
"description": "supabase_py_async",
"importPath": "supabase._async.client",
"description": "supabase._async.client",
"isExtraImport": true,
"detail": "supabase_py_async",
"detail": "supabase._async.client",
"documentation": {}
},
{
"label": "AsyncClient",
"importPath": "supabase_py_async",
"description": "supabase_py_async",
"importPath": "supabase._async.client",
"description": "supabase._async.client",
"isExtraImport": true,
"detail": "supabase_py_async",
"detail": "supabase._async.client",
"documentation": {}
},
{
"label": "AsyncClient",
"importPath": "supabase_py_async",
"description": "supabase_py_async",
"importPath": "supabase._async.client",
"description": "supabase._async.client",
"isExtraImport": true,
"detail": "supabase_py_async",
"detail": "supabase._async.client",
"documentation": {}
},
{
"label": "create_client",
"importPath": "supabase_py_async",
"description": "supabase_py_async",
"importPath": "supabase._async.client",
"description": "supabase._async.client",
"isExtraImport": true,
"detail": "supabase_py_async",
"detail": "supabase._async.client",
"documentation": {}
},
{
"label": "ClientOptions",
"importPath": "supabase_py_async.lib.client_options",
"description": "supabase_py_async.lib.client_options",
"importPath": "supabase.lib.client_options",
"description": "supabase.lib.client_options",
"isExtraImport": true,
"detail": "supabase_py_async.lib.client_options",
"detail": "supabase.lib.client_options",
"documentation": {}
},
{
Expand Down Expand Up @@ -754,82 +754,82 @@
{
"label": "bin_dir",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "bin_dir = os.path.dirname(abs_file)\nbase = bin_dir[: -len(\"bin\") - 1] # strip away the bin part from the __file__, plus the path separator\n# prepend bin to PATH (this file is inside the bin directory)\nos.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.12/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))",
"detail": ".venv.bin.activate_this",
"importPath": ".venv.Scripts.activate_this",
"description": ".venv.Scripts.activate_this",
"peekOfCode": "bin_dir = os.path.dirname(abs_file)\nbase = bin_dir[: -len(\"Scripts\") - 1] # strip away the bin part from the __file__, plus the path separator\n# prepend bin to PATH (this file is inside the bin directory)\nos.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"..\\\\Lib\\\\site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))",
"detail": ".venv.Scripts.activate_this",
"documentation": {}
},
{
"label": "base",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "base = bin_dir[: -len(\"bin\") - 1] # strip away the bin part from the __file__, plus the path separator\n# prepend bin to PATH (this file is inside the bin directory)\nos.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.12/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path)",
"detail": ".venv.bin.activate_this",
"importPath": ".venv.Scripts.activate_this",
"description": ".venv.Scripts.activate_this",
"peekOfCode": "base = bin_dir[: -len(\"Scripts\") - 1] # strip away the bin part from the __file__, plus the path separator\n# prepend bin to PATH (this file is inside the bin directory)\nos.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"..\\\\Lib\\\\site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path)",
"detail": ".venv.Scripts.activate_this",
"documentation": {}
},
{
"label": "os.environ[\"PATH\"]",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "os.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.12/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix",
"detail": ".venv.bin.activate_this",
"importPath": ".venv.Scripts.activate_this",
"description": ".venv.Scripts.activate_this",
"peekOfCode": "os.environ[\"PATH\"] = os.pathsep.join([bin_dir, *os.environ.get(\"PATH\", \"\").split(os.pathsep)])\nos.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"..\\\\Lib\\\\site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix",
"detail": ".venv.Scripts.activate_this",
"documentation": {}
},
{
"label": "os.environ[\"VIRTUAL_ENV\"]",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "os.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.12/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.bin.activate_this",
"importPath": ".venv.Scripts.activate_this",
"description": ".venv.Scripts.activate_this",
"peekOfCode": "os.environ[\"VIRTUAL_ENV\"] = base # virtual env is right above bin directory\nos.environ[\"VIRTUAL_ENV_PROMPT\"] = \"\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"..\\\\Lib\\\\site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.Scripts.activate_this",
"documentation": {}
},
{
"label": "os.environ[\"VIRTUAL_ENV_PROMPT\"]",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "os.environ[\"VIRTUAL_ENV_PROMPT\"] = \"\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"../lib/python3.12/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.bin.activate_this",
"importPath": ".venv.Scripts.activate_this",
"description": ".venv.Scripts.activate_this",
"peekOfCode": "os.environ[\"VIRTUAL_ENV_PROMPT\"] = \"\" or os.path.basename(base) # noqa: SIM222\n# add the virtual environments libraries to the host python import mechanism\nprev_length = len(sys.path)\nfor lib in \"..\\\\Lib\\\\site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.Scripts.activate_this",
"documentation": {}
},
{
"label": "prev_length",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"peekOfCode": "prev_length = len(sys.path)\nfor lib in \"../lib/python3.12/site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.bin.activate_this",
"importPath": ".venv.Scripts.activate_this",
"description": ".venv.Scripts.activate_this",
"peekOfCode": "prev_length = len(sys.path)\nfor lib in \"..\\\\Lib\\\\site-packages\".split(os.pathsep):\n path = os.path.realpath(os.path.join(bin_dir, lib))\n site.addsitedir(path)\nsys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.Scripts.activate_this",
"documentation": {}
},
{
"label": "sys.path[:]",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"importPath": ".venv.Scripts.activate_this",
"description": ".venv.Scripts.activate_this",
"peekOfCode": "sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]\nsys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.bin.activate_this",
"detail": ".venv.Scripts.activate_this",
"documentation": {}
},
{
"label": "sys.real_prefix",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"importPath": ".venv.Scripts.activate_this",
"description": ".venv.Scripts.activate_this",
"peekOfCode": "sys.real_prefix = sys.prefix\nsys.prefix = base",
"detail": ".venv.bin.activate_this",
"detail": ".venv.Scripts.activate_this",
"documentation": {}
},
{
"label": "sys.prefix",
"kind": 5,
"importPath": ".venv.bin.activate_this",
"description": ".venv.bin.activate_this",
"importPath": ".venv.Scripts.activate_this",
"description": ".venv.Scripts.activate_this",
"peekOfCode": "sys.prefix = base",
"detail": ".venv.bin.activate_this",
"detail": ".venv.Scripts.activate_this",
"documentation": {}
},
{
Expand Down Expand Up @@ -873,7 +873,7 @@
"kind": 5,
"importPath": "src.app.api.deps",
"description": "src.app.api.deps",
"peekOfCode": "CurrentUser = Annotated[UserIn, Depends(get_current_user)]\nasync def get_db(user: CurrentUser) -> AsyncClient:\n client: AsyncClient | None = None\n try:\n client = await create_client(\n settings.SUPABASE_URL,\n settings.SUPABASE_KEY,\n access_token=user.access_token,\n options=ClientOptions(\n postgrest_client_timeout=10, storage_client_timeout=10",
"peekOfCode": "CurrentUser = Annotated[UserIn, Depends(get_current_user)]\nasync def get_db(user: CurrentUser) -> AsyncClient:\n client: AsyncClient | None = None\n try:\n client = await create_client(\n settings.SUPABASE_URL,\n settings.SUPABASE_KEY,\n options=ClientOptions(\n postgrest_client_timeout=30,\n storage_client_timeout=30,",
"detail": "src.app.api.deps",
"documentation": {}
},
Expand Down
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"DockerRun.DisableAutoGenerateConfig": true
"DockerRun.DisableAutoGenerateConfig": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies = [
"pydantic[email]>=2.8.2",
"pydantic-settings>=2.4.0",
"python-multipart>=0.0.9",
"supabase-py-async",
"supabase>=2.7.4",
]

[project.optional-dependencies]
Expand Down
7 changes: 0 additions & 7 deletions src/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
"""
-*- coding: utf-8 -*-
@Organization : SupaVision
@Author : 18317
@Date Created : 10/01/2024
@Description :
"""
20 changes: 5 additions & 15 deletions src/app/api/deps.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
"""
-*- coding: utf-8 -*-
@Organization : SupaVision
@Author : 18317
@Date Created : 05/01/2024
@Description :
"""

import logging
from typing import Annotated

from fastapi import Depends, HTTPException
from fastapi.security import OAuth2PasswordBearer
from gotrue.errors import AuthApiError
from supabase_py_async import AsyncClient, create_client
from supabase_py_async.lib.client_options import ClientOptions
from supabase._async.client import AsyncClient, create_client
from supabase.lib.client_options import ClientOptions

from app.core.config import settings
from app.schemas.auth import UserIn
Expand Down Expand Up @@ -62,9 +54,10 @@ async def get_db(user: CurrentUser) -> AsyncClient:
client = await create_client(
settings.SUPABASE_URL,
settings.SUPABASE_KEY,
access_token=user.access_token,
options=ClientOptions(
postgrest_client_timeout=10, storage_client_timeout=10
postgrest_client_timeout=30,
storage_client_timeout=30,
headers={"Authorization": f"Bearer {user.access_token}"},
),
)
# checks all done in supabase-py !
Expand All @@ -77,9 +70,6 @@ async def get_db(user: CurrentUser) -> AsyncClient:
raise HTTPException(
status_code=401, detail="Invalid authentication credentials"
)
finally:
if client:
await client.auth.sign_out()


SessionDep = Annotated[AsyncClient, Depends(get_db)]
8 changes: 0 additions & 8 deletions src/app/core/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
"""
-*- coding: utf-8 -*-
@Organization : SupaVision
@Author : 18317
@Date Created : 05/01/2024
@Description :
"""

import logging
import os
from typing import ClassVar
Expand Down
8 changes: 0 additions & 8 deletions src/app/crud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
"""
-*- coding: utf-8 -*-
@Organization : SupaVision
@Author : 18317
@Date Created : 07/01/2024
@Description :
"""

from .crud_item import item

# For a new basic set of CRUD operations you could just do
Expand Down
2 changes: 1 addition & 1 deletion src/app/crud/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Generic, TypeVar

from supabase_py_async import AsyncClient
from supabase._async.client import AsyncClient

from app.schemas.auth import UserIn
from app.schemas.base import CreateBase, ResponseBase, UpdateBase
Expand Down
2 changes: 1 addition & 1 deletion src/app/crud/crud_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from supabase_py_async import AsyncClient
from supabase._async.client import AsyncClient

from app.crud.base import CRUDBase
from app.schemas import Item, ItemCreate, ItemUpdate
Expand Down
8 changes: 0 additions & 8 deletions src/app/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
"""
-*- coding: utf-8 -*-
@Organization : SupaVision
@Author : 18317
@Date Created : 05/01/2024
@Description :
"""

import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
Expand Down
8 changes: 0 additions & 8 deletions src/app/schemas/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
"""
-*- coding: utf-8 -*-
@Organization : SupaVision
@Author : 18317
@Date Created : 11/01/2024
@Description :
"""

from typing import ClassVar

from pydantic import BaseModel, ConfigDict
Expand Down
Loading

0 comments on commit 4864352

Please sign in to comment.