Skip to main content

Moving Python v4 SDKs to httpx 2

· 2 min read

Python v4 SDKs now depend on httpx2 in place of httpx. The upgrade brings the SDK onto the 2.x line of its HTTP library while keeping the client surface you already use unchanged.

Details​

The default transports are now Httpx2Client and AsyncHttpx2Client, replacing HttpxClient and AsyncHttpxClient. TLS verification stays on by default and keeps the trust order the SDK shipped with: SSL_CERT_FILE, then SSL_CERT_DIR, then the certifi bundle, so no configuration change is needed to keep the behavior you had. To set a proxy, a private CA or a client certificate, build an Httpx2Client yourself and pass it to the client as custom_http_client.

The generated pyproject.toml now declares httpx2 (>=2.13.1,<3.0.0). Regenerate to pick up the new dependency, and update any code that imported the old transport names or caught httpx exceptions, which are now raised from httpx2.

Usage Example​

Build the transport yourself when the defaults do not fit, and hand it to the client:

import ssl

from payments import PaymentsClient
from payments.core import Httpx2Client

transport = Httpx2Client(
timeout=10.0,
proxy_url="http://proxy.internal:3128",
verify=ssl.create_default_context(cafile="corp-ca.pem"),
)
client = PaymentsClient(bearer_auth="YOUR_ACCESS_TOKEN", custom_http_client=transport)

The async client takes an AsyncHttpx2Client through custom_async_http_client instead.

This change is available in the Python v4 SDK. Generate it with version 2.x of the APIMatic CLI:

apimatic sdk generate --language=python

For the full set of flags and options, see the APIMatic CLI documentation.