axios_python logo
axios_python

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)):

PropertyTypeDescription
base_urlstrBase URL attached to relative paths.
methodstrHTTP Method (e.g., "GET", "POST", "HEAD", "OPTIONS").
urlstrThe target path or absolute URL.
headersdictDictionary of HTTP headers.
paramsdictURL Query parameters.
dataAnyRequest body content (raw).
jsonAnyRequest body content (automatically serialized to JSON).
filesAnyMultipart-encoded files dictionary.
streamboolStream the response (Default: False).
timeoutfloatMax seconds to wait for a response (Default: 30).
follow_redirectsboolWhether to automatically follow HTTP redirects (Default: True).
transform_requestlist[Callable]Functions to manipulate data/headers before sending.
transform_responselist[Callable]Functions to manipulate response data before returning.
max_retriesintMaximum retry attempts on failure (Default: 0).
retry_strategyRetryStrategyBackoff class instance (e.g., ExponentialBackoff).
retry_onCallablePredicate function taking an Exception and returning bool.
cancel_tokenCancelTokenToken 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)

On this page