tiny-retriever 0.3.0__tar.gz → 0.4.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 (47) hide show
  1. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.github/workflows/docs.yml +22 -1
  2. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.github/workflows/release.yml +1 -1
  3. tiny_retriever-0.4.0/CHANGELOG.md +130 -0
  4. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/PKG-INFO +39 -13
  5. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/README.md +34 -9
  6. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/environment.yml +1 -1
  7. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/pyproject.toml +4 -3
  8. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/src/tiny_retriever/__init__.py +10 -6
  9. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/src/tiny_retriever/exceptions.py +15 -2
  10. tiny_retriever-0.4.0/src/tiny_retriever/tiny_retriever.py +1312 -0
  11. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/src/tiny_retriever/tiny_retriever.pyi +41 -5
  12. tiny_retriever-0.4.0/tests/conftest.py +69 -0
  13. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/tests/test_exceptions.py +56 -0
  14. tiny_retriever-0.4.0/tests/test_filename.py +167 -0
  15. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/tests/test_retriever.py +460 -6
  16. tiny_retriever-0.4.0/tests/test_sockets.py +434 -0
  17. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/tests/test_threading.py +67 -22
  18. tiny_retriever-0.3.0/CHANGELOG.md +0 -66
  19. tiny_retriever-0.3.0/src/tiny_retriever/tiny_retriever.py +0 -788
  20. tiny_retriever-0.3.0/tests/test_filename.py +0 -119
  21. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.codecov.yml +0 -0
  22. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.gitattributes +0 -0
  23. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.github/ISSUE_TEMPLATE/bugreport.yml +0 -0
  24. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  25. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.github/ISSUE_TEMPLATE/newfeature.yml +0 -0
  26. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  27. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.github/dependabot.yml +0 -0
  28. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.github/workflows/test.yml +0 -0
  29. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.gitignore +0 -0
  30. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.pre-commit-config.yaml +0 -0
  31. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/.readthedocs.yaml +0 -0
  32. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/AUTHORS.md +0 -0
  33. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/CODE_OF_CONDUCT.md +0 -0
  34. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/CONTRIBUTING.md +0 -0
  35. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/LICENSE +0 -0
  36. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/docs/assets/logo.png +0 -0
  37. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/docs/assets/logo.svg +0 -0
  38. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/docs/docs_hooks.py +0 -0
  39. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/docs/examples/hydrodata.ipynb +0 -0
  40. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/docs/examples/images/dem.png +0 -0
  41. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/docs/examples/index.md +0 -0
  42. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/docs/javascripts/mathjax.js +0 -0
  43. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/docs/overrides/main.html +0 -0
  44. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/docs/reference.md +0 -0
  45. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/docs/stylesheets/extra.css +0 -0
  46. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/mkdocs.yml +0 -0
  47. {tiny_retriever-0.3.0 → tiny_retriever-0.4.0}/src/tiny_retriever/py.typed +0 -0
@@ -11,6 +11,10 @@ on:
11
11
  permissions:
12
12
  contents: write
13
13
 
14
+ concurrency:
15
+ group: docs-deploy
16
+ cancel-in-progress: false
17
+
14
18
  jobs:
15
19
  docs:
16
20
  name: Deploy Documentation
@@ -32,6 +36,9 @@ jobs:
32
36
  git config user.name "github-actions[bot]"
33
37
  git config user.email "github-actions[bot]@users.noreply.github.com"
34
38
 
39
+ - name: Fetch gh-pages branch
40
+ run: git fetch origin gh-pages:gh-pages || true
41
+
35
42
  - name: Deploy latest docs (main branch)
36
43
  if: github.ref == 'refs/heads/main'
37
44
  run: |-
@@ -41,5 +48,19 @@ jobs:
41
48
  - name: Deploy release docs (tagged version)
42
49
  if: startsWith(github.ref, 'refs/tags/v')
43
50
  run: |-
