Manage drives and defaults
These examples use the latest stable release of the Python SDK.
Each workspace has one or more drives, and one of them is the workspace default. client.drives creates and lists drives and changes the default; client.sandbox_tokens gives a cloud sandbox or job access to one drive. To create drives or change the default, use an API key with Read / Write permission.
Create a drive
from flashdrive import Flashdrive
with Flashdrive() as client:
drive = client.drives.create("Research", idempotency_key="create-research-1")
print(drive.id, drive.status)
drives.create(name, *, idempotency_key=None, timeout=30) returns a Drive. Names are trimmed and must have 1 to 120 characters. Reuse the same idempotency_key and name to retry a creation whose reply was lost.
A new drive can still be preparing when create() returns. Read client.drives.get(drive.id).status until it is ready; the other statuses are provisioning and failed. Creating a drive does not change the workspace default.
List and read drives
| Call | Result |
|---|---|
drives.list() | A list of Drive objects. |
drives.list(deleted=True) | A list of DeletedDrive objects, with id, name, version, deleted_at and recoverable_until. |
drives.get(drive_id) | A Drive with its current status and document_count. |
drives.usage(drive_id=None) | A DriveUsage with document_count, source_bytes, deleted_document_count, deleted_source_bytes and stored_bytes. Default: the client's drive. |
drives.get_default() | A DefaultDrive with default_drive_id, version and etag. |
drives.set_default(drive_id) | The new DefaultDrive. |
A Drive has id, name, version, status, document_count, etag and full_text. Unknown status values arrive as plain strings, so include a fallback when you match on them. Every response object keeps the service's full JSON in raw.
Choose where calls run
A call's drive_id comes first, then the drive_id you gave the client, then the workspace default:
with Flashdrive(drive_id="DRIVE_UUID") as client:
client.upload("notes.md") # DRIVE_UUID
client.upload("notes.md", drive_id="OTHER_UUID") # OTHER_UUID
The default is read once per call and stays fixed through that call's retries and polling. An explicit drive that does not exist raises an error; it never falls back to the default.
The workspace default is shared with everyone in the workspace, so set_default() changes where their calls go too:
with Flashdrive() as client:
client.drives.set_default("DRIVE_UUID")
print(client.drives.get_default().default_drive_id)
Grep is on for every drive
Keyword and pattern search is on for every drive, including each new one, and there is no setting to turn it off. A Drive's full_text attribute shows it.
If files.grep raises a ConflictError with code full_text_search_off, search is unavailable for that drive: contact support with the error's request_id. Listing, globbing, reading and editing files still work. See find, read and edit files.
Delete a drive
with Flashdrive() as client:
client.drives.delete("DRIVE_UUID", idempotency_key="delete-old-drive-1")
drives.delete(drive_id) reads the drive's current version and deletes it only if nothing changed in between. It returns None. The service refuses:
| Code | Meaning |
|---|---|
default_drive_in_use | The drive is the workspace default. Choose another default first. |
drive_not_empty | The drive still holds files or folders, or has work in progress. Remove them first. |
stale_version | The drive changed since it was read. Read it again before retrying. |
Restore a deleted drive
with Flashdrive() as client:
for gone in client.drives.list(deleted=True):
print(gone.id, gone.name, gone.recoverable_until)
record = client.drives.deletion("DRIVE_UUID")
drive = client.drives.restore("DRIVE_UUID", idempotency_key="restore-old-drive-1")
A deleted drive can be restored until its recoverable_until. drives.deletion(drive_id) reads the deletion record without restoring anything, and drives.restore(drive_id) brings the drive back and returns it as a Drive.
Read a drive's usage
drives.usage() reports how many files and bytes a drive holds, live and in the trash. A deleted file stays in the trash for one hour; until then it counts in the deleted_ fields and in stored_bytes, which is what counts towards the drive's size limit. A drive without usage reporting answers not_supported_on_this_drive.
Follow changes
client.drives.changes() lists what changed in a drive since a cursor. See follow changes for the full workflow.
Give a sandbox one drive
client.sandbox_tokens makes short-lived tokens for cloud sandboxes, containers and GPU jobs: one drive, optionally one folder and its subfolders, read or read_write, for 5 minutes to 12 hours (300 to 43,200 seconds, default 3,600).
with Flashdrive() as client:
made = client.sandbox_tokens.create(access="read", folder_id="FOLDER_UUID",
ttl_seconds=3600, name="render-job")
secret = made["token"] # shown once: hand it straight to the sandbox's secret store
client.sandbox_tokens.extend(made["id"], ttl_seconds=7200)
live = client.sandbox_tokens.list(state="live")
client.sandbox_tokens.revoke(made["id"])
| Call | Result |
|---|---|
sandbox_tokens.create(access=, drive_id=None, folder_id=None, ttl_seconds=None, name=None) | A dictionary with id, name, display_prefix, workspace_id, drive_id, folder_id, access, minted_by, created_at, expires_at, revoked_at, state and, once, token. It is never retried, so a lost reply does not make a second token. name is up to 120 characters. |
sandbox_tokens.list(drive_id=None, state="live", limit=None, cursor=None) | A page (data, next_cursor) of tokens without their secrets, newest first. state="recent" adds tokens that ended in the last 30 days. Workspace admins see every token, others the ones they made. |
sandbox_tokens.extend(token_id, ttl_seconds=None) | The token, with its expiry moved to now plus ttl_seconds (default one hour). The token itself does not change, so work in flight keeps going. |
sandbox_tokens.revoke(token_id) | The token, revoked; new requests are refused within 60 seconds. Repeating is harmless. |
Never print or log the token. Inside the sandbox, the SDK reads it from FLASHDRIVE_API_KEY, ideally injected by the sandbox's network proxy rather than placed on a command line. With a folder token, pass folder_id to client.upload(...). A sandbox token cannot make, list, extend or revoke tokens, and cannot make file links, so files.link, files.read_bytes and files.download are not available to it. See give a sandbox one drive for what a token can do and how to pass it to common sandboxes.