From 6668f038afea4dbfbb5aeccfa931920a17e47902 Mon Sep 17 00:00:00 2001
From: Juan Carlos <juancarlospaco@gmail.com>
Date: Mon, 22 Apr 2024 18:22:40 -0300
Subject: [PATCH 1/7] Async client WIP

---
 tests/test_async_client_configuration.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 tests/test_async_client_configuration.py

diff --git a/tests/test_async_client_configuration.py b/tests/test_async_client_configuration.py
new file mode 100644
index 00000000..4c6ac768
--- /dev/null
+++ b/tests/test_async_client_configuration.py
@@ -0,0 +1,20 @@
+from __future__ import annotations
+
+from typing import Any
+
+import pytest
+
+
+def test_async_configuration():
+    import httpcore
+    import asyncio
+    import os
+    from supabase._async.client import create_client
+
+    url: str = os.environ.get("SUPABASE_URL")
+    key: str = os.environ.get("SUPABASE_KEY")
+
+    client = asyncio.run(create_client(url, key))
+    data   = [{"item": value} for value in range(0, 100000)]
+
+    asyncio.run(client.table("sample").insert(data).execute())

From 61f4a711769e5a150b5e819274511343b047a5ef Mon Sep 17 00:00:00 2001
From: Juan Carlos <juancarlospaco@gmail.com>
Date: Mon, 22 Apr 2024 18:23:08 -0300
Subject: [PATCH 2/7] Async client WIP

---
 supabase/_async/client.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/supabase/_async/client.py b/supabase/_async/client.py
index 49fee765..7ccad564 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 = asyncio.run(create_client(url, key))
 
     Returns
     -------
-    Client
+    AsyncClient
     """
     return await AsyncClient.create(
         supabase_url=supabase_url, supabase_key=supabase_key, options=options

From 9f7d821f578193c5ca197b251c8eed5ee78e61bc Mon Sep 17 00:00:00 2001
From: Juan Carlos <juancarlospaco@gmail.com>
Date: Mon, 22 Apr 2024 18:23:47 -0300
Subject: [PATCH 3/7] Async client WIP

---
 pyproject.toml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pyproject.toml b/pyproject.toml
index 87015b42..db41c4ae 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -22,6 +22,7 @@ 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"}
 
 [tool.poetry.dev-dependencies]
 pre-commit = "^3.5.0"

From f2c7b2842aa58a7c506749a02dc05ae469f655de Mon Sep 17 00:00:00 2001
From: Juan Carlos <juancarlospaco@gmail.com>
Date: Mon, 29 Apr 2024 22:01:40 -0300
Subject: [PATCH 4/7] wip

---
 supabase/_async/client.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/supabase/_async/client.py b/supabase/_async/client.py
index 7ccad564..2e07b88d 100644
--- a/supabase/_async/client.py
+++ b/supabase/_async/client.py
@@ -292,7 +292,7 @@ async def create_client(
     >>>
     >>> url: str = os.environ.get("SUPABASE_TEST_URL")
     >>> key: str = os.environ.get("SUPABASE_TEST_KEY")
-    >>> supabase: AsyncClient = asyncio.run(create_client(url, key))
+    >>> supabase: AsyncClient = await asyncio.create_task(create_client(url, key))
 
     Returns
     -------

From b30fabce771fc8d46b35a8eb1fdcf145bd5a5c77 Mon Sep 17 00:00:00 2001
From: Juan Carlos <juancarlospaco@gmail.com>
Date: Mon, 29 Apr 2024 22:04:00 -0300
Subject: [PATCH 5/7] wip

---
 pyproject.toml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/pyproject.toml b/pyproject.toml
index da760978..23adc1cc 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -23,6 +23,7 @@ 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"

From 1ad6a914e11a6d02d701e347e353687bf56a7b25 Mon Sep 17 00:00:00 2001
From: Juan Carlos <juancarlospaco@gmail.com>
Date: Mon, 29 Apr 2024 22:11:34 -0300
Subject: [PATCH 6/7] update test

---
 tests/test_async_client_configuration.py | 32 ++++++++++++++++--------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/tests/test_async_client_configuration.py b/tests/test_async_client_configuration.py
index 4c6ac768..e268ebc8 100644
--- a/tests/test_async_client_configuration.py
+++ b/tests/test_async_client_configuration.py
@@ -1,20 +1,30 @@
-from __future__ import annotations
-
-from typing import Any
+import asyncio
+import os
 
 import pytest
 
+from supabase._async.client import create_client
+
+pytest_plugins = ("pytest_asyncio", )
 
-def test_async_configuration():
-    import httpcore
-    import asyncio
-    import os
-    from supabase._async.client import create_client
 
+@pytest.mark.asyncio
+async def test_async_configuration():
     url: str = os.environ.get("SUPABASE_URL")
     key: str = os.environ.get("SUPABASE_KEY")
 
-    client = asyncio.run(create_client(url, key))
-    data   = [{"item": value} for value in range(0, 100000)]
+    """
+    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)]
 
-    asyncio.run(client.table("sample").insert(data).execute())
+    # 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()

From 4de10f0fea4a1a491f45cf08c637e6854dcd5756 Mon Sep 17 00:00:00 2001
From: Juan Carlos <juancarlospaco@gmail.com>
Date: Mon, 29 Apr 2024 22:15:38 -0300
Subject: [PATCH 7/7] update test

---
 tests/test_async_client_configuration.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/test_async_client_configuration.py b/tests/test_async_client_configuration.py
index e268ebc8..134dcfc2 100644
--- a/tests/test_async_client_configuration.py
+++ b/tests/test_async_client_configuration.py
@@ -10,8 +10,8 @@
 
 @pytest.mark.asyncio
 async def test_async_configuration():
-    url: str = os.environ.get("SUPABASE_URL")
-    key: str = os.environ.get("SUPABASE_KEY")
+    url: str = os.environ.get("SUPABASE_TEST_URL")
+    key: str = os.environ.get("SUPABASE_TEST_KEY")
 
     """
     Initializing an AsynClient: