APIMatic Requests Client Adapter
raw JSON → 0.1.10 verified Fri Apr 17 auth: no python
`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.
pip install apimatic-requests-client-adapter Common errors
error ModuleNotFoundError: No module named 'apimatic_requests_client_adapter' ↓
cause The `apimatic-requests-client-adapter` library is not installed in your current Python environment.
fix
Run
pip install apimatic-requests-client-adapter to install the library. error TypeError: RequestsClientConfig.__init__() got an unexpected keyword argument 'proxies' ↓
cause You are trying to use a configuration parameter (like `proxies` or `http_client_instance`) that was introduced in a newer version of `apimatic-requests-client-adapter` or `apimatic-core` with an older installed version.
fix
Upgrade both
apimatic-requests-client-adapter and apimatic-core to their latest versions: pip install --upgrade apimatic-requests-client-adapter apimatic-core. error ModuleNotFoundError: No module named 'apimatic_core' ↓
cause The `apimatic-core` library, which provides the `RequestsClientConfig` class essential for configuring `RequestsClient`, is not installed.
fix
Run
pip install apimatic-core to install the dependency. error AttributeError: 'RequestsClient' object has no attribute 'get' ↓
cause You are attempting to use the `RequestsClient` adapter directly like a `requests.Session` object to make HTTP requests. `RequestsClient` implements an `IHttpClient` interface and is meant to be passed to an APIMatic-generated SDK client, which then exposes the high-level API methods.
fix
Instantiate an APIMatic-generated SDK client and pass the
RequestsClient instance to it. If you need raw requests-style functionality, use the requests library directly. Warnings
gotcha This library is primarily an internal component for APIMatic-generated SDKs. While you can instantiate `RequestsClient` directly, its main purpose is to be passed as an `IHttpClient` interface implementation to an SDK client for making API calls. Direct standalone usage for raw HTTP requests is less common; for that, consider using the `requests` library directly. ↓
fix Ensure you are using the `RequestsClient` as intended, typically by injecting it into an APIMatic-generated SDK client instance.
deprecated Older versions (prior to 0.1.8) lacked first-class proxy support via the `RequestsClientConfig`. While proxies could be configured manually on a `requests.Session` object, direct configuration through the `client_config` was not available. ↓
fix Upgrade to version 0.1.8 or newer and use the `proxies` dictionary parameter within `RequestsClientConfig` for straightforward proxy setup.
gotcha Prior to version 0.1.9, injecting an arbitrary custom HTTP client or a pre-configured `requests.Session` directly through a defined interface was less flexible. This could complicate scenarios requiring highly customized HTTP client behavior beyond what `RequestsClientConfig` offered. ↓
fix Upgrade to version 0.1.9 or newer. This version introduced support for passing a custom `requests.Session` object directly to `RequestsClient` or injecting a custom HTTP client instance via `http_client_instance` in `RequestsClientConfig`.
breaking As a 0.x.x version library, minor version updates (e.g., 0.1.x to 0.2.x) can introduce breaking changes without strictly adhering to semantic versioning. Always review the GitHub release notes when updating across minor versions. ↓
fix Consult the GitHub releases page or changelog for your specific versions before upgrading, paying close attention to any mentioned breaking changes or necessary migration steps.
Imports
- RequestsClient wrong
from apimatic_requests_client_adapter import RequestsClientcorrectfrom apimatic_requests_client_adapter.requests_client import RequestsClient - RequestsClientConfig
from apimatic_core.request_builders.requests_client_config import RequestsClientConfig
Quickstart
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)