Skip to content

Commit 021f1b6

Browse files
authored
fix: remove reliance on SyncClient and use Client directly from httpx (#607)
- fix: add deprecation warnings for SyncClient - test: update to use Client instead of SyncClient - chore: remove deprecated classes Client and GetRequestBuilder
1 parent af2f23f commit 021f1b6

22 files changed

+73
-94
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ build_sync: run_unasync remove_pytest_asyncio_from_sync
3636
remove_pytest_asyncio_from_sync:
3737
sed -i 's/@pytest.mark.asyncio//g' tests/_sync/test_client.py
3838
sed -i 's/_async/_sync/g' tests/_sync/test_client.py
39-
sed -i 's/Async/Sync/g' tests/_sync/test_client.py
40-
sed -i 's/Async/Sync/g' postgrest/_sync/request_builder.py
39+
sed -i 's/Async/Sync/g' postgrest/_sync/request_builder.py tests/_sync/test_client.py
4140
sed -i 's/_client\.SyncClient/_client\.Client/g' tests/_sync/test_client.py
42-
sed -i 's/SyncHTTPTransport/HTTPTransport/g' tests/_sync/test_client.py
43-
sed -i 's/SyncHTTPTransport/HTTPTransport/g' tests/_sync/client.py
41+
sed -i 's/SyncHTTPTransport/HTTPTransport/g' tests/_sync/**.py
42+
sed -i 's/SyncClient/Client/g' postgrest/_sync/**.py tests/_sync/**.py
43+
sed -i 's/self\.session\.aclose/self\.session\.close/g' postgrest/_sync/client.py
4444

4545
sleep:
4646
sleep 2

postgrest/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
)
2525
from .base_request_builder import APIResponse
2626
from .constants import DEFAULT_POSTGREST_CLIENT_HEADERS
27-
from .deprecated_client import Client, PostgrestClient
28-
from .deprecated_get_request_builder import GetRequestBuilder
2927
from .exceptions import APIError
3028
from .types import (
3129
CountMethod,
@@ -54,9 +52,6 @@
5452
"SyncSingleRequestBuilder",
5553
"APIResponse",
5654
"DEFAULT_POSTGREST_CLIENT_HEADERS",
57-
"Client",
58-
"PostgrestClient",
59-
"GetRequestBuilder",
6055
"APIError",
6156
"CountMethod",
6257
"Filters",

postgrest/_async/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
from warnings import warn
55

66
from deprecation import deprecated
7-
from httpx import Headers, QueryParams, Timeout
7+
from httpx import AsyncClient, Headers, QueryParams, Timeout
88

99
from ..base_client import BasePostgrestClient
1010
from ..constants import (
1111
DEFAULT_POSTGREST_CLIENT_HEADERS,
1212
DEFAULT_POSTGREST_CLIENT_TIMEOUT,
1313
)
1414
from ..types import CountMethod
15-
from ..utils import AsyncClient
1615
from ..version import __version__
1716
from .request_builder import AsyncRequestBuilder, AsyncRPCFilterRequestBuilder
1817

postgrest/_async/request_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Any, Generic, Optional, TypeVar, Union
44

5-
from httpx import Headers, QueryParams
5+
from httpx import AsyncClient, Headers, QueryParams
66
from pydantic import ValidationError
77

88
from ..base_request_builder import (
@@ -20,7 +20,7 @@
2020
)
2121
from ..exceptions import APIError, APIErrorFromJSON, generate_default_error_message
2222
from ..types import ReturnMethod
23-
from ..utils import AsyncClient, get_origin_and_cast
23+
from ..utils import get_origin_and_cast
2424

2525
_ReturnT = TypeVar("_ReturnT")
2626

postgrest/_sync/client.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
from warnings import warn
55

66
from deprecation import deprecated
7-
from httpx import Headers, QueryParams, Timeout
7+
from httpx import Client, Headers, QueryParams, Timeout
88

99
from ..base_client import BasePostgrestClient
1010
from ..constants import (
1111
DEFAULT_POSTGREST_CLIENT_HEADERS,
1212
DEFAULT_POSTGREST_CLIENT_TIMEOUT,
1313
)
1414
from ..types import CountMethod
15-
from ..utils import SyncClient
1615
from ..version import __version__
1716
from .request_builder import SyncRequestBuilder, SyncRPCFilterRequestBuilder
1817

@@ -31,7 +30,7 @@ def __init__(
3130
timeout: Union[int, float, Timeout, None] = None,
3231
verify: Optional[bool] = None,
3332
proxy: Optional[str] = None,
34-
http_client: Optional[SyncClient] = None,
33+
http_client: Optional[Client] = None,
3534
) -> None:
3635
if timeout is not None:
3736
warn(
@@ -73,7 +72,7 @@ def __init__(
7372
proxy=proxy,
7473
http_client=http_client,
7574
)
76-
self.session = cast(SyncClient, self.session)
75+
self.session = cast(Client, self.session)
7776

7877
def create_session(
7978
self,
@@ -82,17 +81,17 @@ def create_session(
8281
timeout: Union[int, float, Timeout],
8382
verify: bool = True,
8483
proxy: Optional[str] = None,
85-
) -> SyncClient:
84+
) -> Client:
8685
http_client = None
87-
if isinstance(self.http_client, SyncClient):
86+
if isinstance(self.http_client, Client):
8887
http_client = self.http_client
8988

9089
if http_client is not None:
9190
http_client.base_url = base_url
9291
http_client.headers.update({**headers})
9392
return http_client
9493

95-
return SyncClient(
94+
return Client(
9695
base_url=base_url,
9796
headers=headers,
9897
timeout=timeout,
@@ -121,7 +120,7 @@ def __exit__(self, exc_type, exc, tb) -> None:
121120

122121
def aclose(self) -> None:
123122
"""Close the underlying HTTP connections."""
124-
self.session.aclose()
123+
self.session.close()
125124

126125
def from_(self, table: str) -> SyncRequestBuilder[_TableT]:
127126
"""Perform a table operation.

postgrest/_sync/request_builder.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Any, Generic, Optional, TypeVar, Union
44

5-
from httpx import Headers, QueryParams
5+
from httpx import Client, Headers, QueryParams
66
from pydantic import ValidationError
77

88
from ..base_request_builder import (
@@ -20,15 +20,15 @@
2020
)
2121
from ..exceptions import APIError, APIErrorFromJSON, generate_default_error_message
2222
from ..types import ReturnMethod
23-
from ..utils import SyncClient, get_origin_and_cast
23+
from ..utils import get_origin_and_cast
2424

2525
_ReturnT = TypeVar("_ReturnT")
2626

2727

2828
class SyncQueryRequestBuilder(Generic[_ReturnT]):
2929
def __init__(
3030
self,
31-
session: SyncClient,
31+
session: Client,
3232
path: str,
3333
http_method: str,
3434
headers: Headers,
@@ -83,7 +83,7 @@ def execute(self) -> APIResponse[_ReturnT]:
8383
class SyncSingleRequestBuilder(Generic[_ReturnT]):
8484
def __init__(
8585
self,
86-
session: SyncClient,
86+
session: Client,
8787
path: str,
8888
http_method: str,
8989
headers: Headers,
@@ -152,7 +152,7 @@ def execute(self) -> Optional[SingleAPIResponse[_ReturnT]]:
152152
class SyncFilterRequestBuilder(BaseFilterRequestBuilder[_ReturnT], SyncQueryRequestBuilder[_ReturnT]): # type: ignore
153153
def __init__(
154154
self,
155-
session: SyncClient,
155+
session: Client,
156156
path: str,
157157
http_method: str,
158158
headers: Headers,
@@ -173,7 +173,7 @@ class SyncRPCFilterRequestBuilder(
173173
):
174174
def __init__(
175175
self,
176-
session: SyncClient,
176+
session: Client,
177177
path: str,
178178
http_method: str,
179179
headers: Headers,
@@ -192,7 +192,7 @@ def __init__(
192192
class SyncSelectRequestBuilder(BaseSelectRequestBuilder[_ReturnT], SyncQueryRequestBuilder[_ReturnT]): # type: ignore
193193
def __init__(
194194
self,
195-
session: SyncClient,
195+
session: Client,
196196
path: str,
197197
http_method: str,
198198
headers: Headers,
@@ -271,7 +271,7 @@ def csv(self) -> SyncSingleRequestBuilder[str]:
271271

272272

273273
class SyncRequestBuilder(Generic[_ReturnT]):
274-
def __init__(self, session: SyncClient, path: str) -> None:
274+
def __init__(self, session: Client, path: str) -> None:
275275
self.session = session
276276
self.path = path
277277

postgrest/base_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from abc import ABC, abstractmethod
44
from typing import Dict, Optional, Union
55

6-
from httpx import BasicAuth, Timeout
6+
from httpx import AsyncClient, BasicAuth, Client, Timeout
77

8-
from .utils import AsyncClient, SyncClient, is_http_url, is_valid_jwt
8+
from .utils import is_http_url, is_valid_jwt
99

1010

1111
class BasePostgrestClient(ABC):
@@ -20,7 +20,7 @@ def __init__(
2020
timeout: Union[int, float, Timeout],
2121
verify: bool = True,
2222
proxy: Optional[str] = None,
23-
http_client: Union[SyncClient, AsyncClient, None] = None,
23+
http_client: Union[Client, AsyncClient, None] = None,
2424
) -> None:
2525
if not is_http_url(base_url):
2626
ValueError("base_url must be a valid HTTP URL string")
@@ -51,7 +51,7 @@ def create_session(
5151
timeout: Union[int, float, Timeout],
5252
verify: bool = True,
5353
proxy: Optional[str] = None,
54-
) -> Union[SyncClient, AsyncClient]:
54+
) -> Union[Client, AsyncClient]:
5555
raise NotImplementedError()
5656

5757
def auth(

postgrest/base_request_builder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Union,
1919
)
2020

21-
from httpx import Headers, QueryParams
21+
from httpx import AsyncClient, Client, Headers, QueryParams
2222
from httpx import Response as RequestResponse
2323
from pydantic import BaseModel
2424

@@ -35,7 +35,7 @@
3535
from pydantic import validator as field_validator
3636

3737
from .types import CountMethod, Filters, RequestMethod, ReturnMethod
38-
from .utils import AsyncClient, SyncClient, get_origin_and_cast, sanitize_param
38+
from .utils import get_origin_and_cast, sanitize_param
3939

4040

4141
class QueryArgs(NamedTuple):
@@ -255,7 +255,7 @@ def from_dict(cls: Type[Self], dict: Dict[str, Any]) -> Self:
255255
class BaseFilterRequestBuilder(Generic[_ReturnT]):
256256
def __init__(
257257
self,
258-
session: Union[AsyncClient, SyncClient],
258+
session: Union[AsyncClient, Client],
259259
headers: Headers,
260260
params: QueryParams,
261261
) -> None:
@@ -530,7 +530,7 @@ def match(self: Self, query: Dict[str, Any]) -> Self:
530530
class BaseSelectRequestBuilder(BaseFilterRequestBuilder[_ReturnT]):
531531
def __init__(
532532
self,
533-
session: Union[AsyncClient, SyncClient],
533+
session: Union[AsyncClient, Client],
534534
headers: Headers,
535535
params: QueryParams,
536536
) -> None:
@@ -636,7 +636,7 @@ def range(
636636
class BaseRPCRequestBuilder(BaseSelectRequestBuilder[_ReturnT]):
637637
def __init__(
638638
self,
639-
session: Union[AsyncClient, SyncClient],
639+
session: Union[AsyncClient, Client],
640640
headers: Headers,
641641
params: QueryParams,
642642
) -> None:

postgrest/deprecated_client.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

postgrest/deprecated_get_request_builder.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

postgrest/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@
44
from typing import Any, Type, TypeVar, cast, get_origin
55
from urllib.parse import urlparse
66

7+
from deprecation import deprecated
78
from httpx import AsyncClient # noqa: F401
89
from httpx import Client as BaseClient # noqa: F401
910

11+
from .version import __version__
12+
1013
BASE64URL_REGEX = r"^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}$|[a-z0-9_-]{2}$)$"
1114

1215

1316
class SyncClient(BaseClient):
17+
@deprecated(
18+
"1.0.2", "1.3.0", __version__, "Use `Client` from the httpx package instead"
19+
)
20+
def __init__(self, *args, **kwargs) -> None:
21+
super().__init__(*args, **kwargs)
22+
23+
@deprecated(
24+
"1.0.2",
25+
"1.3.0",
26+
__version__,
27+
"Use `close` method from `Client` in the httpx package instead",
28+
)
1429
def aclose(self) -> None:
1530
self.close()
1631

tests/_async/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from httpx import AsyncHTTPTransport, Limits
1+
from httpx import AsyncClient, AsyncHTTPTransport, Limits
22

33
from postgrest import AsyncPostgrestClient
4-
from postgrest.utils import AsyncClient
54

65
REST_URL = "http://127.0.0.1:3000"
76

tests/_async/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44
from httpx import (
5+
AsyncClient,
56
AsyncHTTPTransport,
67
BasicAuth,
78
Headers,
@@ -13,7 +14,6 @@
1314

1415
from postgrest import AsyncPostgrestClient
1516
from postgrest.exceptions import APIError
16-
from postgrest.utils import AsyncClient
1717

1818

1919
@pytest.fixture

tests/_async/test_filter_request_builder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import pytest
2-
from httpx import Headers, QueryParams
2+
from httpx import AsyncClient, Headers, QueryParams
33

44
from postgrest import AsyncFilterRequestBuilder
5-
from postgrest.utils import AsyncClient
65

76

87
@pytest.fixture

tests/_async/test_query_request_builder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import pytest
2-
from httpx import Headers, QueryParams
2+
from httpx import AsyncClient, Headers, QueryParams
33

44
from postgrest import AsyncQueryRequestBuilder
5-
from postgrest.utils import AsyncClient
65

76

87
@pytest.fixture

0 commit comments

Comments
 (0)