Client & Config API
Reference for creating instances and request configuration
Client & Configuration API
The AxiosPython Client
While you can use global module-level functions (axios_python.get()), it is highly recommended to create dedicated client instances for distinct external services.
Each instance maintains its own:
- Base Configuration (e.g.,
base_url,headers) - Request and Response Interceptors
- Middleware Pipeline
- Plugin Architecture
- Transport Connection Pool
Creating an Instance
Create a new client instance using the factory method instead of instantiating the class directly.
import axios_python
github_api = axios_python.create({
"base_url": "https://api.github.com",
"timeout": 5,
"headers": {
"Accept": "application/vnd.github.v3+json"
}
})Request Configuration Reference
You can pass the following properties to axios_python.create(config) (as defaults) or as overrides to individual request methods (api.get("/url", **kwargs)):
| Property | Type | Description |
|---|---|---|
base_url | str | Base URL attached to relative paths. |
method | str | HTTP Method (e.g., "GET", "POST", "HEAD", "OPTIONS"). |
url | str | The target path or absolute URL. |
headers | dict | Dictionary of HTTP headers. |
params | dict | URL Query parameters. |
data | Any | Request body content (raw). |
json | Any | Request body content (automatically serialized to JSON). |
files | Any | Multipart-encoded files dictionary. |
stream | bool | Stream the response (Default: False). |
timeout | float | Max seconds to wait for a response (Default: 30). |
follow_redirects | bool | Whether to automatically follow HTTP redirects (Default: True). |
transform_request | list[Callable] | Functions to manipulate data/headers before sending. |
transform_response | list[Callable] | Functions to manipulate response data before returning. |
max_retries | int | Maximum retry attempts on failure (Default: 0). |
retry_strategy | RetryStrategy | Backoff class instance (e.g., ExponentialBackoff). |
retry_on | Callable | Predicate function taking an Exception and returning bool. |
cancel_token | CancelToken | Token to cancel the request mid-flight. |
HTTP Methods
All instances (and the top-level module) support the following synchronous methods:
request(method, url, **kwargs)get(url, **kwargs)post(url, **kwargs)put(url, **kwargs)patch(url, **kwargs)delete(url, **kwargs)head(url, **kwargs)options(url, **kwargs)
And their asynchronous equivalents:
async_request(method, url, **kwargs)async_get(url, **kwargs)async_post(url, **kwargs)async_put(url, **kwargs)async_patch(url, **kwargs)async_delete(url, **kwargs)async_head(url, **kwargs)async_options(url, **kwargs)