axios-python 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,348 @@
1
+ Metadata-Version: 2.4
2
+ Name: axios-python
3
+ Version: 0.1.0
4
+ Summary: A developer-experience-first HTTP client for Python, inspired by Axios.
5
+ Project-URL: Homepage, https://github.com/ashavijit/axios_python
6
+ Project-URL: Repository, https://github.com/ashavijit/axios_python
7
+ Author: Avijit
8
+ License-Expression: MIT
9
+ Keywords: async,axios,client,http,interceptors,middleware,retry
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Internet :: WWW/HTTP
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: httpx>=0.27.0
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
24
+ Requires-Dist: pytest>=8.0; extra == 'dev'
25
+ Requires-Dist: respx>=0.21; extra == 'dev'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # axios_python
29
+
30
+ [![PyPI version](https://img.shields.io/pypi/v/axios_python.svg)](https://pypi.org/project/axios_python/)
31
+ [![Python versions](https://img.shields.io/pypi/pyversions/axios_python.svg)](https://pypi.org/project/axios_python/)
32
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
33
+
34
+ A developer-experience-first HTTP client for Python, heavily inspired by [Axios](https://axios-http.com/).
35
+
36
+ The Python ecosystem has amazing HTTP transport libraries (`requests`, `httpx`, `aiohttp`), but they are often focused purely on sending requests and getting responses. Modern applications need a **network orchestration layer**β€”features like request lifecycle hooks, middleware, interceptors, isolated client instances, request cancellation, and unified synchronous/asynchronous developer experience.
37
+
38
+ `axios_python` brings the elegant, feature-rich Axios model to Python, built natively on top of `httpx`.
39
+
40
+ ---
41
+
42
+ ## Features
43
+
44
+ - 🌐 **Instance-based Client:** Completely isolated state for different APIs.
45
+ - πŸ”„ **Unified API:** Identical interface for both Sync (`api.get()`) and Async (`await api.async_get()`).
46
+ - πŸ”— **Interceptors:** Hook into requests before they are sent, or responses before they are returned.
47
+ - 🚰 **Middleware Pipeline:** Express.js-style async middleware for complex request wrapping.
48
+ - πŸ” **Retry Engine:** Built-in strategies for linear, fixed, and exponential backoff.
49
+ - 🚫 **Cancellation Tokens:** Cleanly abort requests gracefully.
50
+ - πŸ”Œ **Plugin System:** Easily extend clients with Cache, Auth, and Logging plugins (included out-of-the-box).
51
+ - 🧩 **Swappable Transport:** Backed by `httpx` by default, but completely abstracted for custom transports.
52
+ - πŸ“ **Fully Typed:** 100% strict typing support for modern Python 3.10+.
53
+
54
+ ---
55
+
56
+ ## Installation
57
+
58
+ Install using `pip`:
59
+
60
+ ```bash
61
+ pip install axios_python
62
+ ```
63
+
64
+ Requires Python 3.10+.
65
+
66
+ ---
67
+
68
+ ## Quick Start
69
+
70
+ ### Basic Synchronous Usage
71
+
72
+ ```python
73
+ import axios_python
74
+
75
+ # Zero-setup module level request
76
+ response = axios_python.get("https://httpbin.org/get", params={"query": "python"})
77
+
78
+ # Or create an isolated instance with default configuration
79
+ api = axios_python.create({
80
+ "base_url": "https://httpbin.org",
81
+ "timeout": 10,
82
+ "headers": {
83
+ "X-App-Client": "MyCLI/1.0"
84
+ }
85
+ })
86
+
87
+ # Make a request using the instance
88
+ response = api.get("/get", params={"query": "python"})
89
+
90
+ print(f"Status: {response.status_code}")
91
+ if response.ok:
92
+ print(response.json())
93
+ ```
94
+
95
+ ### Asynchronous Native
96
+
97
+ `axios_python` treats async as a first-class citizen. Just prefix method names with `async_`.
98
+
99
+ ```python
100
+ import asyncio
101
+ import axios_python
102
+
103
+ async def fetch_data():
104
+ # Non-blocking async call via instance
105
+ api = axios_python.create({"base_url": "https://httpbin.org"})
106
+ response = await api.async_get("/delay/2")
107
+
108
+ # Or module level
109
+ response = await axios_python.async_get("https://httpbin.org/delay/2")
110
+ print(response.data)
111
+
112
+ asyncio.run(fetch_data())
113
+ ```
114
+
115
+ ### File Uploads
116
+
117
+ Multipart file uploads are supported out of the box matching the `requests` interface.
118
+
119
+ ```python
120
+ with open("report.csv", "rb") as f:
121
+ # Files can be passed as an open file handle or a tuple mapping
122
+ files = {"file": ("report.csv", f, "text/csv")}
123
+ response = axios_python.post("https://httpbin.org/post", files=files)
124
+ ```
125
+
126
+ ### Streaming Responses
127
+
128
+ For large files or continuous data streams, use `stream=True`. The response is exposed as a context manager for both sync and async calls.
129
+
130
+ ```python
131
+ import axios_python
132
+
133
+ # Synchronous execution
134
+ with axios_python.get("https://httpbin.org/stream-bytes/100", stream=True) as response:
135
+ for chunk in response.iter_bytes(chunk_size=10):
136
+ print(len(chunk))
137
+
138
+ # Asynchronous execution in an async function
139
+ async with await axios_python.async_get("https://.../stream", stream=True) as response:
140
+ async for line in response.aiter_lines():
141
+ print(line)
142
+ ```
143
+
144
+ ---
145
+
146
+ ## Core Concepts
147
+
148
+ ### Interceptors
149
+
150
+ Interceptors allow you to tap into the lifecycle of a request or response. They run sequentially.
151
+
152
+ ```python
153
+ api = axios_python.create({"base_url": "https://api.myapp.com"})
154
+
155
+ # Add a request interceptor
156
+ def authorize_request(config):
157
+ config["headers"]["Authorization"] = "Bearer token123"
158
+ return config
159
+
160
+ api.interceptors.request.use(authorize_request)
161
+
162
+ # Add a response interceptor
163
+ def unwrap_data(response):
164
+ # Automatically unwrap the 'data' payload from the JSON
165
+ response.data = response.json().get("data", response.data)
166
+ return response
167
+
168
+ api.interceptors.response.use(unwrap_data)
169
+ ```
170
+
171
+ ### Middleware
172
+
173
+ For more complex logic that needs to "wrap" the entire request (like timing, distributed tracing, or custom caching), use the Express.js-style middleware pipeline.
174
+
175
+ ```python
176
+ import time
177
+
178
+ async def logger_middleware(ctx, next_fn):
179
+ print(f"Starting {ctx.get('method')} to {ctx.get('url')}")
180
+ start = time.monotonic()
181
+
182
+ # Yield control to the next middleware / transport layer
183
+ result = await next_fn(ctx)
184
+
185
+ elapsed = time.monotonic() - start
186
+ print(f"Finished in {elapsed:.3f}s with status {result.status_code}")
187
+
188
+ return result
189
+
190
+ api.use(logger_middleware)
191
+ ```
192
+
193
+ ### Retry Engine
194
+
195
+ Temporary network issues shouldn't hard-crash your app. Provide a retry strategy when creating your client.
196
+
197
+ ```python
198
+ from axios_python import ExponentialBackoff
199
+
200
+ api = axios_python.create({
201
+ "base_url": "https://httpbin.org",
202
+ "max_retries": 3,
203
+ "retry_strategy": ExponentialBackoff(base=1.0, multiplier=2.0, max_delay=10.0),
204
+ })
205
+ ```
206
+
207
+ By default, this retries on Network Errors and Timeouts.
208
+
209
+ ### Request Cancellation
210
+
211
+ Use a `CancelToken` to abort long-running requests or cancel requests when a user navigates away.
212
+
213
+ ```python
214
+ from axios_python import CancelToken
215
+ import threading
216
+ import time
217
+
218
+ token = CancelToken()
219
+
220
+ def background_fetch():
221
+ try:
222
+ api.get("/delay/10", cancel_token=token)
223
+ except axios_python.CancelError as e:
224
+ print(f"Request aborted: {e}")
225
+
226
+ threading.Thread(target=background_fetch).start()
227
+
228
+ time.sleep(1)
229
+ token.cancel(reason="User clicked 'Stop'")
230
+ ```
231
+
232
+ ---
233
+
234
+ ## Plugins
235
+
236
+ `axios_python` ships with first-party plugins for common use-cases.
237
+
238
+ ### Authentication Plugin
239
+
240
+ Automatically injects `Authorization` headers. Supports static tokens or dynamic providers.
241
+
242
+ ```python
243
+ from axios_python import AuthPlugin
244
+
245
+ api.plugin(AuthPlugin(scheme="Bearer", token="super-secret-key"))
246
+
247
+ # Or dynamically fetch it:
248
+ # api.plugin(AuthPlugin(token_provider=lambda: get_fresh_token()))
249
+ ```
250
+
251
+ ### Cache Plugin
252
+
253
+ In-memory TTL cache for `GET` requests to reduce redundant network load.
254
+
255
+ ```python
256
+ from axios_python import CachePlugin
257
+
258
+ # Cache GET responses for 120 seconds, max 256 items
259
+ api.plugin(CachePlugin(ttl=120, max_size=256))
260
+ ```
261
+
262
+ ### Logger Plugin
263
+
264
+ Standardized `logging` for requests and responses out of the box.
265
+
266
+ ```python
267
+ import logging
268
+ from axios_python import LoggerPlugin
269
+
270
+ logging.basicConfig(level=logging.INFO)
271
+ api.plugin(LoggerPlugin(level=logging.INFO))
272
+ ```
273
+
274
+ ---
275
+
276
+ ## Configuration Reference
277
+
278
+ You can pass the following properties to `axios_python.create(config)` or as overrides to individual request methods (`api.get("/url", **kwargs)`):
279
+
280
+ | Property | Type | Description |
281
+ |----------|------|-------------|
282
+ | `base_url` | `str` | Base URL attached to relative paths. |
283
+ | `method` | `str` | HTTP Method (e.g., `"GET"`, `"POST"`). |
284
+ | `url` | `str` | The target path or absolute URL. |
285
+ | `headers` | `dict` | Dictionary of HTTP headers. |
286
+ | `params` | `dict` | URL Query parameters. |
287
+ | `data` | `Any` | Request body content (raw). |
288
+ | `json` | `Any` | Request body content (automatically serialized to JSON). |
289
+ | `files` | `Any` | Multipart-encoded files dictionary. |
290
+ | `stream` | `bool` | Stream the response (Default: False). |
291
+ | `timeout` | `float` | Max seconds to wait for a response (Default: 30). |
292
+ | `max_retries` | `int` | Maximum retry attempts on failure (Default: 0). |
293
+ | `retry_strategy` | `RetryStrategy` | Backoff class instance (e.g., `ExponentialBackoff`). |
294
+ | `cancel_token` | `CancelToken` | Token to cancel the request mid-flight. |
295
+
296
+ ---
297
+
298
+ ## Error Handling
299
+
300
+ `axios_python` provides strongly typed exceptions extending from `AxiosPythonError`. The `Response` object provides a `.raise_for_status()` method exactly like `requests`.
301
+
302
+ ```python
303
+ import axios_python
304
+
305
+ try:
306
+ response = axios_python.get("https://httpbin.org/status/404")
307
+ response.raise_for_status()
308
+ except axios_python.HTTPStatusError as e:
309
+ print(f"Request failed with status code {e.response.status_code}")
310
+ except axios_python.TimeoutError:
311
+ print("Request timed out.")
312
+ except axios_python.NetworkError:
313
+ print("Unable to connect to the server.")
314
+ except axios_python.RetryError:
315
+ print("All retry attempts failed.")
316
+ except axios_python.CancelError:
317
+ print("Request was manually cancelled.")
318
+ except axios_python.AxiosPythonError as e:
319
+ print(f"A general axios_python error occurred: {e}")
320
+ ```
321
+
322
+ ---
323
+
324
+ ## Advanced
325
+
326
+ ### Custom Transports
327
+
328
+ You aren't locked into `httpx`. You can build a custom transport adapter by implementing the `BaseTransport` abstract class.
329
+
330
+ ```python
331
+ from axios_python import AxiosPython, BaseTransport
332
+
333
+ class MockTransport(BaseTransport):
334
+ def send(self, request):
335
+ return axios_python.Response(200, {}, {"mock": "data"}, request)
336
+
337
+ async def send_async(self, request):
338
+ return self.send(request)
339
+
340
+ # Pass the custom transport directly to the AxiosPython constructor
341
+ api = AxiosPython(config={"base_url": "mock://"}, transport=MockTransport())
342
+ ```
343
+
344
+ ---
345
+
346
+ ## License
347
+
348
+ This project is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,33 @@
1
+ axios_python/__init__.py,sha256=vNKDAB0tFJgktaT1Wq75wjEtbZKzIUatggy2iGp3DyU,4131
2
+ axios_python/client.py,sha256=He-uSXGUCPqiBfFBs1IgpSXfArm2mvFEeaN57U8psxE,11854
3
+ axios_python/config.py,sha256=iJD4GxMpqDvd-k1xpXm-abD4zqJ6MBSvKJLDdsA-g3I,1092
4
+ axios_python/defaults.py,sha256=oZKgcazdKYVeoOltRtEAOXyWmtvCSRmtcO9jyPHz88g,510
5
+ axios_python/exceptions.py,sha256=nmWsmGEdJfqwSW64G6TVqnUezdHzcf_RU_3OOAN2t1c,1205
6
+ axios_python/request.py,sha256=HnPVCb9ISjbn6bjck9LByzw_Y1oJL7Wtxwxu51S1klI,504
7
+ axios_python/response.py,sha256=3ZiFFLAQ2dYewRNLY99KpuUQutG4LBHbLzB2TtwNv4Y,4368
8
+ axios_python/cancel/__init__.py,sha256=juqd9PbXs4yg45zMJ7BHAOPQjb7sgEbWE9InBtGZhfo,24
9
+ axios_python/cancel/exceptions.py,sha256=JIwSPnDa7CuhJHfsGqITxdt480YGK2FRDRPrTqkM7Yg,151
10
+ axios_python/cancel/token.py,sha256=zoACDP71SnurS16HePmvIWsDBnGtDL6DyYNcFywJi88,1987
11
+ axios_python/interceptors/__init__.py,sha256=juqd9PbXs4yg45zMJ7BHAOPQjb7sgEbWE9InBtGZhfo,24
12
+ axios_python/interceptors/chain.py,sha256=7K6swlohrYLatO8IEAlLnEnn2Q5xCDl-yMPrFiuvKqo,3569
13
+ axios_python/interceptors/manager.py,sha256=q3Lr9qlZ4QQIdR7QOK8RP362q_db6-UNX9NVNMaPdbM,711
14
+ axios_python/middleware/__init__.py,sha256=juqd9PbXs4yg45zMJ7BHAOPQjb7sgEbWE9InBtGZhfo,24
15
+ axios_python/middleware/manager.py,sha256=7KfQmK4ss7LysM4ZzdJQytPxUntBZA7qjIdPFonJTj0,1424
16
+ axios_python/middleware/pipeline.py,sha256=ddORT7Vov1UtyWgDSLgnh6wydG8uk0tCcMsU9sIrdIU,2021
17
+ axios_python/plugins/__init__.py,sha256=juqd9PbXs4yg45zMJ7BHAOPQjb7sgEbWE9InBtGZhfo,24
18
+ axios_python/plugins/auth.py,sha256=6sG6lwLt-U6vi_692WVfyc_8ZCMll5Z3RrwZk71qle0,1500
19
+ axios_python/plugins/base.py,sha256=unQ00LrOznBQWpJpPDexJsanwsYlJwq-AKK7ns_2TdY,644
20
+ axios_python/plugins/cache.py,sha256=27951PylkWTooXduX0GzpvbJ5Fl9auPLVt-79JkZXG8,2071
21
+ axios_python/plugins/logger.py,sha256=LHldOoImqGl54OUciTDRRzzwJMKpqXmwtYeQqTx1HhU,1510
22
+ axios_python/retry/__init__.py,sha256=juqd9PbXs4yg45zMJ7BHAOPQjb7sgEbWE9InBtGZhfo,24
23
+ axios_python/retry/engine.py,sha256=2LusOjThAXc7TpZJxO-ZVFKZvmVPlroHOyJ5lF2rpBA,3113
24
+ axios_python/retry/strategy.py,sha256=h46d0gunRrYpxYOVWmP3o91PW4K_ufU65MmrlbVvyqk,2873
25
+ axios_python/transport/__init__.py,sha256=juqd9PbXs4yg45zMJ7BHAOPQjb7sgEbWE9InBtGZhfo,24
26
+ axios_python/transport/base.py,sha256=EZcVGLoy0McUOFB0UaA28rbS7sWoWA2q6wTzW8N4B_s,1236
27
+ axios_python/transport/httpx_adapter.py,sha256=1Y3Ho4OhNrEk7dZ4eTROk4dGnnnI0aWXRP6n4fpdJL0,4379
28
+ axios_python/utils/__init__.py,sha256=juqd9PbXs4yg45zMJ7BHAOPQjb7sgEbWE9InBtGZhfo,24
29
+ axios_python/utils/async_utils.py,sha256=qCE3UethFsKRoMH2igu_Z4sBnjjBettqYK18fFLHz_c,1402
30
+ axios_python/utils/merge.py,sha256=_sZpshxY4KUbmmUwAUyl4OuCInevCeFEy11c58QAUbo,847
31
+ axios_python-0.1.0.dist-info/METADATA,sha256=qkzQpp47wDzZ9_tcUxLBtWSdabcz7SHCAa8gkS8rtT4,10766
32
+ axios_python-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
33
+ axios_python-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any