asanypath 2.3.0__tar.gz → 2.3.2__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 (81) hide show
  1. {asanypath-2.3.0 → asanypath-2.3.2}/.github/workflows/publish.yml +1 -1
  2. {asanypath-2.3.0 → asanypath-2.3.2}/PKG-INFO +103 -15
  3. {asanypath-2.3.0 → asanypath-2.3.2}/README.md +100 -13
  4. asanypath-2.3.2/SECURITY.md +18 -0
  5. {asanypath-2.3.0 → asanypath-2.3.2}/hatch_build.py +9 -3
  6. {asanypath-2.3.0 → asanypath-2.3.2}/pyproject.toml +1 -0
  7. asanypath-2.3.2/scripts/bench_upload.py +181 -0
  8. asanypath-2.3.2/src/asanypath/_prompt.py +22 -0
  9. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/_transfer.py +78 -5
  10. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/_version.py +2 -2
  11. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/artifactory.py +56 -33
  12. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/azure.py +29 -27
  13. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/batcher.py +16 -19
  14. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/cli.py +18 -6
  15. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/cloud.py +196 -34
  16. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/common.py +46 -12
  17. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/ftp.py +14 -22
  18. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/gcs.py +14 -16
  19. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/http.py +58 -11
  20. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/local.py +0 -1
  21. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/options.py +2 -1
  22. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/s3.py +53 -32
  23. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/ssh.py +157 -42
  24. {asanypath-2.3.0 → asanypath-2.3.2}/tests/conftest.py +6 -0
  25. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_artifactory.py +7 -2
  26. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_azure.py +16 -12
  27. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_batcher.py +0 -1
  28. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_cli.py +16 -10
  29. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_cloudpathmixin.py +10 -9
  30. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_commonpathmixin.py +13 -3
  31. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_gcs.py +2 -7
  32. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_http_auth.py +4 -0
  33. asanypath-2.3.2/tests/test_isolation.py +579 -0
  34. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_s3.py +1 -1
  35. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_ssh.py +21 -2
  36. asanypath-2.3.2/tests/test_ssh_hostkeys.py +149 -0
  37. asanypath-2.3.2/tests/test_transport_hardening.py +149 -0
  38. asanypath-2.3.2/tests/test_upload.py +559 -0
  39. asanypath-2.3.0/SECURITY.md +0 -17
  40. {asanypath-2.3.0 → asanypath-2.3.2}/.copilot/skills/async-python-lib/SKILL.md +0 -0
  41. {asanypath-2.3.0 → asanypath-2.3.2}/.copilot/skills/gitguro/SKILL.md +0 -0
  42. {asanypath-2.3.0 → asanypath-2.3.2}/.github/CODEOWNERS +0 -0
  43. {asanypath-2.3.0 → asanypath-2.3.2}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  44. {asanypath-2.3.0 → asanypath-2.3.2}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  45. {asanypath-2.3.0 → asanypath-2.3.2}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  46. {asanypath-2.3.0 → asanypath-2.3.2}/.github/dependabot.yml +0 -0
  47. {asanypath-2.3.0 → asanypath-2.3.2}/.github/workflows/unittests.yml +0 -0
  48. {asanypath-2.3.0 → asanypath-2.3.2}/.gitignore +0 -0
  49. {asanypath-2.3.0 → asanypath-2.3.2}/.pre-commit-config.yaml +0 -0
  50. {asanypath-2.3.0 → asanypath-2.3.2}/CODE_OF_CONDUCT.md +0 -0
  51. {asanypath-2.3.0 → asanypath-2.3.2}/CONTRIBUTING.md +0 -0
  52. {asanypath-2.3.0 → asanypath-2.3.2}/LICENSE +0 -0
  53. {asanypath-2.3.0 → asanypath-2.3.2}/asanypath.png +0 -0
  54. {asanypath-2.3.0 → asanypath-2.3.2}/compose.yml +0 -0
  55. {asanypath-2.3.0 → asanypath-2.3.2}/scripts/bench.py +0 -0
  56. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/__init__.py +0 -0
  57. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/__init__.pyi +0 -0
  58. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/_backend_opts.py +0 -0
  59. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/_credstore.py +0 -0
  60. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/_resume.py +0 -0
  61. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/asanypath.py +0 -0
  62. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/asanypath.pyi +0 -0
  63. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/cache.py +0 -0
  64. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/exceptions.py +0 -0
  65. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/py.typed +0 -0
  66. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/sync.py +0 -0
  67. {asanypath-2.3.0 → asanypath-2.3.2}/src/asanypath/unsupported.py +0 -0
  68. {asanypath-2.3.0 → asanypath-2.3.2}/tests/__init__.py +0 -0
  69. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_asanypath.py +0 -0
  70. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_backend_options.py +0 -0
  71. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_cache.py +0 -0
  72. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_credstore.py +0 -0
  73. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_ftp.py +0 -0
  74. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_http.py +0 -0
  75. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_local.py +0 -0
  76. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_options.py +0 -0
  77. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_py_typed.py +0 -0
  78. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_resume.py +0 -0
  79. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_sync.py +0 -0
  80. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_syncpath.py +0 -0
  81. {asanypath-2.3.0 → asanypath-2.3.2}/tests/test_unsupported_path.py +0 -0
