Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/assets/cloudflare-r2-bucket-info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/cloudflare-r2-credentials.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions docs/examples/r2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Cloudflare R2

[Cloudflare R2](https://www.cloudflare.com/developer-platform/products/r2/) is Cloudflare's object storage solution, designed to be compatible with the S3 API. Some developers may choose to use Cloudflare R2 because it has no egress fees.

It's easy to read and write data to and from Cloudflare R2 with obstore's [`S3Store`][obstore.store.S3Store] with three steps:

1. [Create an API token](https://dash.cloudflare.com/?to=/:account/r2/api-tokens) with read or read/write access to one or more buckets.

Copy the `Access Key ID` and `Secret Access Key` to use in your code.

![](../assets/cloudflare-r2-credentials.jpg)

2. On the general settings of a bucket, take note of the `S3 API` URL. In my case it's `https://f0b62eebfbdde1133378bfe3958325f6.r2.cloudflarestorage.com/kylebarron-public`.

![](../assets/cloudflare-r2-bucket-info.png)

3. Pass this information to [`S3Store.from_url`][obstore.store.S3Store.from_url]:

```py
from obstore.store import S3Store

access_key_id = "..."
secret_access_key = "..."
store = S3Store.from_url(
"https://f0b62eebfbdde1133378bfe3958325f6.r2.cloudflarestorage.com/ kylebarron-public",
access_key_id=access_key_id,
secret_access_key=secret_access_key,
)
store.list_with_delimiter()
```

Or you can construct a store manually with the `endpoint` and `bucket` parameters:

```py
from obstore.store import S3Store

access_key_id = "..."
secret_access_key = "..."
bucket = "kylebarron-public"
endpoint = "https://f0b62eebfbdde1133378bfe3958325f6.r2.cloudflarestorage. com"
store = S3Store(
bucket,
access_key_id=access_key_id,
secret_access_key=secret_access_key,
endpoint=endpoint,
)
store.list_with_delimiter()
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ nav:
- examples/fastapi.md
- examples/minio.md
- examples/pyarrow.md
- examples/r2.md
- examples/stream-zip.md
- examples/tqdm.md
- examples/zarr.md
Expand Down
Loading