Skip to content

Commit 37a9eba

Browse files
MarkDaoustcopybara-github
authored andcommitted
feat(client)!: Replace httpx with httpx2 and use OS trust store by default
BREAKING CHANGE: Replaced httpx with httpx2 across the SDK, removed legacy httpx fallback support and GOOGLE_GENAI_HTTP_CLIENT switching, and switched the default httpx2 SSL context to use the OS certificate trust store (via truststore / httpx2.create_ssl_context()) when SSL_CERT_FILE and SSL_CERT_DIR are not set. The Interactions client is now generated with Speakeasy's `httpClientLibrary: httpx2`, and `httpx2` is a required dependency of the package (the `httpx` dependency and the `httpx2` extra are removed). #2680 PiperOrigin-RevId: 1004152308
1 parent 26f9707 commit 37a9eba

61 files changed

Lines changed: 430 additions & 838 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -250,37 +250,11 @@ client = genai.Client(
250250
)
251251
```
252252

253-
### HTTP client option: httpx2
254-
255-
By default, the SDK uses `httpx` for its HTTP transport. You can opt in to
256-
[`httpx2`](https://github.com/pydantic/httpx2) by installing `google-genai[httpx2]`
257-
and setting the `GOOGLE_GENAI_HTTP_CLIENT` environment variable:
258-
259-
```bash
260-
export GOOGLE_GENAI_HTTP_CLIENT=httpx2
261-
```
262-
263-
Alternatively, you can directly inject an `httpx2.Client` or `httpx2.AsyncClient`
264-
via `HttpOptions`:
265-
266-
```python
267-
import httpx2
268-
from google import genai
269-
from google.genai import types
270-
271-
client = genai.Client(
272-
http_options=types.HttpOptions(
273-
httpx_client=httpx2.Client(),
274-
httpx_async_client=httpx2.AsyncClient(),
275-
)
276-
)
277-
```
278-
279253
### Faster async client option: Aiohttp
280254

281-
By default we use httpx for both sync and async client implementations. In order
255+
By default we use httpx2 for both sync and async client implementations. In order
282256
to have faster performance, you may install `google-genai[aiohttp]`. In Gen AI
283-
SDK we configure `trust_env=True` to match with the default behavior of httpx.
257+
SDK we configure `trust_env=True` to match with the default behavior of httpx2.
284258
Additional args of `aiohttp.ClientSession.request()` ([see `_RequestOptions` args](https://github.com/aio-libs/aiohttp/blob/v3.12.13/aiohttp/client.py#L170)) can be passed
285259
through the following way:
286260

@@ -295,7 +269,7 @@ client=Client(..., http_options=http_options)
295269

296270
### Proxy
297271

298-
Both httpx and aiohttp libraries use `urllib.request.getproxies` from
272+
Both httpx2 and aiohttp libraries use `urllib.request.getproxies` from
299273
environment variables. Before client initialization, you may set proxy (and
300274
optional `SSL_CERT_FILE`) by setting the environment variables:
301275

@@ -304,8 +278,8 @@ export HTTPS_PROXY='http://username:password@proxy_uri:port'
304278
export SSL_CERT_FILE='client.pem'
305279
```
306280

307-
If you need `socks5` proxy, httpx [supports](https://www.python-httpx.org/advanced/proxies/#socks) `socks5` proxy if you pass it via
308-
args to `httpx.Client()`. You may install `httpx[socks]` to use it.
281+
If you need `socks5` proxy, httpx2 [supports](https://www.python-httpx.org/advanced/proxies/#socks) `socks5` proxy if you pass it via
282+
args to `httpx2.Client()`. You may install `httpx2[socks]` to use it.
309283
Then, you can pass it through the following way:
310284

311285
```python

‎docs/source/index.rst‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ To set the API version to `v1alpha` for the Gemini Developer API:
218218
Faster async client option: Aiohttp
219219
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
220220

221-
By default we use httpx for both sync and async client implementations. In order
221+
By default we use httpx2 for both sync and async client implementations. In order
222222
to have faster performance, you may install `google-genai[aiohttp]`. In Gen AI
223-
SDK we configure `trust_env=True` to match with the default behavior of httpx.
223+
SDK we configure `trust_env=True` to match with the default behavior of httpx2.
224224
Additional args of `aiohttp.ClientSession.request()`
225225
(`see _RequestOptions args <https://github.com/aio-libs/aiohttp/blob/v3.12.13/aiohttp/client.py#L170>`_)
226226
can be passed through the following way:
@@ -237,7 +237,7 @@ can be passed through the following way:
237237
Proxy
238238
^^^^^^^
239239

240-
Both httpx and aiohttp libraries use `urllib.request.getproxies` from
240+
Both httpx2 and aiohttp libraries use `urllib.request.getproxies` from
241241
environment variables. Before client initialization, you may set proxy (and
242242
optional SSL_CERT_FILE) by setting the environment variables:
243243

@@ -248,9 +248,9 @@ optional SSL_CERT_FILE) by setting the environment variables:
248248
export SSL_CERT_FILE='client.pem'
249249
250250
251-
If you need `socks5` proxy, httpx `supports <https://www.python-httpx.org/advanced/proxies/#socks>`_
252-
`socks5` proxy if you pass it via args to httpx.Client(). You may install
253-
`httpx[socks]` to use it. Then you can pass it through the following way:
251+
If you need `socks5` proxy, httpx2 `supports <https://www.python-httpx.org/advanced/proxies/#socks>`_
252+
`socks5` proxy if you pass it via args to httpx2.Client(). You may install
253+
`httpx2[socks]` to use it. Then you can pass it through the following way:
254254

255255
.. code:: python
256256

0 commit comments

Comments
 (0)