Skip to content

Commit 082a194

Browse files
authored
docs: add store example (#128)
1 parent f7e49fc commit 082a194

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

docs/examples/example_store.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# type: ignore
2+
"""
3+
# Using object storage
4+
5+
[obstore](https://github.com/developmentseed/obstore) is a new, powerful Python library for getting from and putting to object storage.
6+
**rustac** can use anything that implements [obstore.store.ObjectStore][], and also provides its own zero-dependency version in **rustac.store**.
7+
"""
8+
9+
# %%
10+
# ## Using **rustac.store**.
11+
12+
import contextily
13+
import pandas
14+
import rustac
15+
from rustac.store import HTTPStore
16+
from geopandas import GeoDataFrame
17+
18+
store = HTTPStore("https://raw.githubusercontent.com/stac-utils/rustac-py/refs/heads/main/data")
19+
items = await rustac.read("100-sentinel-2-items.parquet", store=store)
20+
print(len(items["features"]))
21+
22+
data_frame = GeoDataFrame.from_features(items)
23+
data_frame["datetime"] = pandas.to_datetime(data_frame["datetime"])
24+
axis = data_frame.set_crs(epsg=4326).to_crs(epsg=3857).plot(alpha=0.5, edgecolor="k")
25+
contextily.add_basemap(axis, source=contextily.providers.CartoDB.Positron)
26+
axis.set_axis_off()
27+
28+
29+
# %%
30+
# There's a [whole set][rustac.store.ObjectStore] of provided object storage backends.
31+
# See <https://developmentseed.org/obstore/latest/authentication/> for how you might configure authenticate with those backends.
32+
33+
# %%
34+
# ## Using **obstore.store.ObjectStore**.
35+
#
36+
# If you're doing work with **obstore** directly, you can re-use the same `ObjectStore`.
37+
38+
from obstore.store import HTTPStore
39+
40+
store = HTTPStore("https://raw.githubusercontent.com/stac-utils/rustac-py/refs/heads/main/data")
41+
items = await rustac.read("100-sentinel-2-items.parquet", store=store)
42+
43+
# Notice how there's a warning?
44+
# That's because we have to copy the `ObjectStore` when we pass it in to **rustac**.
45+
# This means it can be a bit more efficient to use `rustac.store` if you're only working with **rustac**.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ docs = [
7777
"mkdocs-gallery>=0.10.4",
7878
"mkdocs-material[imaging]>=9.5.45",
7979
"mkdocstrings[python]>=0.27.0",
80+
"obstore>=0.6.0",
8081
"pystac-client>=0.8.5",
8182
]
8283

uv.lock

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)