51
+ VERSION=$(git describe --tags --abbrev=0)
52
+ # Find the previous stable version before deploying
53
+ PREV=$(mike list --json 2>/dev/null | python3 -c "
54
+ import json, sys
55
+ versions = json.load(sys.stdin)
56
+ prev = [v['version'] for v in versions if 'stable' in v.get('aliases', [])]
57
+ print(prev[0] if prev else '')
58
+ " || true)
59
+ # Deploy new version with stable alias
44
60
  pixi r docs-release
45
- mike set-default --push stable
61
+ mike retitle --push "$VERSION" "$VERSION (stable)"
62
+ # Remove (stable) label from previous version
63
+ if [ -n "$PREV" ] && [ "$PREV" != "$VERSION" ]; then
64
+ mike retitle --push "$PREV" "$PREV"
65
+ fi
66
+ mike set-default --push latest
@@ -47,7 +47,7 @@ jobs:
47
47
  with:
48
48
  fetch-depth: 0
49
49
 
50
- - uses: hynek/build-and-inspect-python-package@v2
50
+ - uses: hynek/build-and-inspect-python-package@67230f7b8410ae0052b39c1efc89d89fff43ff10 # v3.0.2
51
51
  with:
52
52
  attest-build-provenance-github: true
53
53
 
@@ -0,0 +1,130 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. The format is based
4
+ on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to
5
+ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.4.0] - 2026-12-01
8
+
9
+ ### Added
10
+
11
+ - Widen the default retry window and read it from the environment
12
+ - Give ServiceError the HTTP status and the start of the error body
13
+ - Retry 429 responses and honor Retry-After
14
+ - Add fetch_response to return status and headers for any HTTP status
15
+
16
+ ### Changed
17
+
18
+ - Run fetch, download, and check_downloads through one retry loop
19
+ - Sort the local test server methods
20
+ - Drop a no-op wait from the loop thread stop
21
+
22
+ ### Fixed
23
+
24
+ - Reject unusable retry settings and attempt counts below one
25
+ - Default to three attempts and tell the caller a transient failure is worth retrying
26
+ later
27
+ - Download to a .part file so a failed request keeps the existing file
28
+ - Retry dropped connections and cut-off bodies, and fail fast on TLS and local file
29
+ errors
30
+ - Report a timeout after one attempt and say how long it waited
31
+ - Start the request timeout once a per-host slot is free
32
+ - Raise ServiceError when check_downloads cannot get a remote size
33
+ - Ask for uncompressed bodies when downloading and checking sizes
34
+ - Log the failures that raise_status=False turns into None
35
+ - Cancel the requests when the caller is interrupted
36
+ - Cancel the rest of a batch when one request fails
37
+ - Reject one request_kwargs dict for several URLs
38
+ - Add unique_filename params to the URL's own query
39
+ - Decode JSON responses whatever their mimetype
40
+ - Decode text without a declared charset as UTF-8 before latin1
41
+ - Accept yarl.URL in fetch as its annotation says
42
+ - Reject request_kwargs keys that fetch sets, and accept a generator of dicts
43
+ - Accept (key, value) pairs as unique_filename params and reject unusable values
44
+ - Reject a directory as a download target before any request
45
+ - Let a download that keeps receiving data run past its timeout
46
+ - Validate MAX_CONCURRENT_CALLS like the other settings and document it as per call
47
+ - Make the Windows selector loop directly instead of setting the deprecated global
48
+ policy
49
+ - Type JSON results as any JSON value and drop a stale stub header
50
+ - Let ServiceError survive pickling and expose its url
51
+ - Report a malformed URL as a ServiceError that raise_status=False logs
52
+ - Treat limit_per_host=0 as no per-host limit, as aiohttp does
53
+ - Do not call a certificate fingerprint mismatch temporary
54
+ - Keep the HTTP status when the error body fails to arrive
55
+ - Send each download and size-check attempt once
56
+ - Stream each download attempt to its own temporary file and keep the target mode
57
+ - Open the temporary file without creating it, so a cancelled open leaves nothing
58
+ - Raise errors of local file operations as they are, timeouts included
59
+ - Let cancelled work clean up after Ctrl-C and before the loop closes
60
+ - Do not retry a 5xx whose error body timed out
61
+ - Drop special mode bits when replacing a file and fit long names in the temporary file
62
+ - Warn and use the default for an unusable environment setting
63
+ - Keep unique_filename fields apart and ignore query key order
64
+ - Do not retry a POST request that got a 5xx response
65
+ - Stop a huge environment integer from failing the import
66
+ - Name files from the encoded URL so an escaped slash keeps its own name
67
+ - Give a bare host and its root path one file name
68
+ - Retry a download's final replace while Windows holds the target
69
+
70
+ ## [0.3.0] - 2026-03-30
71
+
72
+ ### Added
73
+
74
+ - Add retry with exponential backoff for transient errors
75
+
76
+ ## [0.2.1] - 2026-02-09
77
+
78
+ ### Added
79
+
80
+ - Add a new function to check for corrupted download files.
81
+
82
+ ## [0.2.0] - 2026-01-30
83
+
84
+ ### Added
85
+
86
+ - Rewrite all tests using aioresponses.
87
+ - Add support for toggling ssl verification.
88
+
89
+ ## [0.1.3] - 2025-02-20
90
+
91
+ ### Added
92
+
93
+ - Change the timeout from session to request level.
94
+
95
+ ## [0.1.2] - 2025-02-18
96
+
97
+ ### Fixed
98
+
99
+ - Make \_AsyncLoopThread a singleton
100
+ - More robust handling of thread starting/stopping to avoid issues with other threadsafe
101
+ libraries.
102
+
103
+ ## [0.1.1] - 2025-02-12
104
+
105
+ ### Added
106
+
107
+ - Check if the input query parameters that are apssed to aiohttp are valid
108
+
109
+ ## [0.1.0] - 2025-02-12
110
+
111
+ ### Added
112
+
113
+ - Add support for passing a single url/kwargs instead of a list.
114
+
115
+ ### Fixed
116
+
117
+ - If the input is a single url/kwargs return a response instead of list.
118
+
119
+ ### New Contributors
120
+
121
+ - @ made their first contribution
122
+ - @cheginit made their first contribution
123
+
124
+ [0.1.1]: https://github.com/cheginit/tiny-retriever/compare/v0.1.0...v0.1.1
125
+ [0.1.2]: https://github.com/cheginit/tiny-retriever/compare/v0.1.1...v0.1.2
126
+ [0.1.3]: https://github.com/cheginit/tiny-retriever/compare/v0.1.2...v0.1.3
127
+ [0.2.0]: https://github.com/cheginit/tiny-retriever/compare/v0.1.3...v0.2.0
128
+ [0.2.1]: https://github.com/cheginit/tiny-retriever/compare/v0.2.0...v0.2.1
129
+ [0.3.0]: https://github.com/cheginit/tiny-retriever/compare/v0.2.1...v0.3.0
130
+ [0.4.0]: https://github.com/cheginit/tiny-retriever/compare/v0.3.0...v0.4.0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: tiny-retriever
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: A synchronous wrapper for AIOHTTP
5
5
  Project-URL: Changelog, https://cheginit.github.io/tiny-retriever/CHANGELOG
