diff --git a/pyproject.toml b/pyproject.toml index 3f608bfc..23adc1cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,8 @@ gotrue = ">=1.3,<3.0" httpx = ">=0.24,<0.28" storage3 = ">=0.5.3,<0.8.0" supafunc = ">=0.3.1,<0.5.0" +httpcore = {extras = ["asyncio"], version = "^1.0.5"} +pytest-asyncio = "^0.23.6" [tool.poetry.dev-dependencies] pre-commit = "^3.5.0" diff --git a/supabase/_async/client.py b/supabase/_async/client.py index 49fee765..2e07b88d 100644 --- a/supabase/_async/client.py +++ b/supabase/_async/client.py @@ -232,7 +232,7 @@ def _init_postgrest_client( rest_url: str, headers: Dict[str, str], schema: str, - timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT, + timeout: Union[int, float, Timeout] = None, ) -> AsyncPostgrestClient: """Private helper for creating an instance of the Postgrest client.""" return AsyncPostgrestClient( @@ -285,16 +285,18 @@ async def create_client( Examples -------- Instantiating the client. + >>> import httpcore + >>> import asyncio >>> import os - >>> from supabase import create_client, Client + >>> from supabase._async.client import create_client >>> >>> url: str = os.environ.get("SUPABASE_TEST_URL") >>> key: str = os.environ.get("SUPABASE_TEST_KEY") - >>> supabase: Client = create_client(url, key) + >>> supabase: AsyncClient = await asyncio.create_task(create_client(url, key)) Returns ------- - Client + AsyncClient """ return await AsyncClient.create( supabase_url=supabase_url, supabase_key=supabase_key, options=options diff --git a/tests/test_async_client_configuration.py b/tests/test_async_client_configuration.py new file mode 100644 index 00000000..134dcfc2 --- /dev/null +++ b/tests/test_async_client_configuration.py @@ -0,0 +1,30 @@ +import asyncio +import os + +import pytest + +from supabase._async.client import create_client + +pytest_plugins = ("pytest_asyncio", ) + + +@pytest.mark.asyncio +async def test_async_configuration(): + url: str = os.environ.get("SUPABASE_TEST_URL") + key: str = os.environ.get("SUPABASE_TEST_KEY") + + """ + Initializing an AsynClient: + Using asyncio.create_task instead of asyncio.run allows you to reuse + the same client across different request, avoiding an event loop error. + """ + + client = await asyncio.create_task(create_client(url, key)) + data = [{"item": value} for value in range(0, 100000)] + + # insert + await client.table("sample").insert(data).execute() + # select + await client.table("sample").select("*").execute() + # delete + await client.table("sample").delete().gt("item", 100).execute()