Setup
Inside an Opus Code task,Opus is already defined and ready to use.
File Operations
All file operations are accessed viaOpus.file.
Downloading a File
UseOpus.file.download(file_url) to fetch a file from Opus storage by its URL:
Modifications to downloaded files are local only unless uploaded via
Opus.file.upload, which creates a new file and returns a new URL; the original remote file is never modified.Getting a Presigned Download URL
UseOpus.file.presigned_download(file_url, expiry=None) to get a presigned URL for downloading a file without fetching it locally:
If no
expiry is provided, the server default is used.Creating a File
UseOpus.file.create(file_name, file_type) to create a new empty file:
If the file isn’t uploaded via
Opus.file.upload, the created file won’t be persisted.Supported File Types
Pass any of these as thefile_type argument:
The type is case-insensitive:
"pdf", "PDF", and "Pdf" all work.
Uploading a File
UseOpus.file.upload(file, access_scope="all") to upload an OpusFile to Opus storage.
The
access_scope parameter is optional and defaults to "all".Code Playground: In the code playground, the
access_scope is always "unlisted" regardless of the value provided.You can upload the same file multiple times. Each upload returns a new URL.
Supported Access Scopes
The scope is case-insensitive:
"Workspace", "WORKSPACE", and "WorkSpace" all work.
OpusFile Interface
OpusFile is the object returned by download() and create(). Its attributes are read-only.
Properties
Operations
Examples
Reading:Working with File Formats
For format-specific helpers and patterns, check the dedicated guide: Working with File Formats.Errors
All SDK exceptions inherit fromOpusError and are available via Opus.errors:
Related
Available Packages
Browse the full list of Python packages you can import in Opus Code.
Working with File Formats
Format-specific helpers for reading and writing PDFs, spreadsheets, and more.
Opus Code
Write custom Python code directly in your workflow.