httpx-tenacity 0.1.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.
- httpx_tenacity-0.1.0/.gitignore +244 -0
- httpx_tenacity-0.1.0/LICENSE +176 -0
- httpx_tenacity-0.1.0/PKG-INFO +56 -0
- httpx_tenacity-0.1.0/README.md +23 -0
- httpx_tenacity-0.1.0/pyproject.toml +234 -0
- httpx_tenacity-0.1.0/src/httpx_tenacity/__init__.py +20 -0
- httpx_tenacity-0.1.0/src/httpx_tenacity/_version.py +34 -0
- httpx_tenacity-0.1.0/src/httpx_tenacity/async_tenacious_transport.py +127 -0
- httpx_tenacity-0.1.0/src/httpx_tenacity/py.typed +2 -0
- httpx_tenacity-0.1.0/src/httpx_tenacity/retry_callback.py +39 -0
- httpx_tenacity-0.1.0/src/httpx_tenacity/tenacious_transport.py +127 -0
- httpx_tenacity-0.1.0/src/httpx_tenacity/types.py +53 -0
- httpx_tenacity-0.1.0/src/httpx_tenacity/wait.py +47 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
### Linux template
|
|
2
|
+
*~
|
|
3
|
+
|
|
4
|
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
|
5
|
+
.fuse_hidden*
|
|
6
|
+
|
|
7
|
+
# KDE directory preferences
|
|
8
|
+
.directory
|
|
9
|
+
|
|
10
|
+
# Linux trash folder which might appear on any partition or disk
|
|
11
|
+
.Trash-*
|
|
12
|
+
|
|
13
|
+
# .nfs files are created when an open file is removed but is still being accessed
|
|
14
|
+
.nfs*
|
|
15
|
+
|
|
16
|
+
### Windows template
|
|
17
|
+
# Windows thumbnail cache files
|
|
18
|
+
Thumbs.db
|
|
19
|
+
Thumbs.db:encryptable
|
|
20
|
+
ehthumbs.db
|
|
21
|
+
ehthumbs_vista.db
|
|
22
|
+
|
|
23
|
+
# Dump file
|
|
24
|
+
*.stackdump
|
|
25
|
+
|
|
26
|
+
# Folder config file
|
|
27
|
+
[Dd]esktop.ini
|
|
28
|
+
|
|
29
|
+
# Recycle Bin used on file shares
|
|
30
|
+
$RECYCLE.BIN/
|
|
31
|
+
|
|
32
|
+
# Windows Installer files
|
|
33
|
+
*.cab
|
|
34
|
+
*.msi
|
|
35
|
+
*.msix
|
|
36
|
+
*.msm
|
|
37
|
+
*.msp
|
|
38
|
+
|
|
39
|
+
# Windows shortcuts
|
|
40
|
+
*.lnk
|
|
41
|
+
|
|
42
|
+
### JupyterNotebooks template
|
|
43
|
+
# gitignore template for Jupyter Notebooks
|
|
44
|
+
# website: http://jupyter.org/
|
|
45
|
+
|
|
46
|
+
.ipynb_checkpoints
|
|
47
|
+
*/.ipynb_checkpoints/*
|
|
48
|
+
|
|
49
|
+
# IPython
|
|
50
|
+
profile_default/
|
|
51
|
+
ipython_config.py
|
|
52
|
+
|
|
53
|
+
# Remove previous ipynb_checkpoints
|
|
54
|
+
# git rm -r .ipynb_checkpoints/
|
|
55
|
+
|
|
56
|
+
### macOS template
|
|
57
|
+
# General
|
|
58
|
+
.DS_Store
|
|
59
|
+
.AppleDouble
|
|
60
|
+
.LSOverride
|
|
61
|
+
|
|
62
|
+
# Icon must end with two \r
|
|
63
|
+
Icon
|
|
64
|
+
|
|
65
|
+
# Thumbnails
|
|
66
|
+
._*
|
|
67
|
+
|
|
68
|
+
# Files that might appear in the root of a volume
|
|
69
|
+
.DocumentRevisions-V100
|
|
70
|
+
.fseventsd
|
|
71
|
+
.Spotlight-V100
|
|
72
|
+
.TemporaryItems
|
|
73
|
+
.Trashes
|
|
74
|
+
.VolumeIcon.icns
|
|
75
|
+
.com.apple.timemachine.donotpresent
|
|
76
|
+
|
|
77
|
+
# Directories potentially created on remote AFP share
|
|
78
|
+
.AppleDB
|
|
79
|
+
.AppleDesktop
|
|
80
|
+
Network Trash Folder
|
|
81
|
+
Temporary Items
|
|
82
|
+
.apdisk
|
|
83
|
+
|
|
84
|
+
### Python template
|
|
85
|
+
# Byte-compiled / optimized / DLL files
|
|
86
|
+
__pycache__/
|
|
87
|
+
*.py[cod]
|
|
88
|
+
*$py.class
|
|
89
|
+
|
|
90
|
+
# C extensions
|
|
91
|
+
*.so
|
|
92
|
+
|
|
93
|
+
# Distribution / packaging
|
|
94
|
+
.Python
|
|
95
|
+
build/
|
|
96
|
+
develop-eggs/
|
|
97
|
+
dist/
|
|
98
|
+
downloads/
|
|
99
|
+
eggs/
|
|
100
|
+
.eggs/
|
|
101
|
+
lib/
|
|
102
|
+
lib64/
|
|
103
|
+
parts/
|
|
104
|
+
sdist/
|
|
105
|
+
var/
|
|
106
|
+
wheels/
|
|
107
|
+
share/python-wheels/
|
|
108
|
+
*.egg-info/
|
|
109
|
+
.installed.cfg
|
|
110
|
+
*.egg
|
|
111
|
+
MANIFEST
|
|
112
|
+
|
|
113
|
+
# PyInstaller
|
|
114
|
+
# Usually these files are written by a python script from a template
|
|
115
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
116
|
+
*.manifest
|
|
117
|
+
*.spec
|
|
118
|
+
|
|
119
|
+
# Installer logs
|
|
120
|
+
pip-log.txt
|
|
121
|
+
pip-delete-this-directory.txt
|
|
122
|
+
|
|
123
|
+
# Unit test / coverage reports
|
|
124
|
+
htmlcov/
|
|
125
|
+
.tox/
|
|
126
|
+
.nox/
|
|
127
|
+
.coverage
|
|
128
|
+
.coverage.*
|
|
129
|
+
.cache
|
|
130
|
+
nosetests.xml
|
|
131
|
+
coverage.xml
|
|
132
|
+
*.cover
|
|
133
|
+
*.py,cover
|
|
134
|
+
.hypothesis/
|
|
135
|
+
.pytest_cache/
|
|
136
|
+
cover/
|
|
137
|
+
|
|
138
|
+
# Translations
|
|
139
|
+
*.mo
|
|
140
|
+
*.pot
|
|
141
|
+
|
|
142
|
+
# Django stuff:
|
|
143
|
+
*.log
|
|
144
|
+
local_settings.py
|
|
145
|
+
db.sqlite3
|
|
146
|
+
db.sqlite3-journal
|
|
147
|
+
|
|
148
|
+
# Flask stuff:
|
|
149
|
+
instance/
|
|
150
|
+
.webassets-cache
|
|
151
|
+
|
|
152
|
+
# Scrapy stuff:
|
|
153
|
+
.scrapy
|
|
154
|
+
|
|
155
|
+
# Sphinx documentation
|
|
156
|
+
docs/_build/
|
|
157
|
+
|
|
158
|
+
# PyBuilder
|
|
159
|
+
.pybuilder/
|
|
160
|
+
target/
|
|
161
|
+
|
|
162
|
+
# Jupyter Notebook
|
|
163
|
+
|
|
164
|
+
# IPython
|
|
165
|
+
|
|
166
|
+
# pyenv
|
|
167
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
168
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
169
|
+
# .python-version
|
|
170
|
+
|
|
171
|
+
# pipenv
|
|
172
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
173
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
174
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
175
|
+
# install all needed dependencies.
|
|
176
|
+
#Pipfile.lock
|
|
177
|
+
|
|
178
|
+
# poetry
|
|
179
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
180
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
181
|
+
# commonly ignored for libraries.
|
|
182
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
183
|
+
#poetry.lock
|
|
184
|
+
|
|
185
|
+
# pdm
|
|
186
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
187
|
+
#pdm.lock
|
|
188
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
189
|
+
# in version control.
|
|
190
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
191
|
+
.pdm.toml
|
|
192
|
+
|
|
193
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
194
|
+
__pypackages__/
|
|
195
|
+
|
|
196
|
+
# Celery stuff
|
|
197
|
+
celerybeat-schedule
|
|
198
|
+
celerybeat.pid
|
|
199
|
+
|
|
200
|
+
# SageMath parsed files
|
|
201
|
+
*.sage.py
|
|
202
|
+
|
|
203
|
+
# Environments
|
|
204
|
+
.env
|
|
205
|
+
.venv
|
|
206
|
+
env/
|
|
207
|
+
venv/
|
|
208
|
+
ENV/
|
|
209
|
+
env.bak/
|
|
210
|
+
venv.bak/
|
|
211
|
+
|
|
212
|
+
# Spyder project settings
|
|
213
|
+
.spyderproject
|
|
214
|
+
.spyproject
|
|
215
|
+
|
|
216
|
+
# Rope project settings
|
|
217
|
+
.ropeproject
|
|
218
|
+
|
|
219
|
+
# mkdocs documentation
|
|
220
|
+
/site
|
|
221
|
+
|
|
222
|
+
# mypy
|
|
223
|
+
.mypy_cache/
|
|
224
|
+
.dmypy.json
|
|
225
|
+
dmypy.json
|
|
226
|
+
|
|
227
|
+
# Pyre type checker
|
|
228
|
+
.pyre/
|
|
229
|
+
|
|
230
|
+
# pytype static type analyzer
|
|
231
|
+
.pytype/
|
|
232
|
+
|
|
233
|
+
# Cython debug symbols
|
|
234
|
+
cython_debug/
|
|
235
|
+
|
|
236
|
+
# PyCharm
|
|
237
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
238
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
239
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
240
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
241
|
+
#.idea/
|
|
242
|
+
|
|
243
|
+
# Hatch-VCS
|
|
244
|
+
_version.py
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
https://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: httpx-tenacity
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight package that provides tenacious (retrying) httpx transports.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Midnighter/httpx-tenacity
|
|
6
|
+
Project-URL: Documentation, https://midnighter.github.io/httpx-tenacity/
|
|
7
|
+
Project-URL: Source Code, https://github.com/Midnighter/httpx-tenacity
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/Midnighter/httpx-tenacity/issues
|
|
9
|
+
Project-URL: Download, https://pypi.org/project/httpx-tenacity/#files
|
|
10
|
+
Author-email: "Moritz E. Beber" <midnighter@posteo.net>
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: httpx,retry,tenacity
|
|
14
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
15
|
+
Classifier: Environment :: Web Environment
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
+
Classifier: Natural Language :: English
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
26
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Requires-Dist: httpx~=0.25
|
|
30
|
+
Requires-Dist: tenacity~=9.1
|
|
31
|
+
Requires-Dist: typing-extensions~=4.6; python_version < '3.11'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# HTTPX Tenacity
|
|
35
|
+
|
|
36
|
+
| | |
|
|
37
|
+
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
38
|
+
| Package | [](https://pypi.org/project/httpx-tenacity/) [](https://pypi.org/project/httpx-tenacity/) |
|
|
39
|
+
| Meta | [](LICENSE) [](.github/CODE_OF_CONDUCT.md) [](https://mypy-lang.org/) [](https://github.com/ambv/black) [](https://github.com/astral-sh/ruff) |
|
|
40
|
+
| Automation | [](https://github.com/Midnighter/httpx-tenacity/actions/workflows/main.yml) |
|
|
41
|
+
|
|
42
|
+
_A lightweight package that provides tenacious (retrying) httpx transports._
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
The package is published on [PyPI](https://pypi.org/project/httpx-tenacity/). Install it,
|
|
47
|
+
for example, with pip.
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
pip install httpx-tenacity
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Copyright
|
|
54
|
+
|
|
55
|
+
- Copyright © 2026 Moritz E. Beber.
|
|
56
|
+
- Free software distributed under the [Apache Software License 2.0](./LICENSE).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# HTTPX Tenacity
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
5
|
+
| Package | [](https://pypi.org/project/httpx-tenacity/) [](https://pypi.org/project/httpx-tenacity/) |
|
|
6
|
+
| Meta | [](LICENSE) [](.github/CODE_OF_CONDUCT.md) [](https://mypy-lang.org/) [](https://github.com/ambv/black) [](https://github.com/astral-sh/ruff) |
|
|
7
|
+
| Automation | [](https://github.com/Midnighter/httpx-tenacity/actions/workflows/main.yml) |
|
|
8
|
+
|
|
9
|
+
_A lightweight package that provides tenacious (retrying) httpx transports._
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
The package is published on [PyPI](https://pypi.org/project/httpx-tenacity/). Install it,
|
|
14
|
+
for example, with pip.
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
pip install httpx-tenacity
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Copyright
|
|
21
|
+
|
|
22
|
+
- Copyright © 2026 Moritz E. Beber.
|
|
23
|
+
- Free software distributed under the [Apache Software License 2.0](./LICENSE).
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
################################################################################
|
|
2
|
+
# Build Configuration
|
|
3
|
+
################################################################################
|
|
4
|
+
|
|
5
|
+
[build-system]
|
|
6
|
+
build-backend = "hatchling.build"
|
|
7
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
8
|
+
|
|
9
|
+
################################################################################
|
|
10
|
+
# Project Configuration
|
|
11
|
+
################################################################################
|
|
12
|
+
|
|
13
|
+
[project]
|
|
14
|
+
name = "httpx-tenacity"
|
|
15
|
+
dynamic = ["version"]
|
|
16
|
+
description = "A lightweight package that provides tenacious (retrying) httpx transports."
|
|
17
|
+
authors = [{ name = "Moritz E. Beber", email = "midnighter@posteo.net" }]
|
|
18
|
+
license = "Apache-2.0"
|
|
19
|
+
readme = { "file" = "README.md", "content-type" = "text/markdown" }
|
|
20
|
+
requires-python = ">=3.10"
|
|
21
|
+
# Please consult https://pypi.org/classifiers/ for a full list.
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
24
|
+
"Environment :: Web Environment",
|
|
25
|
+
"Intended Audience :: Developers",
|
|
26
|
+
"License :: OSI Approved :: Apache Software License",
|
|
27
|
+
"Natural Language :: English",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
30
|
+
"Programming Language :: Python :: 3.10",
|
|
31
|
+
"Programming Language :: Python :: 3.11",
|
|
32
|
+
"Programming Language :: Python :: 3.12",
|
|
33
|
+
"Programming Language :: Python :: 3.13",
|
|
34
|
+
"Programming Language :: Python :: 3.14",
|
|
35
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
36
|
+
"Typing :: Typed",
|
|
37
|
+
]
|
|
38
|
+
keywords = ["httpx", "tenacity", "retry"]
|
|
39
|
+
dependencies = [
|
|
40
|
+
"httpx ~=0.25",
|
|
41
|
+
"tenacity ~=9.1",
|
|
42
|
+
"typing-extensions ~=4.6; python_version < '3.11'",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[project.urls]
|
|
46
|
+
Homepage = "https://github.com/Midnighter/httpx-tenacity"
|
|
47
|
+
Documentation = "https://midnighter.github.io/httpx-tenacity/"
|
|
48
|
+
"Source Code" = "https://github.com/Midnighter/httpx-tenacity"
|
|
49
|
+
"Bug Tracker" = "https://github.com/Midnighter/httpx-tenacity/issues"
|
|
50
|
+
Download = "https://pypi.org/project/httpx-tenacity/#files"
|
|
51
|
+
|
|
52
|
+
[dependency-groups]
|
|
53
|
+
style = ["pydoclint", "ruff"]
|
|
54
|
+
types = ["mypy", "ty"]
|
|
55
|
+
docs = [
|
|
56
|
+
"mkdocs-material ~=9.5",
|
|
57
|
+
"mkdocstrings[python] ~=1.0",
|
|
58
|
+
"mkdocs-awesome-pages-plugin ~=2.9",
|
|
59
|
+
"mike ~=2.1",
|
|
60
|
+
]
|
|
61
|
+
tests = ["anyio", "pytest", "pytest-cov", "pytest-httpx", "pytest-raises"]
|
|
62
|
+
|
|
63
|
+
################################################################################
|
|
64
|
+
# Tool Configuration
|
|
65
|
+
################################################################################
|
|
66
|
+
|
|
67
|
+
[tool.hatch.build]
|
|
68
|
+
only-packages = true
|
|
69
|
+
|
|
70
|
+
[tool.hatch.build.targets.wheel]
|
|
71
|
+
packages = ["src/httpx_tenacity"]
|
|
72
|
+
|
|
73
|
+
[tool.hatch.build.hooks.vcs]
|
|
74
|
+
version-file = "src/httpx_tenacity/_version.py"
|
|
75
|
+
|
|
76
|
+
[tool.hatch.version]
|
|
77
|
+
source = "vcs"
|
|
78
|
+
|
|
79
|
+
[tool.pytest.ini_options]
|
|
80
|
+
testpaths = ["tests"]
|
|
81
|
+
markers = ["raises"]
|
|
82
|
+
|
|
83
|
+
[tool.coverage.paths]
|
|
84
|
+
source = ["src/httpx_tenacity", "*/site-packages/httpx_tenacity"]
|
|
85
|
+
|
|
86
|
+
[tool.coverage.run]
|
|
87
|
+
branch = true
|
|
88
|
+
parallel = true
|
|
89
|
+
omit = ["src/httpx_tenacity/_version.py"]
|
|
90
|
+
|
|
91
|
+
[tool.coverage.report]
|
|
92
|
+
exclude_lines = ["pragma: no cover"]
|
|
93
|
+
precision = 2
|
|
94
|
+
|
|
95
|
+
[tool.ruff]
|
|
96
|
+
line-length = 88
|
|
97
|
+
|
|
98
|
+
[tool.ruff.lint]
|
|
99
|
+
select = ["ALL"]
|
|
100
|
+
ignore = [
|
|
101
|
+
"D107", # 'Missing docstring in __init__' ignored because pydoclint wants us to document the class instead.
|
|
102
|
+
"D203", # '1 blank line required before class docstring' ignored because we want no blank line.
|
|
103
|
+
"D212", # 'Multi-line docstring summary should start at the first line' ignored because we want the summary to start on the second line.
|
|
104
|
+
"D407", # 'Missing dashed underline after section' ignored because Google style docstrings don't underline.
|
|
105
|
+
"ANN002", # 'Missing type annotation for {*args} in method'.
|
|
106
|
+
"ANN003", # 'Missing type annotation for {*kwargs} in method'.
|
|
107
|
+
]
|
|
108
|
+
exclude = ["src/httpx_tenacity/_version.py"]
|
|
109
|
+
|
|
110
|
+
[tool.ruff.lint.extend-per-file-ignores]
|
|
111
|
+
"__init__.py" = [
|
|
112
|
+
"E401", # 'Multiple imports on one line'
|
|
113
|
+
"E402", # 'Module level import not at top of file'
|
|
114
|
+
"F401", # 'Imported but unused'
|
|
115
|
+
"I001", # 'Import block is un-sorted or un-formatted' ignored because we may have to import in a particular, not-alphabetical order.
|
|
116
|
+
]
|
|
117
|
+
"tests/**/*.py" = [
|
|
118
|
+
"S101", # 'Use of assert detected' ignored because we are using pytest.
|
|
119
|
+
"INP001", # 'Insecure input' ignored because we are testing.
|
|
120
|
+
"ANN201", # 'Missing type annotation for {return}' ignored because all tests return `None`.
|
|
121
|
+
"PLR2004", # Magic numbers are okay in tests.
|
|
122
|
+
"FBT001", # Boolean positional arguments are fine in tests.
|
|
123
|
+
]
|
|
124
|
+
"tests/pyodide/**/*.py" = [
|
|
125
|
+
"PLC0415", # We explicitly need imports inside function and ignore the '`import` should be at the top-level of a file' rule.
|
|
126
|
+
"I001", # 'Import block is un-sorted or un-formatted' ignored because we may have to import in a particular, not-alphabetical order.
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
[tool.ruff.lint.isort]
|
|
130
|
+
case-sensitive = true
|
|
131
|
+
known-first-party = ["src", "httpx_tenacity"]
|
|
132
|
+
lines-after-imports = 2
|
|
133
|
+
|
|
134
|
+
[tool.pydoclint]
|
|
135
|
+
style = "google"
|
|
136
|
+
arg-type-hints-in-docstring = false
|
|
137
|
+
check-return-types = false
|
|
138
|
+
check-yield-types = false
|
|
139
|
+
exclude = "_version.py"
|
|
140
|
+
|
|
141
|
+
################################################################################
|
|
142
|
+
# Hatch Environments
|
|
143
|
+
################################################################################
|
|
144
|
+
|
|
145
|
+
[tool.hatch.envs.default]
|
|
146
|
+
description = """
|
|
147
|
+
Base environment with default configuration values.
|
|
148
|
+
|
|
149
|
+
All environments inheriting from the default also inherit the configuration values set
|
|
150
|
+
here.
|
|
151
|
+
"""
|
|
152
|
+
installer = "uv"
|
|
153
|
+
|
|
154
|
+
[tool.hatch.envs.dev]
|
|
155
|
+
description = """Development environment."""
|
|
156
|
+
dependency-groups = ["style", "types", "docs", "tests"]
|
|
157
|
+
|
|
158
|
+
[tool.hatch.envs.dev.env-vars]
|
|
159
|
+
PYTHONDEVMODE = "1"
|
|
160
|
+
PYTHONASYNCIODEBUG = "1"
|
|
161
|
+
|
|
162
|
+
[tool.hatch.envs.style]
|
|
163
|
+
description = """Check the style of the codebase."""
|
|
164
|
+
dependency-groups = ["style"]
|
|
165
|
+
detached = true
|
|
166
|
+
installer = "uv"
|
|
167
|
+
|
|
168
|
+
[tool.hatch.envs.style.scripts]
|
|
169
|
+
docstrings = ["pydoclint src", "pydoclint tests"]
|
|
170
|
+
code = "ruff check {args}"
|
|
171
|
+
format = "ruff format {args}"
|
|
172
|
+
fix = "ruff check --fix {args}"
|
|
173
|
+
check = ["docstrings", "code"]
|
|
174
|
+
|
|
175
|
+
[tool.hatch.envs.audit]
|
|
176
|
+
description = """Check dependencies for security vulnerabilities."""
|
|
177
|
+
extra-dependencies = ["pip-audit"]
|
|
178
|
+
|
|
179
|
+
[tool.hatch.envs.audit.scripts]
|
|
180
|
+
check = ["pip-audit"]
|
|
181
|
+
|
|
182
|
+
[tool.hatch.envs.types]
|
|
183
|
+
description = """Check the static types of the codebase."""
|
|
184
|
+
dependency-groups = ["types"]
|
|
185
|
+
|
|
186
|
+
[tool.hatch.envs.types.scripts]
|
|
187
|
+
check = ["mypy src/httpx_tenacity", "ty check src/httpx_tenacity"]
|
|
188
|
+
|
|
189
|
+
[tool.hatch.envs.docs]
|
|
190
|
+
description = """Build or serve the documentation."""
|
|
191
|
+
dependency-groups = ["docs"]
|
|
192
|
+
|
|
193
|
+
[tool.hatch.envs.docs.scripts]
|
|
194
|
+
build = "mkdocs build {args:--clean --strict}"
|
|
195
|
+
serve = "mkdocs serve {args}"
|
|
196
|
+
deploy = "mike deploy {args}"
|
|
197
|
+
|
|
198
|
+
[tool.hatch.envs.distribution]
|
|
199
|
+
description = """Test the source and wheel distribution of the package."""
|
|
200
|
+
dependencies = ["pip", "twine"]
|
|
201
|
+
detached = true
|
|
202
|
+
installer = "uv"
|
|
203
|
+
builder = true
|
|
204
|
+
|
|
205
|
+
[tool.hatch.envs.distribution.scripts]
|
|
206
|
+
check = ["pip check", "hatch build {args:--clean}", "twine check dist/*"]
|
|
207
|
+
|
|
208
|
+
[tool.hatch.envs.unit-tests]
|
|
209
|
+
description = """Run the unit tests."""
|
|
210
|
+
dependency-groups = ["tests"]
|
|
211
|
+
|
|
212
|
+
[tool.hatch.envs.unit-tests.env-vars]
|
|
213
|
+
PYTHONDEVMODE = "1"
|
|
214
|
+
PYTHONASYNCIODEBUG = "1"
|
|
215
|
+
|
|
216
|
+
[[tool.hatch.envs.unit-tests.matrix]]
|
|
217
|
+
python = ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
218
|
+
|
|
219
|
+
[tool.hatch.envs.unit-tests.scripts]
|
|
220
|
+
run = "pytest {args:--cov=httpx_tenacity --cov-report=term-missing} {root}/tests/unit"
|
|
221
|
+
|
|
222
|
+
[tool.hatch.envs.acceptance-tests]
|
|
223
|
+
description = """Run the acceptance tests."""
|
|
224
|
+
dependency-groups = ["tests"]
|
|
225
|
+
|
|
226
|
+
[tool.hatch.envs.acceptance-tests.env-vars]
|
|
227
|
+
PYTHONDEVMODE = "1"
|
|
228
|
+
PYTHONASYNCIODEBUG = "1"
|
|
229
|
+
|
|
230
|
+
[[tool.hatch.envs.acceptance-tests.matrix]]
|
|
231
|
+
python = ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
232
|
+
|
|
233
|
+
[tool.hatch.envs.acceptance-tests.scripts]
|
|
234
|
+
run = "pytest {args:--cov=httpx_tenacity --cov-report=term-missing} {root}/tests/acceptance"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Copyright (c) 2026 Moritz E. Beber
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
|
5
|
+
# the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
12
|
+
# License for the specific language governing permissions and limitations under
|
|
13
|
+
# the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"""Provide top level symbols."""
|
|
17
|
+
|
|
18
|
+
from .types import HTTPXHTTPTransportKeywordArguments
|
|
19
|
+
from .async_tenacious_transport import AsyncTenaciousTransport
|
|
20
|
+
from .tenacious_transport import TenaciousTransport
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
TYPE_CHECKING = False
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from typing import Union
|
|
17
|
+
|
|
18
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
20
|
+
else:
|
|
21
|
+
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
23
|
+
|
|
24
|
+
version: str
|
|
25
|
+
__version__: str
|
|
26
|
+
__version_tuple__: VERSION_TUPLE
|
|
27
|
+
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
30
|
+
|
|
31
|
+
__version__ = version = '0.1.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 1, 0)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Copyright (c) 2026 Moritz E. Beber
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
|
5
|
+
# the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
12
|
+
# License for the specific language governing permissions and limitations under
|
|
13
|
+
# the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"""Provide an asynchronous tenacious (retrying) transport."""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import logging
|
|
21
|
+
import sys
|
|
22
|
+
from typing import TYPE_CHECKING
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if sys.version_info < (3, 11):
|
|
26
|
+
from typing_extensions import Unpack
|
|
27
|
+
else:
|
|
28
|
+
from typing import Unpack
|
|
29
|
+
|
|
30
|
+
import httpx
|
|
31
|
+
import tenacity
|
|
32
|
+
|
|
33
|
+
from httpx_tenacity.retry_callback import is_server_side_issue
|
|
34
|
+
from httpx_tenacity.wait import smart_wait
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
38
|
+
from datetime import timedelta
|
|
39
|
+
|
|
40
|
+
from .types import HTTPXHTTPTransportKeywordArguments
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
logger = logging.getLogger(__name__)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class AsyncTenaciousTransport(httpx.AsyncBaseTransport):
|
|
47
|
+
"""
|
|
48
|
+
Define the asynchronous tenacious (retrying) transport.
|
|
49
|
+
|
|
50
|
+
This transport consists of a composed transport for handling requests and an
|
|
51
|
+
appropriately configured tenacity retrying instance.
|
|
52
|
+
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
*,
|
|
58
|
+
retry: tenacity.AsyncRetrying,
|
|
59
|
+
transport: httpx.AsyncBaseTransport,
|
|
60
|
+
**kwargs: dict[str, object],
|
|
61
|
+
) -> None:
|
|
62
|
+
super().__init__(**kwargs)
|
|
63
|
+
self._retry = retry
|
|
64
|
+
self._transport = transport
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def create(
|
|
68
|
+
cls,
|
|
69
|
+
max_attempts: int = 5,
|
|
70
|
+
multiplier: float = 1,
|
|
71
|
+
max_wait_seconds: float | timedelta = 60,
|
|
72
|
+
min_wait_seconds: float | timedelta = 0.02,
|
|
73
|
+
exponent_base: float = 2,
|
|
74
|
+
**kwargs: Unpack[HTTPXHTTPTransportKeywordArguments],
|
|
75
|
+
) -> AsyncTenaciousTransport:
|
|
76
|
+
"""
|
|
77
|
+
Create an instance of an asynchronous tenacious (retrying) transport.
|
|
78
|
+
|
|
79
|
+
This factory method constructs the instance with an underlying
|
|
80
|
+
`httpx.AsyncHTTPTransport`.
|
|
81
|
+
That transport is passed any additional keyword arguments.
|
|
82
|
+
|
|
83
|
+
The constructed transport retries requests when there are server-side issues
|
|
84
|
+
and will either wait the time set in a Retry-After response header or use a
|
|
85
|
+
random exponential backoff.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
max_attempts: Maximum number of attempts.
|
|
89
|
+
multiplier: Multiplier for the exponential backoff between retries.
|
|
90
|
+
max_wait_seconds: Maximum wait time between retries.
|
|
91
|
+
min_wait_seconds: Minimum wait time between retries.
|
|
92
|
+
exponent_base: The base for the exponential backoff.
|
|
93
|
+
**kwargs: Additional keyword arguments are used in the construction of an
|
|
94
|
+
`httpx.AsyncHTTPTransport`.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
A default instance of the class created from the given arguments.
|
|
98
|
+
|
|
99
|
+
"""
|
|
100
|
+
return cls(
|
|
101
|
+
retry=tenacity.AsyncRetrying(
|
|
102
|
+
retry=tenacity.retry_if_result(is_server_side_issue),
|
|
103
|
+
stop=tenacity.stop_after_attempt(max_attempts),
|
|
104
|
+
wait=smart_wait(
|
|
105
|
+
multiplier=multiplier,
|
|
106
|
+
max=max_wait_seconds,
|
|
107
|
+
min=min_wait_seconds,
|
|
108
|
+
exp_base=exponent_base,
|
|
109
|
+
),
|
|
110
|
+
before_sleep=tenacity.before_sleep_log(logger, logging.DEBUG),
|
|
111
|
+
reraise=True,
|
|
112
|
+
),
|
|
113
|
+
transport=httpx.AsyncHTTPTransport(**kwargs),
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
async def handle_async_request(
|
|
117
|
+
self,
|
|
118
|
+
request: httpx.Request,
|
|
119
|
+
) -> httpx.Response:
|
|
120
|
+
"""Handle an asynchronous request with retrying."""
|
|
121
|
+
fresh_retry = self._retry.copy()
|
|
122
|
+
async for attempt in fresh_retry:
|
|
123
|
+
with attempt:
|
|
124
|
+
response = await self._transport.handle_async_request(request)
|
|
125
|
+
if attempt.retry_state.outcome and not attempt.retry_state.outcome.failed:
|
|
126
|
+
attempt.retry_state.set_result(response)
|
|
127
|
+
return response
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Copyright (c) 2026 Moritz E. Beber
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
|
5
|
+
# the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
12
|
+
# License for the specific language governing permissions and limitations under
|
|
13
|
+
# the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"""Provide custom retry callback functions."""
|
|
17
|
+
|
|
18
|
+
import httpx
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
HTTP_SERVER_ERROR_UPPER_LIMIT = 599
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def is_server_side_issue(response: httpx.Response) -> bool:
|
|
25
|
+
"""
|
|
26
|
+
Return whether the response indicates a server side issue.
|
|
27
|
+
|
|
28
|
+
A server side issue is defined as either an HTTP server error code (500 - 599) or
|
|
29
|
+
too many requests (429).
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
if (
|
|
33
|
+
httpx.codes.INTERNAL_SERVER_ERROR
|
|
34
|
+
<= response.status_code
|
|
35
|
+
<= HTTP_SERVER_ERROR_UPPER_LIMIT
|
|
36
|
+
):
|
|
37
|
+
return True
|
|
38
|
+
|
|
39
|
+
return response.status_code == httpx.codes.TOO_MANY_REQUESTS
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Copyright (c) 2026 Moritz E. Beber
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
|
5
|
+
# the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
12
|
+
# License for the specific language governing permissions and limitations under
|
|
13
|
+
# the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"""Provide a synchronous tenacious (retrying) transport."""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import logging
|
|
21
|
+
import sys
|
|
22
|
+
from typing import TYPE_CHECKING
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if sys.version_info < (3, 11):
|
|
26
|
+
from typing_extensions import Unpack
|
|
27
|
+
else:
|
|
28
|
+
from typing import Unpack
|
|
29
|
+
|
|
30
|
+
import httpx
|
|
31
|
+
import tenacity
|
|
32
|
+
|
|
33
|
+
from httpx_tenacity.retry_callback import is_server_side_issue
|
|
34
|
+
from httpx_tenacity.wait import smart_wait
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
38
|
+
from datetime import timedelta
|
|
39
|
+
|
|
40
|
+
from .types import HTTPXHTTPTransportKeywordArguments
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
logger = logging.getLogger(__name__)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class TenaciousTransport(httpx.BaseTransport):
|
|
47
|
+
"""
|
|
48
|
+
Define the synchronous tenacious (retrying) transport.
|
|
49
|
+
|
|
50
|
+
This transport consists of a composed transport for handling requests and an
|
|
51
|
+
appropriately configured tenacity retrying instance.
|
|
52
|
+
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
*,
|
|
58
|
+
retry: tenacity.Retrying,
|
|
59
|
+
transport: httpx.BaseTransport,
|
|
60
|
+
**kwargs: dict[str, object],
|
|
61
|
+
) -> None:
|
|
62
|
+
super().__init__(**kwargs)
|
|
63
|
+
self._retry = retry
|
|
64
|
+
self._transport = transport
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def create(
|
|
68
|
+
cls,
|
|
69
|
+
max_attempts: int = 5,
|
|
70
|
+
multiplier: float = 1,
|
|
71
|
+
max_wait_seconds: float | timedelta = 60,
|
|
72
|
+
min_wait_seconds: float | timedelta = 0.02,
|
|
73
|
+
exponent_base: float = 2,
|
|
74
|
+
**kwargs: Unpack[HTTPXHTTPTransportKeywordArguments],
|
|
75
|
+
) -> TenaciousTransport:
|
|
76
|
+
"""
|
|
77
|
+
Create an instance of a synchronous tenacious (retrying) transport.
|
|
78
|
+
|
|
79
|
+
This factory method constructs the instance with an underlying
|
|
80
|
+
`httpx.HTTPTransport`.
|
|
81
|
+
That transport is passed any additional keyword arguments.
|
|
82
|
+
|
|
83
|
+
The constructed transport retries requests when there are server-side issues
|
|
84
|
+
and will either wait the time set in a Retry-After response header or use a
|
|
85
|
+
random exponential backoff.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
max_attempts: Maximum number of attempts.
|
|
89
|
+
multiplier: Multiplier for the exponential backoff between retries.
|
|
90
|
+
max_wait_seconds: Maximum wait time between retries.
|
|
91
|
+
min_wait_seconds: Minimum wait time between retries.
|
|
92
|
+
exponent_base: The base for the exponential backoff.
|
|
93
|
+
**kwargs: Additional keyword arguments are used in the construction of an
|
|
94
|
+
`httpx.HTTPTransport`.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
A default instance of the class created from the given arguments.
|
|
98
|
+
|
|
99
|
+
"""
|
|
100
|
+
return cls(
|
|
101
|
+
retry=tenacity.Retrying(
|
|
102
|
+
retry=tenacity.retry_if_result(is_server_side_issue),
|
|
103
|
+
stop=tenacity.stop_after_attempt(max_attempts),
|
|
104
|
+
wait=smart_wait(
|
|
105
|
+
multiplier=multiplier,
|
|
106
|
+
max=max_wait_seconds,
|
|
107
|
+
min=min_wait_seconds,
|
|
108
|
+
exp_base=exponent_base,
|
|
109
|
+
),
|
|
110
|
+
before_sleep=tenacity.before_sleep_log(logger, logging.DEBUG),
|
|
111
|
+
reraise=True,
|
|
112
|
+
),
|
|
113
|
+
transport=httpx.HTTPTransport(**kwargs),
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
def handle_request(
|
|
117
|
+
self,
|
|
118
|
+
request: httpx.Request,
|
|
119
|
+
) -> httpx.Response:
|
|
120
|
+
"""Handle a synchronous request with retrying."""
|
|
121
|
+
fresh_retry = self._retry.copy()
|
|
122
|
+
for attempt in fresh_retry:
|
|
123
|
+
with attempt:
|
|
124
|
+
response = self._transport.handle_request(request)
|
|
125
|
+
if attempt.retry_state.outcome and not attempt.retry_state.outcome.failed:
|
|
126
|
+
attempt.retry_state.set_result(response)
|
|
127
|
+
return response
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Copyright (c) 2025 Moritz E. Beber
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
|
5
|
+
# the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
12
|
+
# License for the specific language governing permissions and limitations under
|
|
13
|
+
# the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"""Provide additional type definitions."""
|
|
17
|
+
|
|
18
|
+
import ssl
|
|
19
|
+
from collections.abc import Iterable
|
|
20
|
+
from typing import TypeAlias, TypedDict
|
|
21
|
+
|
|
22
|
+
import httpx
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Fallback for Pyodide HTTPX. See: https://github.com/Midnighter/httpx-tenacity/pull/10#issuecomment-3241566927
|
|
26
|
+
SocketOption: TypeAlias = (
|
|
27
|
+
tuple[int, int, int]
|
|
28
|
+
| tuple[int, int, bytes | bytearray]
|
|
29
|
+
| tuple[int, int, None, int]
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# We redefine the following types from httpx._types to avoid a dependency on the
|
|
33
|
+
# private module. It would be better if HTTPX exposed these types publicly, but
|
|
34
|
+
# they are unlikely to change often. Thus we consider it acceptable to redefine
|
|
35
|
+
# them here for type hinting purposes.
|
|
36
|
+
CertTypes: TypeAlias = str | tuple[str, str] | tuple[str, str, str]
|
|
37
|
+
ProxyTypes: TypeAlias = httpx.URL | str | httpx.Proxy
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class HTTPXHTTPTransportKeywordArguments(TypedDict, total=False):
|
|
41
|
+
"""Keyword arguments for the sync and async httpx HTTPTransport constructor."""
|
|
42
|
+
|
|
43
|
+
verify: ssl.SSLContext | str | bool
|
|
44
|
+
cert: CertTypes | None
|
|
45
|
+
trust_env: bool
|
|
46
|
+
http1: bool
|
|
47
|
+
http2: bool
|
|
48
|
+
limits: httpx.Limits
|
|
49
|
+
proxy: ProxyTypes | None
|
|
50
|
+
uds: str | None
|
|
51
|
+
local_address: str | None
|
|
52
|
+
retries: int
|
|
53
|
+
socket_options: Iterable[SocketOption] | None
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Copyright (c) 2026 Moritz E. Beber
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
4
|
+
# use this file except in compliance with the License. You may obtain a copy of
|
|
5
|
+
# the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
11
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
12
|
+
# License for the specific language governing permissions and limitations under
|
|
13
|
+
# the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"""Provide custom wait functions."""
|
|
17
|
+
|
|
18
|
+
import httpx
|
|
19
|
+
import tenacity
|
|
20
|
+
from tenacity.wait import wait_random_exponential
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# We follow tenacity's convention here to use lower snake-case class names for the wait
|
|
24
|
+
# strategies.
|
|
25
|
+
class smart_wait(wait_random_exponential): # noqa: N801
|
|
26
|
+
"""
|
|
27
|
+
Wait strategy that smartly backs-off.
|
|
28
|
+
|
|
29
|
+
This strategy first checks the Retry-After response header for a wait time
|
|
30
|
+
indication and uses random exponential backoff if that is not the case.
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __call__(self, retry_state: tenacity.RetryCallState) -> float: # noqa: D102
|
|
35
|
+
# When we have a successful outcome, i.e., we received an HTTP response without
|
|
36
|
+
# encountering a Python exception, check if the response headers indicate a wait
|
|
37
|
+
# time; otherwise use the random exponential strategy to determine the wait
|
|
38
|
+
# time.
|
|
39
|
+
if retry_state.outcome and not retry_state.outcome.failed:
|
|
40
|
+
response: httpx.Response = retry_state.outcome.result()
|
|
41
|
+
if (
|
|
42
|
+
response.status_code == httpx.codes.TOO_MANY_REQUESTS
|
|
43
|
+
and (wait := response.headers.get("Retry-After")) is not None
|
|
44
|
+
):
|
|
45
|
+
return float(wait)
|
|
46
|
+
|
|
47
|
+
return super().__call__(retry_state=retry_state)
|