@@ -139,7 +139,7 @@ jobs:
139
139
  env:
140
140
  VERSION: ${{ needs.release-version.outputs.value }}
141
141
  run: |
142
- unzip -p dist/*.whl '*/METADATA' | grep -Fx "Requires-Dist: asanypath-native~=${VERSION%.*}.0"
142
+ unzip -p dist/*.whl '*/METADATA' | grep -Fx "Requires-Dist: asanypath-native~=${VERSION}"
143
143
 
144
144
  - name: Upload Python distributions
145
145
  uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: asanypath
3
- Version: 2.3.0
3
+ Version: 2.3.2
4
4
  Summary: Async pathlib for local and cloud storage
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.14
19
19
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
20
  Requires-Python: >=3.10
21
21
  Requires-Dist: anyio>=4
22
- Requires-Dist: asanypath-native~=2.3.0
22
+ Requires-Dist: asanypath-native~=2.3.2
23
23
  Requires-Dist: msgspec>=0.22.0
24
24
  Requires-Dist: yarl>=1.2
25
25
  Provides-Extra: all
@@ -31,6 +31,7 @@ Requires-Dist: aiobotocore; extra == 'bench'
31
31
  Requires-Dist: aiofiles; extra == 'bench'
32
32
  Requires-Dist: asyncssh>=2.14; extra == 'bench'
33
33
  Requires-Dist: azure-storage-blob; extra == 'bench'
34
+ Requires-Dist: boto3; extra == 'bench'
34
35
  Requires-Dist: cloudpathlib[all]; extra == 'bench'
35
36
  Requires-Dist: fsspec; extra == 'bench'
36
37
  Requires-Dist: gcloud-aio-storage; extra == 'bench'
@@ -157,7 +158,9 @@ shared reader for local downloads and source reads in cross-backend copies.
157
158
  FTP/FTPS, sources without size metadata, and HTTP servers without advertised
158
159
  range support retain single-stream downloads. Local-only copies and native
159
160
  server-side copy/rename operations retain their existing implementations.
160
- Uploads remain single writes; this does not introduce multipart uploads.
161
+ Large S3/Azure uploads also use concurrent parts within this shared budget.
162
+ GCS resumable sessions remain sequential because the protocol requires ordered
163
+ offsets.
161
164
 
162
165
  Concurrent library copies share a default budget within the event loop. To
163
166
  configure a batch explicitly:
@@ -170,10 +173,14 @@ with TransferBudget(floor=8, ceiling=32, min_range_size=8 * 1024 * 1024, per_fil
170
173
  await asyncio.gather(*(src.copy(dst) for src, dst in pairs))
171
174
  ```
172
175
 
173
- The ceiling bounds concurrent reads in this budget, not metadata requests or
174
- other processes. Parallel range buffers are bounded by the active streams
175
- times the range size; cross-backend destinations still buffer the complete
176
- object for their existing write API. `floor=1` disables automatic splitting.
176
+ The ceiling bounds concurrent range reads and upload parts in this budget,
177
+ not metadata requests, single-request writes, or other processes. Parallel
178
+ buffers are bounded by active streams times their chunk sizes. Cross-backend
179
+ copies spool the downloaded source to a temporary file before using the
180
+ destination's upload API. S3/Azure then upload concurrent parts; destinations
181
+ without a streaming upload implementation can still buffer the complete write.
182
+ Same-backend server-side copies are unchanged.
183
+ `floor=1` disables automatic range splitting and makes upload parts sequential.
177
184
  Explicit `chunk_size` requests retain sequential streaming when splitting
178
185
  would be inappropriate, and `chunk_size=0` disables streaming to local paths.
179
186
 
@@ -218,14 +225,24 @@ async with AsAnyPath("s3://bucket/huge.bin").open("wb") as f:
218
225
  await AsAnyPath("/data/movie.mp4").copy("s3://bucket/movie.mp4")
219
226
  ```
220
227
 
221
- Peak memory per upload is one part — **8 MiB by default**. Objects smaller than
222
- one part upload in a single request. (`write_bytes(data)` / `write_text(...)`
228
+ S3 multipart and Azure block uploads send **up to 8 parts concurrently by
229
+ default**, filling freed slots without waiting for a whole batch. Concurrent
230
+ files share the budget rather than each multiplying the target concurrency.
231
+ At the default 8 MiB part size, a single large upload buffers up to **64 MiB of
232
+ part payload**, plus file spooling, transport and runtime overhead. Native part
233
+ requests borrow immutable Python bytes instead of copying each buffer again.
234
+ Objects smaller than one part upload in a single request.
235
+ (`write_bytes(data)` / `write_text(...)`
223
236
  take the whole payload in memory by definition — use `open("wb")` or `copy()`
224
- for large data.)
237
+ for large data; direct `write_bytes()` remains a single write.)
225
238
 
226
- **Tuning the memory footprint.** The part size *is* the max RAM held per
227
- in-flight chunk (parts upload sequentially, so there is no concurrency
228
- multiplier). Set it globally via env, or per call:
239
+ **Tuning throughput and memory.** Buffered part payload scales with part size
240
+ times concurrent upload slots. A slot is reserved before reading its part,
241
+ so queued uploads do not allocate unbounded buffers. Tune concurrency with
242
+ `TransferBudget(floor=..., ceiling=..., per_file_cap=...)`, or CLI
243
+ `--concurrency-floor` (also used by `cp`, `mv`, and `sync`). To limit a batch
244
+ to one in-flight part/range, use `TransferBudget(floor=1, ceiling=1)`.
245
+ Set part size globally via env, or per call:
229
246
 
230
247
  ```bash
231
248
  export ASANYPATH_UPLOAD_CHUNK_SIZE=33554432 # 32 MiB parts (bytes)
@@ -244,11 +261,59 @@ Bigger parts mean fewer requests and a larger single-object ceiling (S3 allows
244
261
  applied automatically: **S3** clamps to ≥ 5 MiB parts, **GCS** rounds down to a
245
262
  256 KiB multiple.
246
263
 
264
+ On S3 failure or cancellation, in-flight workers are cancelled and joined
265
+ before aborting the multipart upload; completion lists remain in source order.
266
+ Azure only commits the ordered block list after all stages succeed; abandoned
267
+ uncommitted blocks are left for Azure's automatic expiry.
268
+
247
269
  Unknown URI schemes now construct as `UnsupportedProtocolPath` placeholders.
248
270
  Pure path operations (e.g. `.name`, `.parent`, joins) still work, while backend
249
271
  operations (e.g. `.exists()`, `.read_bytes()`, `.open()`) raise
250
272
  `UnsupportedProtocolError` on use.
251
273
 
274
+ ### Credentials and derived paths
275
+
276
+ Credentials and endpoints passed to a constructor belong to that path and to
277
+ paths derived from it (`/`, `parent`, `with_name`, `with_segments`, listing
278
+ children). Independently constructed paths resolve their own credentials from
279
+ the environment, the keyring, or the backend's usual configuration:
280
+
281
+ ```python
282
+ from asanypath.s3 import S3Path
283
+
284
+ p = S3Path("s3://bucket/data", endpoint_url="https://minio.local", aws_access_key_id="...",
285
+ aws_secret_access_key="...")
286
+ child = p / "part-0.parquet" # same endpoint and credentials
287
+ other = S3Path("s3://bucket/data") # default AWS configuration
288
+ ```
289
+
290
+ For backends whose credentials authenticate against the host in the URL
291
+ (Artifactory, SSH, FTP), explicit credentials never follow a derived path to a
292
+ different host. Listing results are only yielded when they name a direct child
293
+ of the listed path.
294
+
295
+ Ambient (environment) credentials belong to one configured service and are only
296
+ sent to that service's origin (scheme, host and port). Without a configured
297
+ service they are not sent at all, and a warning names the missing setting:
298
+
299
+ - **HTTP(S):** `HTTP_AUTH_USER`/`HTTP_AUTH_PASSWORD` or `HTTP_AUTH_TOKEN`
300
+ (with optional `HTTP_AUTH_HEADER`) are only used for URLs on the origin of
301
+ `HTTP_AUTH_URL`, e.g. `HTTP_AUTH_URL=https://files.example.com`. On a
302
+ redirect to another scheme, host or port, only non-credential headers
303
+ (`Range`, `Accept`, conditional headers, ...) are forwarded.
304
+ - **Artifactory:** `ARTIFACTORY_IDENTITY_TOKEN` is only used for the service in
305
+ `ARTIFACTORY_BASE_URL` (or `ART_BASE_URL`). A JFrog CLI server token is only
306
+ used for that server's own origin.
307
+ - **SSH:** host keys are checked like OpenSSH. `StrictHostKeyChecking`
308
+ (`yes`, `ask`, `accept-new`, `no`) and `UserKnownHostsFile` are read from
309
+ ssh_config; the default is `ask` against `~/.ssh/known_hosts`. Interactive
310
+ sessions are prompted for a host with no recorded key; non-interactive ones
311
+ refuse it. A changed key is refused, and with `StrictHostKeyChecking no`
312
+ password authentication is disabled for it. Pass `known_hosts=()` (or set
313
+ `SSH_KNOWN_HOSTS=none`) to disable checking.
314
+ - **Azure `presign()`** signs a blob-scoped SAS with the account key; a
315
+ configured SAS token is never handed out as a presigned URL.
316
+
252
317
  ### Download caching (opt-in)
253
318
 
254
319
  Reading the same object or URL twice always re-downloads it — there is **no
@@ -296,9 +361,16 @@ Behaviour and trade-offs:
296
361
  payloads; SQLite metadata and transaction journals add filesystem overhead.
297
362
  Objects larger than the budget are returned without being cached.
298
363
  - **Byte-only native storage:** SQLite stores raw bytes, never Python pickles.
299
- The database lives under `native-v1/` in the configured cache directory.
364
+ The database lives under `native-v1/` in the configured cache directory,
365
+ readable only by its owner (directory `0700`, files `0600` on POSIX).
300
366
  Legacy DiskCache files are ignored, not migrated or deleted. Multiple
301
- processes can share the new store; use the same size limit across them.
367
+ processes of the same user can share the new store; use the same size limit
368
+ across them.
369
+ - **Scoped to credentials.** Entries are keyed by URL plus a hash of the
370
+ path's credentials and endpoint, so different identities never share an
371
+ entry. Credentials themselves are never written to the cache. A cached entry
372
+ is not revalidated, so revoking an identity's access upstream does not evict
373
+ what it already cached.
302
374
  - **Staleness is on you.** Entries are keyed by URL with no revalidation — a
303
375
  cached object that changes upstream is served stale until it expires (`ttl`)
304
376
  or is evicted. Prefer caching immutable/versioned objects, or set a `ttl`.
@@ -510,6 +582,22 @@ uv run --extra bench python scripts/bench.py --backend all --rounds 3 --objects
510
582
  uv run --extra bench python scripts/bench.py --backend art --rounds 3 --concurrency-levels 1,10,50
511
583
  ```
512
584
 
585
+ For multipart upload throughput, use `scripts/bench_upload.py` with real shard
586
+ files and an explicitly selected S3-compatible endpoint:
587
+
588
+ ```bash
589
+ uv run --extra bench python scripts/bench_upload.py \
590
+ --destination s3://my-bucket/bench --endpoint-url https://my-storage-endpoint \
591
+ --part-mib 8 --streams 1 8 --rounds 3 /data/shard-001 /data/shard-002
592
+ ```
593
+
594
+ This compares asanypath and boto3 using one shared request budget per client.
595
+ It warms up each case, reports JSON timings and MiB/s, verifies uploaded contents
596
+ outside the timed interval, and deletes only the uniquely named benchmark
597
+ objects it created. Both clients use normal AWS credentials (or `--profile`).
598
+ Run with one large shard and again with several representative shards; results
599
+ from a local test server are not evidence of production endpoint throughput.
600
+
513
601
  ### S3 — live S3-compatible service (median of 20 rounds, 10 objects, c=1)
514
602
 
515
603
  | Operation | asanypath | s3fs | aiobotocore | cloudpathlib |
@@ -102,7 +102,9 @@ shared reader for local downloads and source reads in cross-backend copies.
102
102
  FTP/FTPS, sources without size metadata, and HTTP servers without advertised
103
103
  range support retain single-stream downloads. Local-only copies and native
104
104
  server-side copy/rename operations retain their existing implementations.
105
- Uploads remain single writes; this does not introduce multipart uploads.
105
+ Large S3/Azure uploads also use concurrent parts within this shared budget.
106
+ GCS resumable sessions remain sequential because the protocol requires ordered
107
+ offsets.
106
108
 
107
109
  Concurrent library copies share a default budget within the event loop. To
108
110
  configure a batch explicitly:
@@ -115,10 +117,14 @@ with TransferBudget(floor=8, ceiling=32, min_range_size=8 * 1024 * 1024, per_fil
115
117
  await asyncio.gather(*(src.copy(dst) for src, dst in pairs))
116
118
  ```
117
119
 
118
- The ceiling bounds concurrent reads in this budget, not metadata requests or
119
- other processes. Parallel range buffers are bounded by the active streams
120
- times the range size; cross-backend destinations still buffer the complete
121
- object for their existing write API. `floor=1` disables automatic splitting.
120
+ The ceiling bounds concurrent range reads and upload parts in this budget,
121
+ not metadata requests, single-request writes, or other processes. Parallel
122
+ buffers are bounded by active streams times their chunk sizes. Cross-backend
123
+ copies spool the downloaded source to a temporary file before using the
124
+ destination's upload API. S3/Azure then upload concurrent parts; destinations
125
+ without a streaming upload implementation can still buffer the complete write.
126
+ Same-backend server-side copies are unchanged.
127
+ `floor=1` disables automatic range splitting and makes upload parts sequential.
122
128
  Explicit `chunk_size` requests retain sequential streaming when splitting
123
129
  would be inappropriate, and `chunk_size=0` disables streaming to local paths.
124
130
 
@@ -163,14 +169,24 @@ async with AsAnyPath("s3://bucket/huge.bin").open("wb") as f:
163
169
  await AsAnyPath("/data/movie.mp4").copy("s3://bucket/movie.mp4")
164
170
  ```
165
171
 
166
- Peak memory per upload is one part — **8 MiB by default**. Objects smaller than
167
- one part upload in a single request. (`write_bytes(data)` / `write_text(...)`
172
+ S3 multipart and Azure block uploads send **up to 8 parts concurrently by
173
+ default**, filling freed slots without waiting for a whole batch. Concurrent
174
+ files share the budget rather than each multiplying the target concurrency.
175
+ At the default 8 MiB part size, a single large upload buffers up to **64 MiB of
176
+ part payload**, plus file spooling, transport and runtime overhead. Native part
177
+ requests borrow immutable Python bytes instead of copying each buffer again.
178
+ Objects smaller than one part upload in a single request.
179
+ (`write_bytes(data)` / `write_text(...)`
168
180
  take the whole payload in memory by definition — use `open("wb")` or `copy()`
169
- for large data.)
181
+ for large data; direct `write_bytes()` remains a single write.)
170
182
 
171
- **Tuning the memory footprint.** The part size *is* the max RAM held per
172
- in-flight chunk (parts upload sequentially, so there is no concurrency
173
- multiplier). Set it globally via env, or per call:
183
+ **Tuning throughput and memory.** Buffered part payload scales with part size
184
+ times concurrent upload slots. A slot is reserved before reading its part,
185
+ so queued uploads do not allocate unbounded buffers. Tune concurrency with
186
+ `TransferBudget(floor=..., ceiling=..., per_file_cap=...)`, or CLI
187
+ `--concurrency-floor` (also used by `cp`, `mv`, and `sync`). To limit a batch
188
+ to one in-flight part/range, use `TransferBudget(floor=1, ceiling=1)`.
189
+ Set part size globally via env, or per call:
174
190
 
175
191
  ```bash
176
192
  export ASANYPATH_UPLOAD_CHUNK_SIZE=33554432 # 32 MiB parts (bytes)
@@ -189,11 +205,59 @@ Bigger parts mean fewer requests and a larger single-object ceiling (S3 allows
189
205
  applied automatically: **S3** clamps to ≥ 5 MiB parts, **GCS** rounds down to a
190
206
  256 KiB multiple.
191
207
 
208
+ On S3 failure or cancellation, in-flight workers are cancelled and joined
209
+ before aborting the multipart upload; completion lists remain in source order.
210
+ Azure only commits the ordered block list after all stages succeed; abandoned
211
+ uncommitted blocks are left for Azure's automatic expiry.
212
+
192
213
  Unknown URI schemes now construct as `UnsupportedProtocolPath` placeholders.
193
214
  Pure path operations (e.g. `.name`, `.parent`, joins) still work, while backend
194
215
  operations (e.g. `.exists()`, `.read_bytes()`, `.open()`) raise
195
216
  `UnsupportedProtocolError` on use.
196
217
 
218
+ ### Credentials and derived paths
219
+
220
+ Credentials and endpoints passed to a constructor belong to that path and to
221
+ paths derived from it (`/`, `parent`, `with_name`, `with_segments`, listing
222
+ children). Independently constructed paths resolve their own credentials from
223
+ the environment, the keyring, or the backend's usual configuration:
224
+
225
+ ```python
226
+ from asanypath.s3 import S3Path
227
+
228
+ p = S3Path("s3://bucket/data", endpoint_url="https://minio.local", aws_access_key_id="...",
229
+ aws_secret_access_key="...")
230
+ child = p / "part-0.parquet" # same endpoint and credentials
231
+ other = S3Path("s3://bucket/data") # default AWS configuration
232
+ ```
233
+
234
+ For backends whose credentials authenticate against the host in the URL
235
+ (Artifactory, SSH, FTP), explicit credentials never follow a derived path to a
236
+ different host. Listing results are only yielded when they name a direct child
237
+ of the listed path.
238
+
239
+ Ambient (environment) credentials belong to one configured service and are only
240
+ sent to that service's origin (scheme, host and port). Without a configured
241
+ service they are not sent at all, and a warning names the missing setting:
242
+
243
+ - **HTTP(S):** `HTTP_AUTH_USER`/`HTTP_AUTH_PASSWORD` or `HTTP_AUTH_TOKEN`
244
+ (with optional `HTTP_AUTH_HEADER`) are only used for URLs on the origin of
245
+ `HTTP_AUTH_URL`, e.g. `HTTP_AUTH_URL=https://files.example.com`. On a
246
+ redirect to another scheme, host or port, only non-credential headers
247
+ (`Range`, `Accept`, conditional headers, ...) are forwarded.
248
+ - **Artifactory:** `ARTIFACTORY_IDENTITY_TOKEN` is only used for the service in
249
+ `ARTIFACTORY_BASE_URL` (or `ART_BASE_URL`). A JFrog CLI server token is only
250
+ used for that server's own origin.
251
+ - **SSH:** host keys are checked like OpenSSH. `StrictHostKeyChecking`
252
+ (`yes`, `ask`, `accept-new`, `no`) and `UserKnownHostsFile` are read from
253
+ ssh_config; the default is `ask` against `~/.ssh/known_hosts`. Interactive
254
+ sessions are prompted for a host with no recorded key; non-interactive ones
255
+ refuse it. A changed key is refused, and with `StrictHostKeyChecking no`
256
+ password authentication is disabled for it. Pass `known_hosts=()` (or set
257
+ `SSH_KNOWN_HOSTS=none`) to disable checking.
258
+ - **Azure `presign()`** signs a blob-scoped SAS with the account key; a
259
+ configured SAS token is never handed out as a presigned URL.
260
+
197
261
  ### Download caching (opt-in)
198
262
 
199
263
  Reading the same object or URL twice always re-downloads it — there is **no
@@ -241,9 +305,16 @@ Behaviour and trade-offs:
241
305
  payloads; SQLite metadata and transaction journals add filesystem overhead.
242
306
  Objects larger than the budget are returned without being cached.
243
307
  - **Byte-only native storage:** SQLite stores raw bytes, never Python pickles.
244
- The database lives under `native-v1/` in the configured cache directory.
308
+ The database lives under `native-v1/` in the configured cache directory,
309
+ readable only by its owner (directory `0700`, files `0600` on POSIX).
245
310
  Legacy DiskCache files are ignored, not migrated or deleted. Multiple
246
- processes can share the new store; use the same size limit across them.
311
+ processes of the same user can share the new store; use the same size limit
312
+ across them.
313
+ - **Scoped to credentials.** Entries are keyed by URL plus a hash of the
314
+ path's credentials and endpoint, so different identities never share an
315
+ entry. Credentials themselves are never written to the cache. A cached entry
316
+ is not revalidated, so revoking an identity's access upstream does not evict
317
+ what it already cached.
247
318
  - **Staleness is on you.** Entries are keyed by URL with no revalidation — a
248
319
  cached object that changes upstream is served stale until it expires (`ttl`)
249
320
  or is evicted. Prefer caching immutable/versioned objects, or set a `ttl`.
@@ -455,6 +526,22 @@ uv run --extra bench python scripts/bench.py --backend all --rounds 3 --objects
455
526
  uv run --extra bench python scripts/bench.py --backend art --rounds 3 --concurrency-levels 1,10,50
456
527
  ```
457
528
 
529
+ For multipart upload throughput, use `scripts/bench_upload.py` with real shard
530
+ files and an explicitly selected S3-compatible endpoint:
531
+
532
+ ```bash
533
+ uv run --extra bench python scripts/bench_upload.py \
534
+ --destination s3://my-bucket/bench --endpoint-url https://my-storage-endpoint \
535
+ --part-mib 8 --streams 1 8 --rounds 3 /data/shard-001 /data/shard-002
536
+ ```
537
+
538
+ This compares asanypath and boto3 using one shared request budget per client.
539
+ It warms up each case, reports JSON timings and MiB/s, verifies uploaded contents
540
+ outside the timed interval, and deletes only the uniquely named benchmark
541
+ objects it created. Both clients use normal AWS credentials (or `--profile`).
542
+ Run with one large shard and again with several representative shards; results
543
+ from a local test server are not evidence of production endpoint throughput.
544
+
458
545
  ### S3 — live S3-compatible service (median of 20 rounds, 10 objects, c=1)
459
546
 
460
547
  | Operation | asanypath | s3fs | aiobotocore | cloudpathlib |
@@ -0,0 +1,18 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ Do not report suspected vulnerabilities in public issues or pull requests.
6
+ Report them privately through GitHub's private vulnerability reporting: open
7
+ the repository's **Security** tab and choose **Report a vulnerability**.
8
+ Include reproduction details, affected versions, and potential impact. Do not
9
+ include credentials, tokens, or customer data in the report.
10
+
11
+ Maintainers coordinate fixes through a GitHub security advisory and publish the
12
+ advisory together with the patched release.
13
+
14
+ ## Supported Versions
15
+
16
+ Security fixes are applied to the latest released version. The project may also
17
+ publish fixes for an earlier release when maintainers determine that it is
18
+ necessary and practical.
@@ -4,17 +4,23 @@
4
4
  # license that can be found in the LICENSE file or at
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
+ import re
8
+
7
9
  from hatchling.metadata.plugin.interface import MetadataHookInterface
8
10
 
9
11
 
10
12
  class PinNativeHook(MetadataHookInterface):
11
- """Provide dependencies, pinning asanypath-native to asanypath's minor version."""
13
+ """Provide dependencies, pinning asanypath-native to asanypath's release.
14
+
15
+ ``~=X.Y.Z`` requires at least the same patch release (fixes and APIs the
16
+ Python code relies on) while allowing later patches of the same minor.
17
+ """
12
18
 
13
19
  def update(self, metadata: dict) -> None:
14
- major, minor, *_ = metadata["version"].split(".")
20
+ major, minor, patch = re.match(r"(\d+)\.(\d+)\.(\d+)", metadata["version"]).groups()
15
21
  metadata["dependencies"] = [
16
22
  "anyio>=4",
17
- f"asanypath-native~={major}.{minor}.0",
23
+ f"asanypath-native~={major}.{minor}.{patch}",
18
24
  "msgspec>=0.22.0",
19
25
  "yarl>=1.2",
20
26
  ]
@@ -59,6 +59,7 @@ cli = ["rich-click>=1.9.7"]
59
59
  ftp = ["aioftp>=0.21"]
60
60
  credstore = ["keyring>=24"]
61
61
  bench = [
62
+ "boto3",
62
63
  "asyncssh>=2.14",
63
64
  "fsspec",
64
65
  "s3fs",
@@ -0,0 +1,181 @@
1
+ # Copyright (C) 2026 Axis Communications AB, Lund, Sweden
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+
7
+ """Compare bounded multipart uploads of real files to an explicitly chosen S3 prefix.
8
+
9
+ Uses normal AWS credential resolution; never reads repository credential files.
10
+ Each case warms up once, uploads to unique keys, verifies contents outside the
11
+ timed interval, and deletes only its own objects. Timings include public copy API
12
+ overhead for asanypath and upload_file API overhead for boto3.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import argparse
18
+ import asyncio
19
+ import hashlib
20
+ import json
21
+ import statistics
22
+ import time
23
+ from collections.abc import Awaitable, Iterable
24
+ from pathlib import Path
25
+ from uuid import uuid4
26
+
27
+ from asanypath import AsAnyPath, TransferBudget
28
+
29
+
30
+ async def finish_uploads(uploads: Iterable[Awaitable[object]]) -> None:
31
+ pending = asyncio.gather(*uploads, return_exceptions=True)
32
+ try:
33
+ results = await asyncio.shield(pending)
34
+ except asyncio.CancelledError:
35
+ await pending
36
+ raise
37
+ for result in results:
38
+ if isinstance(result, BaseException):
39
+ raise result
40
+
41
+
42
+ def positive(value: str) -> int:
43
+ result = int(value)
44
+ if result < 1:
45
+ raise argparse.ArgumentTypeError("must be positive")
46
+ return result
47
+
48
+
49
+ def digest(path: Path) -> bytes:
50
+ checksum = hashlib.sha256()
51
+ with path.open("rb") as file:
52
+ while chunk := file.read(8 * 1024 * 1024):
53
+ checksum.update(chunk)
54
+ return checksum.digest()
55
+
56
+
57
+ async def main() -> None:
58
+ parser = argparse.ArgumentParser(description=__doc__)
59
+ parser.add_argument("files", nargs="+", type=Path, help="Representative local shard files")
60
+ parser.add_argument("--destination", required=True, help="s3://bucket/benchmark-prefix")
61
+ parser.add_argument("--endpoint-url", help="The storage endpoint used by both clients")
62
+ parser.add_argument("--profile", help="AWS profile used by both clients")
63
+ parser.add_argument("--streams", nargs="+", type=positive, default=[1, 8])
64
+ parser.add_argument("--part-mib", type=positive, default=8)
65
+ parser.add_argument("--rounds", type=positive, default=3)
66
+ parser.add_argument(
67
+ "--implementations",
68
+ nargs="+",
69
+ choices=["asanypath", "boto3"],
70
+ default=["asanypath", "boto3"],
71
+ )
72
+ args = parser.parse_args()
73
+ if not args.destination.startswith("s3://") or not args.destination[5:].split("/")[0]:
74
+ parser.error("--destination must be an s3://bucket/prefix URI")
75
+ if args.part_mib < 5:
76
+ parser.error("--part-mib must be at least 5 for S3")
77
+ for file in args.files:
78
+ if not file.is_file():
79
+ parser.error(f"Not a file: {file}")
80
+ kwargs = {}
81
+ if args.endpoint_url:
82
+ kwargs["endpoint_url"] = args.endpoint_url
83
+ if args.profile:
84
+ kwargs["profile"] = args.profile
85
+ part_size = args.part_mib * 1024 * 1024
86
+ total = sum(file.stat().st_size for file in args.files)
87
+ expected = [digest(file) for file in args.files]
88
+ base = args.destination.rstrip("/") + "/asanypath-upload-bench-" + uuid4().hex
89
+ bucket = base[5:].split("/", 1)[0]
90
+
91
+ for streams in args.streams:
92
+ for implementation in args.implementations:
93
+ client = transfer = None
94
+ if implementation == "boto3":
95
+ import boto3
96
+ from boto3.s3.transfer import S3Transfer, TransferConfig
97
+ from botocore.config import Config
98
+
99
+ client = boto3.Session(profile_name=args.profile).client(
100
+ "s3",
101
+ endpoint_url=args.endpoint_url,
102
+ config=Config(max_pool_connections=max(10, streams)),
103
+ )
104
+ # One manager shares its request budget across all files.
105
+ transfer = S3Transfer(
106
+ client,
107
+ TransferConfig(
108
+ multipart_threshold=part_size,
109
+ multipart_chunksize=part_size,
110
+ max_concurrency=streams,
111
+ preferred_transfer_client="classic",
112
+ ),
113
+ )
114
+ samples = []
115
+ try:
116
+ for round_number in range(args.rounds + 1):
117
+ uris = [
118
+ f"{base}/{implementation}/{streams}/{round_number}/{index}"
119
+ for index in range(len(args.files))
120
+ ]
121
+ destinations = [AsAnyPath(uri, **kwargs) for uri in uris]
122
+ try:
123
+ start = time.perf_counter()
124
+ if implementation == "asanypath":
125
+ with TransferBudget(
126
+ floor=streams, ceiling=streams, per_file_cap=streams
127
+ ):
128
+ await finish_uploads(
129
+ (
130
+ AsAnyPath(file).copy(dst, chunk_size=part_size)
131
+ for file, dst in zip(args.files, destinations, strict=True)
132
+ )
133
+ )
134
+ else:
135
+ await finish_uploads(
136
+ (
137
+ asyncio.to_thread(
138
+ transfer.upload_file,
139
+ str(file),
140
+ bucket,
141
+ uri[5:].split("/", 1)[1],
142
+ )
143
+ for file, uri in zip(args.files, uris, strict=True)
144
+ )
145
+ )
146
+ elapsed = time.perf_counter() - start
147
+ for dst, checksum in zip(destinations, expected, strict=True):
148
+ actual = hashlib.sha256()
149
+ async for chunk in dst.iter_bytes(part_size):
150
+ actual.update(chunk)
151
+ if actual.digest() != checksum:
152
+ raise OSError(f"Uploaded content verification failed: {dst}")
153
+ if round_number:
154
+ samples.append(elapsed)
155
+ finally:
156
+ await asyncio.gather(*(dst.unlink(missing_ok=True) for dst in destinations))
157
+ median = statistics.median(samples)
158
+ print(
159
+ json.dumps(
160
+ {
161
+ "implementation": implementation,
162
+ "streams": streams,
163
+ "files": len(args.files),
164
+ "bytes": total,
165
+ "part_bytes": part_size,
166
+ "seconds": samples,
167
+ "median_seconds": median,
168
+ "median_mib_per_second": total / (1024 * 1024) / median,
169
+ }
170
+ ),
171
+ flush=True,
172
+ )
173
+ finally:
174
+ if transfer is not None:
175
+ await asyncio.to_thread(transfer.__exit__, None, None, None)
176
+ if client is not None:
177
+ client.close()
178
+
179
+
180
+ if __name__ == "__main__":
181
+ asyncio.run(main())
@@ -0,0 +1,22 @@
1
+ # Copyright (C) 2026 Axis Communications AB, Lund, Sweden
2
+ #
3
+ # Use of this source code is governed by an MIT-style
4
+ # license that can be found in the LICENSE file or at
5
+ # https://opensource.org/licenses/MIT.
6
+
7
+ """Whether backends may prompt the user on the terminal."""
8
+
9
+ from __future__ import annotations
10
+
11
+ import sys
12
+ from os import getenv
13
+
14
+
15
+ def interactive() -> bool:
16
+ """Whether a backend may prompt the user (credentials, host keys)."""
17
+ if getenv("ASANYPATH_INTERACTIVE") == "0":
18
+ return False
19
+ try:
20
+ return sys.stdin.isatty()
21
+ except (AttributeError, ValueError): # pragma: no cover
22
+ return False # pragma: no cover