|
| 1 | +# Files |
| 2 | + |
| 3 | +## Path translation |
| 4 | + |
| 5 | +DesignSafe uses Tapis URIs internally (`tapis://system-id/path`). Most users work with familiar paths like `/MyData/folder/` — dapi translates between the two. |
| 6 | + |
| 7 | +```python |
| 8 | +from dapi import DSClient |
| 9 | +ds = DSClient() |
| 10 | + |
| 11 | +# MyData → includes your username automatically |
| 12 | +ds.files.to_uri("/MyData/analysis/input/") |
| 13 | +# tapis://designsafe.storage.default/<username>/analysis/input/ |
| 14 | + |
| 15 | +# Community data |
| 16 | +ds.files.to_uri("/CommunityData/some-dataset/") |
| 17 | +# tapis://designsafe.storage.community/some-dataset/ |
| 18 | + |
| 19 | +# Projects — looks up the Tapis system ID from the project number |
| 20 | +ds.files.to_uri("/projects/PRJ-1234/data/") |
| 21 | +# tapis://project-xxxx-xxxx-xxxx/data/ |
| 22 | + |
| 23 | +# Already a Tapis URI — passed through unchanged |
| 24 | +ds.files.to_uri("tapis://designsafe.storage.default/<username>/folder/") |
| 25 | +``` |
| 26 | + |
| 27 | +Verify a path exists before using it: |
| 28 | + |
| 29 | +```python |
| 30 | +ds.files.to_uri("/MyData/analysis/input/", verify_exists=True) |
| 31 | +``` |
| 32 | + |
| 33 | +Reverse translation (URI back to Jupyter path): |
| 34 | + |
| 35 | +```python |
| 36 | +ds.files.to_path("tapis://designsafe.storage.default/<username>/data/file.txt") |
| 37 | +# /home/jupyter/MyData/data/file.txt |
| 38 | + |
| 39 | +ds.files.to_path("tapis://designsafe.storage.community/datasets/eq.csv") |
| 40 | +# /home/jupyter/CommunityData/datasets/eq.csv |
| 41 | +``` |
| 42 | + |
| 43 | +### Supported path formats |
| 44 | + |
| 45 | +| Input path | Tapis system | |
| 46 | +|---|---| |
| 47 | +| `/MyData/...` | `designsafe.storage.default/<username>/...` | |
| 48 | +| `/home/jupyter/MyData/...` | `designsafe.storage.default/<username>/...` | |
| 49 | +| `jupyter/MyData/...` | `designsafe.storage.default/<username>/...` | |
| 50 | +| `/CommunityData/...` | `designsafe.storage.community/...` | |
| 51 | +| `/projects/PRJ-XXXX/...` | `project-<uuid>/...` (auto-discovered) | |
| 52 | +| `tapis://...` | passed through unchanged | |
| 53 | + |
| 54 | +## List files |
| 55 | + |
| 56 | +```python |
| 57 | +files = ds.files.list("tapis://designsafe.storage.default/<username>/analysis/") |
| 58 | +for f in files: |
| 59 | + print(f"{f.name} ({f.type}, {f.size} bytes)") |
| 60 | +``` |
| 61 | + |
| 62 | +Pagination: |
| 63 | + |
| 64 | +```python |
| 65 | +# Get items 100-199 |
| 66 | +files = ds.files.list(uri, limit=100, offset=100) |
| 67 | +``` |
| 68 | + |
| 69 | +## Upload |
| 70 | + |
| 71 | +```python |
| 72 | +ds.files.upload( |
| 73 | + "/local/path/input.json", |
| 74 | + "tapis://designsafe.storage.default/<username>/analysis/input.json", |
| 75 | +) |
| 76 | +``` |
| 77 | + |
| 78 | +The local file must exist and be a regular file (not a directory). Parent directories are created on the remote system. |
| 79 | + |
| 80 | +## Download |
| 81 | + |
| 82 | +```python |
| 83 | +ds.files.download( |
| 84 | + "tapis://designsafe.storage.default/<username>/results/output.csv", |
| 85 | + "/local/path/output.csv", |
| 86 | +) |
| 87 | +``` |
| 88 | + |
| 89 | +Local parent directories are created automatically. The local path must be a file path, not a directory. |
0 commit comments