6
6
  Project-URL: CI, https://github.com/cheginit/tiny-retriever/actions
@@ -25,8 +25,10 @@ Classifier: Topic :: Scientific/Engineering
25
25
  Classifier: Topic :: Scientific/Engineering :: GIS
26
26
  Classifier: Typing :: Typed
27
27
  Requires-Python: >=3.10
28
- Requires-Dist: aiofiles
28
+ Requires-Dist: aiofiles>=0.8
29
29
  Requires-Dist: aiohttp>=3.8.6
30
+ Requires-Dist: multidict>=4.5
31
+ Requires-Dist: yarl>=1
30
32
  Provides-Extra: dev
31
33
  Requires-Dist: aioresponses; extra == 'dev'
32
34
  Requires-Dist: geopandas>=1; extra == 'dev'
@@ -59,7 +61,6 @@ Requires-Dist: aioresponses; extra == 'test'
59
61
  Requires-Dist: coverage[toml]; extra == 'test'
60
62
  Requires-Dist: pytest-cov; extra == 'test'
61
63
  Requires-Dist: pytest-sugar; extra == 'test'
62
- Requires-Dist: shapely>=2; extra == 'test'
63
64
  Provides-Extra: typecheck
64
65
  Requires-Dist: pyright; extra == 'typecheck'
65
66
  Description-Content-Type: text/markdown
@@ -97,8 +98,8 @@ TinyRetriever provides the following features:
97
98
  - **Unique Filenames**: Generate unique filenames based on query parameters
98
99
  - **Works in Jupyter Notebooks**: Easily use TinyRetriever in Jupyter notebooks without
99
100
  any additional setup or dependencies
