axios-python 0.1.0__tar.gz → 0.2.0__tar.gz

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.
Files changed (61) hide show
  1. axios_python-0.2.0/.github/workflows/test.yml +37 -0
  2. {axios_python-0.1.0 → axios_python-0.2.0}/.gitignore +208 -208
  3. {axios_python-0.1.0 → axios_python-0.2.0}/PKG-INFO +53 -3
  4. {axios_python-0.1.0 → axios_python-0.2.0}/README.md +372 -321
  5. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/__init__.py +136 -148
  6. axios_python-0.2.0/axios_python/cancel/__init__.py +4 -0
  7. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/cancel/exceptions.py +12 -9
  8. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/cancel/token.py +77 -74
  9. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/client.py +363 -349
  10. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/config.py +52 -47
  11. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/defaults.py +30 -26
  12. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/exceptions.py +50 -47
  13. axios_python-0.2.0/axios_python/helpers.py +37 -0
  14. axios_python-0.2.0/axios_python/interceptors/__init__.py +4 -0
  15. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/interceptors/chain.py +121 -118
  16. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/interceptors/manager.py +32 -29
  17. axios_python-0.2.0/axios_python/middleware/__init__.py +4 -0
  18. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/middleware/manager.py +57 -54
  19. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/middleware/pipeline.py +71 -68
  20. axios_python-0.2.0/axios_python/plugins/__init__.py +4 -0
  21. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/plugins/auth.py +52 -49
  22. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/plugins/base.py +30 -27
  23. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/plugins/cache.py +78 -75
  24. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/plugins/logger.py +60 -57
  25. axios_python-0.2.0/axios_python/py.typed +0 -0
  26. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/request.py +27 -23
  27. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/response.py +140 -137
  28. axios_python-0.2.0/axios_python/retry/__init__.py +4 -0
  29. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/retry/engine.py +108 -105
  30. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/retry/strategy.py +119 -116
  31. axios_python-0.2.0/axios_python/transport/__init__.py +4 -0
  32. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/transport/base.py +53 -50
  33. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/transport/httpx_adapter.py +111 -131
  34. axios_python-0.2.0/axios_python/utils/__init__.py +4 -0
  35. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/utils/async_utils.py +59 -56
  36. {axios_python-0.1.0 → axios_python-0.2.0}/axios_python/utils/merge.py +36 -33
  37. {axios_python-0.1.0 → axios_python-0.2.0}/pyproject.toml +59 -44
  38. axios_python-0.2.0/tests/__init__.py +3 -0
  39. axios_python-0.2.0/tests/conftest.py +20 -0
  40. axios_python-0.2.0/tests/test_all_spread.py +64 -0
  41. axios_python-0.2.0/tests/test_cancel.py +69 -0
  42. axios_python-0.2.0/tests/test_client.py +90 -0
  43. axios_python-0.2.0/tests/test_interceptors.py +92 -0
  44. axios_python-0.2.0/tests/test_middleware.py +102 -0
  45. axios_python-0.2.0/tests/test_plugins.py +89 -0
  46. axios_python-0.2.0/tests/test_request_methods.py +137 -0
  47. axios_python-0.2.0/tests/test_response.py +122 -0
  48. axios_python-0.2.0/tests/test_retry.py +141 -0
  49. axios_python-0.2.0/tests/test_transforms.py +108 -0
  50. axios_python-0.1.0/axios_python/cancel/__init__.py +0 -1
  51. axios_python-0.1.0/axios_python/interceptors/__init__.py +0 -1
  52. axios_python-0.1.0/axios_python/middleware/__init__.py +0 -1
  53. axios_python-0.1.0/axios_python/plugins/__init__.py +0 -1
  54. axios_python-0.1.0/axios_python/retry/__init__.py +0 -1
  55. axios_python-0.1.0/axios_python/transport/__init__.py +0 -1
  56. axios_python-0.1.0/axios_python/utils/__init__.py +0 -1
  57. axios_python-0.1.0/rename2.py +0 -45
  58. axios_python-0.1.0/test_async.py +0 -12
  59. axios_python-0.1.0/test_stream.py +0 -41
  60. axios_python-0.1.0/test_sync.py +0 -11
  61. axios_python-0.1.0/test_v2.py +0 -50
