Skip to content

Commit be7596f

Browse files
authored
docs: Add Cloudflare R2 example (#504)
* docs: Add Cloudflare R2 example * edit
1 parent f88c7bd commit be7596f

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed
64.6 KB
Loading
56.2 KB
Loading

docs/examples/r2.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Cloudflare R2
2+
3+
[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.
4+
5+
It's easy to read and write data to and from Cloudflare R2 with obstore's [`S3Store`][obstore.store.S3Store] with three steps:
6+
7+
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.
8+
9+
Copy the `Access Key ID` and `Secret Access Key` to use in your code.
10+
11+
![](../assets/cloudflare-r2-credentials.jpg)
12+
13+
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`.
14+
15+
![](../assets/cloudflare-r2-bucket-info.png)
16+
17+
3. Pass this information to [`S3Store.from_url`][obstore.store.S3Store.from_url]:
18+
19+
```py
20+
from obstore.store import S3Store
21+
22+
access_key_id = "..."
23+
secret_access_key = "..."
24+
store = S3Store.from_url(
25+
"https://f0b62eebfbdde1133378bfe3958325f6.r2.cloudflarestorage.com/ kylebarron-public",
26+
access_key_id=access_key_id,
27+
secret_access_key=secret_access_key,
28+
)
29+
store.list_with_delimiter()
30+
```
31+
32+
Or you can construct a store manually with the `endpoint` and `bucket` parameters:
33+
34+
```py
35+
from obstore.store import S3Store
36+
37+
access_key_id = "..."
38+
secret_access_key = "..."
39+
bucket = "kylebarron-public"
40+
endpoint = "https://f0b62eebfbdde1133378bfe3958325f6.r2.cloudflarestorage. com"
41+
store = S3Store(
42+
bucket,
43+
access_key_id=access_key_id,
44+
secret_access_key=secret_access_key,
45+
endpoint=endpoint,
46+
)
47+
store.list_with_delimiter()
48+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ nav:
4040
- examples/fastapi.md
4141
- examples/minio.md
4242
- examples/pyarrow.md
43+
- examples/r2.md
4344
- examples/stream-zip.md
4445
- examples/tqdm.md
4546
- examples/zarr.md

0 commit comments

Comments
 (0)