Files
File operations and path translation utilities for DesignSafe storage systems.
Path Translation
Translate DesignSafe-style paths to Tapis URIs.
Converts commonly used DesignSafe path formats (e.g., /MyData/folder, /projects/PRJ-XXXX/folder) to their corresponding Tapis system URIs. Supports MyData, CommunityData, and project-specific paths with automatic system discovery for projects.
PARAMETER | DESCRIPTION |
---|---|
t
|
Authenticated Tapis client instance.
TYPE:
|
path
|
The DesignSafe-style path string to translate. Supported formats: - MyData paths: "/MyData/folder", "jupyter/MyData/folder" - Community paths: "/CommunityData/folder" - Project paths: "/projects/PRJ-XXXX/folder" - Direct Tapis URIs: "tapis://system-id/path"
TYPE:
|
verify_exists
|
If True, verifies the translated path exists on the target Tapis system. Defaults to False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The corresponding Tapis URI (e.g., "tapis://system-id/path").
TYPE:
|
RAISES | DESCRIPTION |
---|---|
FileOperationError
|
If path translation fails, project system lookup fails, or path verification fails (when verify_exists=True). |
AuthenticationError
|
If username is required for MyData paths but t.username is not available. |
ValueError
|
If the input path format is unrecognized, empty, or incomplete. |
Example
uri = get_ds_path_uri(client, "/MyData/analysis/results") Translated '/MyData/analysis/results' to 'tapis://designsafe.storage.default/username/analysis/results' using t.username
uri = get_ds_path_uri(client, "/projects/PRJ-1234/data", verify_exists=True) Searching Tapis systems for project ID 'PRJ-1234'... Found unique matching system: project-1234-abcd-ef01-2345-6789abcdef01 Verifying existence of translated path: tapis://project-1234-abcd-ef01-2345-6789abcdef01/data Verification successful: Path exists.
Source code in dapi/files.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
|
Convert a Tapis URI to the corresponding DesignSafe local path.
Converts Tapis system URIs back to their equivalent DesignSafe local paths that would be accessible in a Jupyter environment. This is the reverse operation of get_ds_path_uri().
PARAMETER | DESCRIPTION |
---|---|
tapis_uri
|
The Tapis URI to convert. Supported formats: - "tapis://designsafe.storage.default/username/path" -> "/home/jupyter/MyData/path" - "tapis://designsafe.storage.community/path" -> "/home/jupyter/CommunityData/path" - "tapis://project-*/path" -> "/home/jupyter/MyProjects/path"
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The corresponding DesignSafe local path, or the original URI if it's not a recognized Tapis URI format.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the Tapis URI format is invalid. |
Example
local_path = tapis_uri_to_local_path("tapis://designsafe.storage.default/user/data/file.txt") print(local_path) # "/home/jupyter/MyData/data/file.txt"
local_path = tapis_uri_to_local_path("tapis://designsafe.storage.community/datasets/earthquake.csv") print(local_path) # "/home/jupyter/CommunityData/datasets/earthquake.csv"
Source code in dapi/files.py
File Operations
Upload a local file to a Tapis storage system.
PARAMETER | DESCRIPTION |
---|---|
t
|
Authenticated Tapis client instance.
TYPE:
|
local_path
|
Path to the local file to upload.
TYPE:
|
remote_uri
|
Tapis URI destination (e.g., "tapis://system/path/file.txt").
TYPE:
|
RAISES | DESCRIPTION |
---|---|
FileNotFoundError
|
If the local file does not exist. |
ValueError
|
If local_path is not a file or remote_uri is invalid. |
FileOperationError
|
If the Tapis upload operation fails. |
Example
upload_file(client, "/local/data.txt", "tapis://mysystem/uploads/data.txt") Uploading '/local/data.txt' to system 'mysystem' at path 'uploads/data.txt'... Upload complete.
Source code in dapi/files.py
Download a file from a Tapis storage system to local filesystem.
PARAMETER | DESCRIPTION |
---|---|
t
|
Authenticated Tapis client instance.
TYPE:
|
remote_uri
|
Tapis URI of the file to download (e.g., "tapis://system/path/file.txt").
TYPE:
|
local_path
|
Local filesystem path where the file should be saved.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If local_path is a directory or remote_uri is invalid. |
FileOperationError
|
If the download operation fails or remote file not found. |
Example
download_file(client, "tapis://mysystem/data/results.txt", "/local/results.txt") Downloading from system 'mysystem' path 'data/results.txt' to '/local/results.txt'... Download complete.
Source code in dapi/files.py
List files and directories in a Tapis storage system path.
PARAMETER | DESCRIPTION |
---|---|
t
|
Authenticated Tapis client instance.
TYPE:
|
remote_uri
|
Tapis URI of the directory to list (e.g., "tapis://system/path/").
TYPE:
|
limit
|
Maximum number of items to return. Defaults to 100.
TYPE:
|
offset
|
Number of items to skip (for pagination). Defaults to 0.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[Tapis]
|
List[Tapis]: List of file and directory objects from the specified path. |
List[Tapis]
|
Each object contains metadata like name, size, type, and permissions. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If remote_uri is invalid. |
FileOperationError
|
If the listing operation fails or path not found. |
Example
files = list_files(client, "tapis://mysystem/data/") Listing files in system 'mysystem' at path 'data/'... Found 5 items. for file in files: ... print(f"{file.name} ({file.type})")
Source code in dapi/files.py
Utility Functions
Parse a Tapis URI into system ID and path components.
PARAMETER | DESCRIPTION |
---|---|
tapis_uri
|
URI in the format 'tapis://system_id/path'.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
A tuple containing (system_id, path).
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the URI format is invalid or missing required components. |
Example
system_id, path = _parse_tapis_uri("tapis://mysystem/folder/file.txt") print(system_id) # "mysystem" print(path) # "folder/file.txt"