Skip to main content
The Opus SDK lets you work with files from inside an Opus Code task—download files from Opus storage, create new files, upload files back to storage, and more. Aside from the Opus SDK, you can use a wide range of Python packages; the full list is available in Available Packages.

Setup

Inside an Opus Code task, Opus is already defined and ready to use.

File Operations

All file operations are accessed via Opus.file.

Downloading a File

Use Opus.file.download(file_url) to fetch a file from Opus storage by its URL:
This returns an OpusFile object.
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

Use Opus.file.presigned_download(file_url, expiry=None) to get a presigned URL for downloading a file without fetching it locally:
You can optionally set a custom expiry (in seconds, between 60 and 86400):
If no expiry is provided, the server default is used.
The expiry must be between 60 seconds (1 minute) and 86400 seconds (24 hours). Values outside this range raise InvalidFileExpiryError.

Creating a File

Use Opus.file.create(file_name, file_type) to create a new empty file:
The first argument is the file name (without extension), the second is the file type. The extension is added automatically based on the type. This returns an OpusFile object.
If the file isn’t uploaded via Opus.file.upload, the created file won’t be persisted.
Creating a file with a name that already exists in the current session raises FileAlreadyExistsError.

Supported File Types

Pass any of these as the file_type argument: The type is case-insensitive: "pdf", "PDF", and "Pdf" all work.

Uploading a File

Use Opus.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:
Writing:
Download, modify, and re-upload:
Create a CSV from scratch:
Create a JSON file:
Process a downloaded file line by line:

Working with File Formats

For format-specific helpers and patterns, check the dedicated guide: Working with File Formats.

Errors

All SDK exceptions inherit from OpusError and are available via Opus.errors:

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.