APIMatic Requests Client Adapter

0.1.10 · active · verified Fri Apr 17

`apimatic-requests-client-adapter` is a Python library that provides an adapter for the popular `requests` HTTP client library. It is specifically designed to be consumed by SDKs generated with APIMatic, allowing them to leverage `requests` for making HTTP calls while integrating APIMatic's configuration, retry logic, and other features. The library is actively maintained with a somewhat irregular but frequent release cadence, and its current version is 0.1.10.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate the `RequestsClient` adapter. It involves creating a `RequestsClientConfig` object (from `apimatic-core`) to define HTTP client behavior and optionally a `requests.Session` for advanced session management. The `RequestsClient` instance is then ready to be passed into an APIMatic-generated SDK client.

from requests import Session
from apimatic_core.request_builders.requests_client_config import RequestsClientConfig
from apimatic_requests_client_adapter.requests_client import RequestsClient

# 1. Configure the RequestsClient using RequestsClientConfig
# This object defines behaviors like timeouts, retries, and proxy settings.
client_config = RequestsClientConfig(
    timeout=30,
    max_retries=3,
    backoff_factor=0.5,
    retry_status_codes=[408, 413, 429, 500, 502, 503, 504],
    verify=True,
    # Proxy support added in v0.1.8+
    # proxies={'http': 'http://my.proxy.com:8080', 'https': 'https://my.proxy.com:8080'}
)

# 2. Optionally, create a pre-configured requests.Session object.
# This allows sharing session state (like cookies) across requests.
session = Session()
# You could configure the session further here, e.g., session.proxies = {'http': '...', 'https': '...'}

# 3. Instantiate the RequestsClient adapter.
# This client implements the IHttpClient interface expected by APIMatic SDKs.
# If requests_session is not provided, an internal Session is created.
# If client_config is not provided, default configurations are used.
requests_client_adapter = RequestsClient(
    requests_client_config=client_config,
    requests_session=session
)

print(f"APIMatic Requests Client Adapter created. Timeout: {requests_client_adapter._requests_client_config.timeout}s")
# This adapter is typically passed to an APIMatic-generated SDK client, e.g.:
# my_sdk_client = MyAPISDKClient(http_client_instance=requests_client_adapter)

view raw JSON →