100
- - **Automatic Retries**: Exponential backoff with jitter for transient errors (5xx, DNS
101
- failures, timeouts)
101
+ - **Automatic Retries**: Exponential backoff with jitter for transient errors (5xx,
102
+ failed or dropped connections, cut-off responses)
102
103
  - **Robust Error Handling**: Optional status raising and comprehensive error messages
103
104
  - **Performance Optimized**: Uses [`orjson`](https://github.com/ijl/orjson) when
104
105
  available for faster JSON serialization
@@ -153,6 +154,11 @@ paths = [Path("downloads", p) for p in paths]
153
154
  terry.download(urls, paths)
154
155
  ```
155
156
 
157
+ Each attempt streams to its own temporary `<name>.<random>.part` file, which replaces
158
+ the target only once complete and keeps an existing target's permissions. A failed
159
+ download leaves an existing file unchanged, and concurrent downloads to one path each
160
+ publish a whole body.
161
+
156
162
  ### Fetching Data
157
163
 
158
164
  ```python
@@ -180,6 +186,9 @@ else:
180
186
  print("All files are valid!")
181
187
  ```
182
188
 
189
+ `check_downloads` raises `ServiceError` when it cannot get a remote size, and skips a
190
+ file whose server sends no `Content-Length`.
191
+
183
192
  ### Generate Unique Filenames
184
193
 
185
194
  ```python
@@ -215,7 +224,8 @@ responses = terry.fetch(
215
224
  ### Error Handling
216
225
 
217
226
  ```python
218
- from tiny_retriever import fetch, ServiceError
227
+ from tiny_retriever import fetch
228
+ from tiny_retriever.exceptions import ServiceError
219
229
 
220
230
  try:
221
231
  responses = fetch(urls, return_type="json", raise_status=True)
@@ -223,10 +233,19 @@ except ServiceError as e:
223
233
  print(f"Request failed: {e}")
224
234
  ```
225
235
 
236
+ For an HTTP error, the message quotes the start of the response body, and `e.status`
237
+ holds the status code. `e.status` is `None` when the request got no response. `e.url`
238
+ holds the requested URL.
239
+
226
240
  ### Retry Configuration
227
241
 
228
- All functions retry transient errors (5xx, DNS failures, timeouts) automatically with
229
- exponential backoff and jitter. You can control the number of attempts:
242
+ All functions retry transient errors (5xx responses, failed or dropped connections,
243
+ cut-off responses) automatically with exponential backoff and jitter. A timeout is
244
+ reported as transient without a retry, since the request already waited the full
245
+ timeout, and so is a 5xx response to a POST request, since the server may have acted on
246
+ it. Other errors, such as 4xx responses and TLS or certificate failures, fail at once,
247
+ and local file errors such as a full disk raise as they are. You can control the number
248
+ of attempts:
230
249
 
231
250
  ```python
232
251
  # Retry up to 5 times on transient errors
@@ -240,11 +259,18 @@ terry.download(urls, paths, retries=1)
240
259
 
241
260
  TinyRetriever can be configured through environment variables and function parameters:
242
261
 
243
- - `MAX_CONCURRENT_CALLS`: Maximum number of concurrent requests (default: 10)
262
+ - `MAX_CONCURRENT_CALLS`: Maximum concurrent requests per call (default: 10)
263
+ - `MAX_RETRIES`: Attempts per request for transient errors (default: 3)
264
+ - `BACKOFF_FACTOR`: Seconds before the first retry, doubling up to 30 (default: 0.5)
244
265
  - Default chunk size for downloads: 1 MB
245
- - Default timeout: 2 minutes for fetch, 10 minutes for download
246
- - Default connections per host: 4
247
- - Default retry attempts: 3
266
+ - Default timeout: 2 minutes for a fetch request, and 10 minutes for a download to
267
+ connect or to receive its next chunk of data
268
+ - Default connections per host: 4, and `limit_per_host=0` sets no per-host limit
269
+
270
+ The environment variables are read once, when `tiny_retriever` is first imported, and an
271
+ unusable value logs a warning and falls back to the default. A request that still fails
272
+ with a transient error (5xx, timeout, connection) raises `ServiceError` saying to try
273
+ again later.
248
274
 
249
275
  ## Contributing
250
276
 
@@ -31,8 +31,8 @@ TinyRetriever provides the following features:
31
31
  - **Unique Filenames**: Generate unique filenames based on query parameters
32
32
  - **Works in Jupyter Notebooks**: Easily use TinyRetriever in Jupyter notebooks without
33
33
  any additional setup or dependencies
34
- - **Automatic Retries**: Exponential backoff with jitter for transient errors (5xx, DNS
35
- failures, timeouts)
34
+ - **Automatic Retries**: Exponential backoff with jitter for transient errors (5xx,
35
+ failed or dropped connections, cut-off responses)
36
36
  - **Robust Error Handling**: Optional status raising and comprehensive error messages
37
37
  - **Performance Optimized**: Uses [`orjson`](https://github.com/ijl/orjson) when
38
38
  available for faster JSON serialization
@@ -87,6 +87,11 @@ paths = [Path("downloads", p) for p in paths]
87
87
  terry.download(urls, paths)
88
88
  ```
89
89
 
90
+ Each attempt streams to its own temporary `<name>.<random>.part` file, which replaces
91
+ the target only once complete and keeps an existing target's permissions. A failed
92
+ download leaves an existing file unchanged, and concurrent downloads to one path each
93
+ publish a whole body.
94
+
90
95
  ### Fetching Data
91
96
 
92
97
  ```python
@@ -114,6 +119,9 @@ else:
114
119
  print("All files are valid!")
115
120
  ```
116
121
 
122
+ `check_downloads` raises `ServiceError` when it cannot get a remote size, and skips a
123
+ file whose server sends no `Content-Length`.
124
+
117
125
  ### Generate Unique Filenames
118
126
 
119
127
  ```python
@@ -149,7 +157,8 @@ responses = terry.fetch(
149
157
  ### Error Handling
150
158
 
151
159
  ```python
152
- from tiny_retriever import fetch, ServiceError
160
+ from tiny_retriever import fetch
161
+ from tiny_retriever.exceptions import ServiceError
153
162
 
154
163
  try:
155
164
  responses = fetch(urls, return_type="json", raise_status=True)
@@ -157,10 +166,19 @@ except ServiceError as e:
157
166
  print(f"Request failed: {e}")
158
167
  ```
159
168
 
169
+ For an HTTP error, the message quotes the start of the response body, and `e.status`
170
+ holds the status code. `e.status` is `None` when the request got no response. `e.url`
171
+ holds the requested URL.
172
+
160
173
  ### Retry Configuration
161
174
 
162
- All functions retry transient errors (5xx, DNS failures, timeouts) automatically with
163
- exponential backoff and jitter. You can control the number of attempts:
175
+ All functions retry transient errors (5xx responses, failed or dropped connections,
176
+ cut-off responses) automatically with exponential backoff and jitter. A timeout is
177
+ reported as transient without a retry, since the request already waited the full
178
+ timeout, and so is a 5xx response to a POST request, since the server may have acted on
179
+ it. Other errors, such as 4xx responses and TLS or certificate failures, fail at once,
180
+ and local file errors such as a full disk raise as they are. You can control the number
181
+ of attempts:
164
182
 
165
183
  ```python
166
184
  # Retry up to 5 times on transient errors
@@ -174,11 +192,18 @@ terry.download(urls, paths, retries=1)
174
192
 
175
193
  TinyRetriever can be configured through environment variables and function parameters:
176
194
 
177
- - `MAX_CONCURRENT_CALLS`: Maximum number of concurrent requests (default: 10)
195
+ - `MAX_CONCURRENT_CALLS`: Maximum concurrent requests per call (default: 10)
196
+ - `MAX_RETRIES`: Attempts per request for transient errors (default: 3)
197
+ - `BACKOFF_FACTOR`: Seconds before the first retry, doubling up to 30 (default: 0.5)
178
198
  - Default chunk size for downloads: 1 MB
179
- - Default timeout: 2 minutes for fetch, 10 minutes for download
180
- - Default connections per host: 4
181
- - Default retry attempts: 3
199
+ - Default timeout: 2 minutes for a fetch request, and 10 minutes for a download to
200
+ connect or to receive its next chunk of data
201
+ - Default connections per host: 4, and `limit_per_host=0` sets no per-host limit
202
+
203
+ The environment variables are read once, when `tiny_retriever` is first imported, and an
204
+ unusable value logs a warning and falls back to the default. A request that still fails
205
+ with a transient error (5xx, timeout, connection) raises `ServiceError` saying to try
206
+ again later.
182
207
 
183
208
  ## Contributing
184
209
 
@@ -3,7 +3,7 @@ channels:
3
3
  - conda-forge
4
4
  - nodefaults
5
5
  dependencies:
6
- - python >=3.9
6
+ - python >=3.10
7
7
  - tiny-retriever
8
8
  # notebooks deps
9
9
  - rioxarray
@@ -34,8 +34,10 @@ dynamic = [
34
34
  "version",
35
35
  ]
36
36
  dependencies = [
37
- "aiofiles",
37
+ "aiofiles>=0.8",
38
38
  "aiohttp>=3.8.6",
39
+ "multidict>=4.5",
40
+ "yarl>=1",
39
41
  ]
40
42
  optional-dependencies.dev = [
41
43
  "aioresponses",
@@ -73,7 +75,6 @@ optional-dependencies.test = [
73
75
  "coverage[toml]",
74
76
  "pytest-cov",
75
77
  "pytest-sugar",
76
- "shapely>=2",
77
78
  ]
78
79
  optional-dependencies.typecheck = [
79
80
  "pyright",
@@ -230,7 +231,7 @@ changelog-update = "git cliff -c pyproject.toml -o CHANGELOG.md"
230
231
  [tool.pixi.feature.docs.tasks]
231
232
  docs-build = "mkdocs build --strict"
232
233
  docs-serve = { cmd = "mkdocs serve", depends-on = [ "docs-build" ] }
233
- docs-deploy = "mike deploy --push latest"
234
+ docs-deploy = "mike deploy --push --title latest latest"
234
235
  docs-release = "mike deploy --push --update-aliases $(git describe --tags --abbrev=0) stable"
235
236
 
236
237
  [tool.pixi.feature.lint.tasks]
@@ -2,26 +2,30 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import asyncio
6
- import sys
7
5
  from importlib.metadata import PackageNotFoundError, version
8
6
 
9
7
  from tiny_retriever import exceptions
10
- from tiny_retriever.tiny_retriever import check_downloads, download, fetch, unique_filename
8
+ from tiny_retriever.tiny_retriever import (
9
+ Response,
10
+ check_downloads,
11
+ download,
12
+ fetch,
13
+ fetch_response,
14
+ unique_filename,
15
+ )
11
16
 
12
17
  try:
13
18
  __version__ = version("tiny_retriever")
14
19
  except PackageNotFoundError:
15
20
  __version__ = "999"
16
21
 
17
- if sys.platform == "win32": # pragma: no cover
18
- asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
19
-
20
22
  __all__ = [
23
+ "Response",
21
24
  "__version__",
22
25
  "check_downloads",
23
26
  "download",
24
27
  "exceptions",
25
28
  "fetch",
29
+ "fetch_response",
26
30
  "unique_filename",
27
31
  ]
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import TYPE_CHECKING
5
+ from typing import TYPE_CHECKING, Any
6
6
 
7
7
  if TYPE_CHECKING:
8
8
  from collections.abc import Generator, Sequence
@@ -15,13 +15,26 @@ class ServiceError(Exception):
15
15
  ----------
16
16
  err : str
17
17
  Service error message.
18
+ url : str
19
+ The requested URL. Also available as the ``url`` attribute.
20
+ status : int, optional
21
+ HTTP status of the response, or ``None`` (default) when the
22
+ request failed without one. Also available as the ``status``
23
+ attribute.
18
24
  """
19
25
 
20
- def __init__(self, err: str, url: str) -> None:
26
+ def __init__(self, err: str, url: str, status: int | None = None) -> None:
27
+ self._err = err
28
+ self.url = url
29
+ self.status = status
21
30
  self.message = "Service returned the following error message:\n"
22
31
  self.message += f"URL: {url}\nERROR: {err}\n"
23
32
  super().__init__(self.message)
24
33
 
34
+ def __reduce__(self) -> tuple[type[ServiceError], tuple[str, str, int | None], dict[str, Any]]:
35
+ # args holds only the formatted message, so rebuild from the constructor arguments.
36
+ return type(self), (self._err, self.url, self.status), self.__dict__
37
+
25
38
 
26
39
  class InputValueError(Exception):
27
40
  """Exception raised for invalid input.