Skip to main content
The R2 resource mounts a Cloudflare R2 bucket at some prefix such as /r2/. All operations involve network I/O to the remote object store. Uses aioboto3 against R2’s S3-compatible API. For credential setup, see R2 Setup.

Config

R2Resource(config) takes an R2Config object with the bucket name and either account_id (endpoint is auto-built as https://{account_id}.r2.cloudflarestorage.com) or an explicit endpoint_url. Both READ and WRITE modes are supported.

Filesystem Layout

The R2 resource maps object keys to virtual paths under the mount prefix. R2 “directories” are prefix-based — there are no real directory objects. For example, if bucket my-bucket contains:
Then mounting at /r2/ exposes:
Path mapping: virtual /r2/assets/logo.png maps to R2 key assets/logo.png.

Cache

The R2 resource uses IndexCacheStore with index_ttl = 600 (10 minutes). Directory listings are cached for up to 600 seconds before being refreshed from R2. This reduces API calls for repeated directory traversals.

Example

Shell Commands

The R2 resource supports the full set of shell commands since it operates on real file content (text, binary, JSON, CSV, etc.). Large files benefit from range reads to avoid downloading entire objects.

Read Commands

Text Processing

File Operations

Path Utilities

Compression

Encoding

Data Format Support

Commands with format-specific variants for structured data files: These variants auto-detect the format by extension and convert to tabular text (CSV) for processing.

Use Cases

  • AI agents accessing R2 data: Mount R2 buckets for agents to read and process datasets
  • Data pipelines: Read and write R2 objects with shell-like commands
  • FUSE mounting: Expose R2 buckets through a virtual FUSE mount for external tools