@@ -0,0 +1,37 @@
1
+ name: Test and Type Check
2
+
3
+ on:
4
+ push:
5
+ branches: [ "main" ]
6
+ pull_request:
7
+ branches: [ "main" ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12"]
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python ${{ matrix.python-version }}
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+ cache: 'pip'
24
+
25
+ - name: Install dependencies
26
+ run: |
27
+ python -m pip install --upgrade pip
28
+ pip install -e ".[dev]"
29
+ pip install mypy
30
+
31
+ - name: Run mypy type checking
32
+ run: |
33
+ mypy axios_python/
34
+
35
+ - name: Run pytest
36
+ run: |
37
+ pytest tests/ -v
@@ -1,209 +1,209 @@
1
- # Byte-compiled / optimized / DLL files
2
- __pycache__/
3
- *.py[codz]
4
- *$py.class
5
-
6
- # C extensions
7
- *.so
8
-
9
- # Distribution / packaging
10
- .Python
11
- build/
12
- develop-eggs/
13
- dist/
14
- downloads/
15
- eggs/
16
- .eggs/
17
- lib/
18
- lib64/
19
- parts/
20
- sdist/
21
- var/
22
- wheels/
23
- share/python-wheels/
24
- *.egg-info/
25
- .installed.cfg
26
- *.egg
27
- MANIFEST
28
-
29
- # PyInstaller
30
- # Usually these files are written by a python script from a template
31
- # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
- *.manifest
33
- *.spec
34
-
35
- # Installer logs
36
- pip-log.txt
37
- pip-delete-this-directory.txt
38
-
39
- # Unit test / coverage reports
40
- htmlcov/
41
- .tox/
42
- .nox/
43
- .coverage
44
- .coverage.*
45
- .cache
46
- nosetests.xml
47
- coverage.xml
48
- *.cover
49
- *.py.cover
50
- .hypothesis/
51
- .pytest_cache/
52
- cover/
53
-
54
- # Translations
55
- *.mo
56
- *.pot
57
-
58
- # Django stuff:
59
- *.log
60
- local_settings.py
61
- db.sqlite3
62
- db.sqlite3-journal
63
-
64
- # Flask stuff:
65
- instance/
66
- .webassets-cache
67
-
68
- # Scrapy stuff:
69
- .scrapy
70
-
71
- # Sphinx documentation
72
- docs/_build/
73
-
74
- # PyBuilder
75
- .pybuilder/
76
- target/
77
-
78
- # Jupyter Notebook
79
- .ipynb_checkpoints
80
-
81
- # IPython
82
- profile_default/
83
- ipython_config.py
84
-
85
- # pyenv
86
- # For a library or package, you might want to ignore these files since the code is
87
- # intended to run in multiple environments; otherwise, check them in:
88
- # .python-version
89
-
90
- # pipenv
91
- # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
- # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
- # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
- # install all needed dependencies.
95
- #Pipfile.lock
96
-
97
- # UV
98
- # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
- # This is especially recommended for binary packages to ensure reproducibility, and is more
100
- # commonly ignored for libraries.
101
- #uv.lock
102
-
103
- # poetry
104
- # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
- # This is especially recommended for binary packages to ensure reproducibility, and is more
106
- # commonly ignored for libraries.
107
- # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
- #poetry.lock
109
- #poetry.toml
110
-
111
- # pdm
112
- # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
- # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
- # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
- #pdm.lock
116
- #pdm.toml
117
- .pdm-python
118
- .pdm-build/
119
-
120
- # pixi
121
- # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
- #pixi.lock
123
- # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
- # in the .venv directory. It is recommended not to include this directory in version control.
125
- .pixi
126
-
127
- # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
- __pypackages__/
129
-
130
- # Celery stuff
131
- celerybeat-schedule
132
- celerybeat.pid
133
-
134
- # SageMath parsed files
135
- *.sage.py
136
-
137
- # Environments
138
- .env
139
- .envrc
140
- .venv
141
- env/
142
- venv/
143
- ENV/
144
- env.bak/
145
- venv.bak/
146
-
147
- # Spyder project settings
148
- .spyderproject
149
- .spyproject
150
-
151
- # Rope project settings
152
- .ropeproject
153
-
154
- # mkdocs documentation
155
- /site
156
-
157
- # mypy
158
- .mypy_cache/
159
- .dmypy.json
160
- dmypy.json
161
-
162
- # Pyre type checker
163
- .pyre/
164
-
165
- # pytype static type analyzer
166
- .pytype/
167
-
168
- # Cython debug symbols
169
- cython_debug/
170
-
171
- # PyCharm
172
- # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
- # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
- # and can be added to the global gitignore or merged into this file. For a more nuclear
175
- # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
- #.idea/
177
-
178
- # Abstra
179
- # Abstra is an AI-powered process automation framework.
180
- # Ignore directories containing user credentials, local state, and settings.
181
- # Learn more at https://abstra.io/docs
182
- .abstra/
183
-
184
- # Visual Studio Code
185
- # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
- # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
- # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
- # you could uncomment the following to ignore the entire vscode folder
189
- # .vscode/
190
-
191
- # Ruff stuff:
192
- .ruff_cache/
193
-
194
- # PyPI configuration file
195
- .pypirc
196
-
197
- # Cursor
198
- # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
- # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
- # refer to https://docs.cursor.com/context/ignore-files
201
- .cursorignore
202
- .cursorindexingignore
203
-
204
- # Marimo
205
- marimo/_static/
206
- marimo/_lsp/
207
- __marimo__/
208
-
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
208
+
209
209
  pre-commit-venv/
@@ -1,11 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: axios-python
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: A developer-experience-first HTTP client for Python, inspired by Axios.
5
5
  Project-URL: Homepage, https://github.com/ashavijit/axios_python
6
6
  Project-URL: Repository, https://github.com/ashavijit/axios_python
7
7
  Author: Avijit
8
- License-Expression: MIT
9
8
  Keywords: async,axios,client,http,interceptors,middleware,retry
10
9
  Classifier: Development Status :: 3 - Alpha
11
10
  Classifier: Intended Audience :: Developers
@@ -112,6 +111,33 @@ async def fetch_data():
112
111
  asyncio.run(fetch_data())
113
112
  ```
114
113
 
114
+ ### Concurrent Requests
115
+
116
+ Run multiple requests simultaneously using `all()` and unpack the results cleanly with the `spread()` callback wrapper, just like in JavaScript Axios.
117
+
118
+ ```python
119
+ import asyncio
120
+ from axios_python import create, all, spread
121
+
122
+ api = create({"base_url": "https://api.github.com"})
123
+
124
+ async def fetch_multiple():
125
+ # Fetch user profile and repos concurrently
126
+ results = await all([
127
+ api.async_get("/users/octocat"),
128
+ api.async_get("/users/octocat/repos")
129
+ ])
130
+
131
+ @spread
132
+ def process(profile, repos):
133
+ print(f"User: {profile.json()['name']}")
134
+ print(f"Repos: {len(repos.json())}")
135
+
136
+ process(results)
137
+
138
+ asyncio.run(fetch_multiple())
139
+ ```
140
+
115
141
  ### File Uploads
116
142
 
117
143
  Multipart file uploads are supported out of the box matching the `requests` interface.
@@ -168,6 +194,27 @@ def unwrap_data(response):
168
194
  api.interceptors.response.use(unwrap_data)
169
195
  ```
170
196
 
197
+ ### Data Transformation
198
+
199
+ In addition to interceptors, you can use `transform_request` and `transform_response` to modify the payload directly before sending or after receiving.
200
+
201
+ ```python
202
+ import json
203
+
204
+ def stringify_json(data, headers):
205
+ if isinstance(data, dict):
206
+ headers['Content-Type'] = 'application/json'
207
+ return json.dumps(data)
208
+ return data
209
+
210
+ api = axios_python.create({
211
+ "transform_request": [stringify_json]
212
+ })
213
+
214
+ # Dictionary sent will automatically be stringified using our transform
215
+ api.post("/submit", data={"key": "value"})
216
+ ```
217
+
171
218
  ### Middleware
172
219
 
173
220
  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.
@@ -280,7 +327,7 @@ You can pass the following properties to `axios_python.create(config)` or as ove
280
327
  | Property | Type | Description |
281
328
  |----------|------|-------------|
282
329
  | `base_url` | `str` | Base URL attached to relative paths. |
283
- | `method` | `str` | HTTP Method (e.g., `"GET"`, `"POST"`). |
330
+ | `method` | `str` | HTTP Method (e.g., `"GET"`, `"POST"`, `"HEAD"`, `"OPTIONS"`). |
284
331
  | `url` | `str` | The target path or absolute URL. |
285
332
  | `headers` | `dict` | Dictionary of HTTP headers. |
286
333
  | `params` | `dict` | URL Query parameters. |
@@ -289,6 +336,9 @@ You can pass the following properties to `axios_python.create(config)` or as ove
289
336
  | `files` | `Any` | Multipart-encoded files dictionary. |
290
337
  | `stream` | `bool` | Stream the response (Default: False). |
291
338
  | `timeout` | `float` | Max seconds to wait for a response (Default: 30). |
339
+ | `follow_redirects` | `bool` | Whether to automatically follow HTTP redirects (Default: True). |
340
+ | `transform_request` | `list[Callable]`| Functions to manipulate data/headers before sending. |
341
+ | `transform_response` | `list[Callable]`| Functions to manipulate response data before returning. |
292
342
  | `max_retries` | `int` | Maximum retry attempts on failure (Default: 0). |
293
343
  | `retry_strategy` | `RetryStrategy` | Backoff class instance (e.g., `ExponentialBackoff`). |
294
344
  | `cancel_token` | `CancelToken` | Token to cancel the request mid-flight. |