8000 feat: allow injection of httpx client by silentworks · Pull Request #591 · supabase/postgrest-py · GitHub
[go: up one dir, main page]

Skip to content

feat: allow injection of httpx client #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 14, 2025
Merged
Prev Previous commit
Next Next commit
change client property name to standardise with the auth client
  • Loading branch information
silentworks committed Apr 30, 2025
commit d34d99e81efabdd69936b7a68255d29d3853a473
14 changes: 7 additions & 7 deletions postgrest/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
verify: bool = True,
proxy: Optional[str] = None,
client: Union[AsyncClient, None] = None,
http_client: Union[AsyncClient, None] = None,
) -> None:
BasePostgrestClient.__init__(
self,
Expand All @@ -40,7 +40,7 @@ def __init__(
timeout=timeout,
verify=verify,
proxy=proxy,
client=client,
http_client=http_client,
)
self.session = cast(AsyncClient, self.session)

Expand All @@ -51,12 +51,12 @@ def create_session(
timeout: Union[int, float, Timeout],
verify: bool = True,
proxy: Optional[str] = None,
client: Union[AsyncClient, None] = None,
http_client: Union[AsyncClient, None] = None,
) -> AsyncClient:
if client is not None:
client.base_url = base_url
client.headers = headers
return client
if http_client is not None:
http_client.base_url = base_url
http_client.headers = headers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also pass timeout, verify, proxy, here?

Copy link
Contributor Author
@silentworks silentworks May 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't pass those as I don't want them to be override the options for httpx client the developer will pass. The only options we need to maintain are the base_url and headers. The others should be manually configured by the developer if they are passing their own httpx client.

Copy link
Contributor
@grdsdev grdsdev May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, let us at least deprecate the usage of the other params in favor of the httpx client as in https://github.com/supabase/functions-py/pull/201/files#r2083278694

return http_client

return AsyncClient(
base_url=base_url,
Expand Down
14 changes: 7 additions & 7 deletions postgrest/_sync/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(
timeout: Union[int, float, Timeout] = DEFAULT_POSTGREST_CLIENT_TIMEOUT,
verify: bool = True,
proxy: Optional[str] = None,
client: Union[SyncClient, None] = None,
http_client: Union[SyncClient, None] = None,
) -> None:
BasePostgrestClient.__init__(
self,
Expand All @@ -40,7 +40,7 @@ def __init__(
timeout=timeout,
verify=verify,
proxy=proxy,
client=client,
http_client=http_client,
)
self.session = cast(SyncClient, self.session)

Expand All @@ -51,12 +51,12 @@ def create_session(
timeout: Union[int, float, Timeout],
verify: bool = True,
proxy: Optional[str] = None,
client: Union[SyncClient, None] = None,
http_client: Union[SyncClient, None] = None,
) -> SyncClient:
if client is not None:
client.base_url = base_url
client.headers = headers
return client
if http_client is not None:
http_client.base_url = base_url
http_client.headers = headers
return http_client

return SyncClient(
base_url=base_url,
Expand Down
8 changes: 4 additions & 4 deletions postgrest/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(
timeout: Union[int, float, Timeout],
verify: bool = True,
proxy: Optional[str] = None,
client: Union[SyncClient, AsyncClient, None] = None,
http_client: Union[SyncClient, AsyncClient, None] = None,
) -> None:
if not is_http_url(base_url):
ValueError("base_url must be a valid HTTP URL string")
Expand All @@ -34,14 +34,14 @@ def __init__(
self.timeout = timeout
self.verify = verify
self.proxy = proxy
self.client = client
self.http_client = http_client
self.session = self.create_session(
self.base_url,
self.headers,
self.timeout,
self.verify,
self.proxy,
self.client,
self.http_client,
)

@abstractmethod
Expand All @@ -52,7 +52,7 @@ def create_session(
timeout: Union[int, float, Timeout],
verify: bool = True,
proxy: Optional[str] = None,
client: Union[SyncClient, AsyncClient, None] = None,
http_client: Union[SyncClient, AsyncClient, None] = None,
) -> Union[SyncClient, AsyncClient]:
raise NotImplementedError()

Expand Down
0