AsyncFileSystem
and SyncFileSystem
. Both classes enable you to download files uploaded by the user and to upload files created during flow execution. Files and folders uploaded by the user are located in a root folder /in
(input files). Files and folders created during flow execution which will be delivered back to the user are located in a root folder /out
(output files).
Overview
AsyncFileSystem vs SyncFileSystem
Feature | AsyncFileSystem | SyncFileSystem |
---|---|---|
Usage | Asynchronous functions (async def ) | Synchronous functions |
Performance | Non-blocking, better I/O performance | Blocking, easier to use |
Ray Remote Functions | Not compatible | Compatible |
Context Manager | async with | with |
AsyncFileSystem and SyncFileSystem Classes
Basic Structure
Both classes share the same interface but differ in implementation. As a developer of agentic services you access both classes through theTracer
object:
SyncFileSystem
if you pass the tracer
object to a Ray remote function. This constraint is due to the fact that Ray remote functions do not support async execution.
Working with Context Managers
BothAsyncFileSystem
and SyncFileSystem
support context managers for automatic resource cleanup:
AsyncFileSystem Context Manager
SyncFileSystem Context Manager
Listing Files and Folders
Use thels()
method to list files and subfolders in the input or output directories:
AsyncFileSystem
SyncFileSystem
Downloading Files and Folders
Thedownload()
method allows you to download files uploaded by the user to a local temporary directory:
AsyncFileSystem
SyncFileSystem
Uploading Files and Folders
Theupload()
method allows you to upload files created during service execution to the output directory:
AsyncFileSystem
SyncFileSystem
Opening and Reading Files
Use theopen()
method to create file streams for reading files. The streams support both read_all()
and read()
methods:
AsyncFileSystem
SyncFileSystem
Removing Files and Folders
Use theremove()
method to delete files and folders:
AsyncFileSystem
SyncFileSystem
Complete Example
Here’s a complete example showing how to use the file management API in a typical workflow:Error Handling
The file management API raises appropriate exceptions for common error conditions:FileNotFoundError
: When trying to access a file or folder that doesn’t existRuntimeError
: When trying to use a closed stream or re-enter a stream context- HTTP exceptions: For network-related errors during file operations
- Continue with complete upload/download example