Search documentation

Type to search the documentation.

Docs/Examples/Read from object storage

Python example

Read from object storage

Mount an existing bucket prefix with a named credential Secret.

Before you run#

Use an installed, authenticated Yak CLI with access to the invite-only preview. Read Object Storage Mounts for the full setup and current behavior.

Source code#

Download object_storage_mount.py

Canonical exampleobject_storage_mount.py
object_storage_mount.py
import asyncio
from pathlib import Path

import yak

app = yak.App(name="object-storage-reader", image="python:3.11")
dataset = yak.ObjectStorageMount(
    bucket="team-datasets",
    prefix="training/current",
    credentials=yak.Secret.from_name("dataset-reader"),
    mode="ro",
)


@app.task(mounts={"/dataset": dataset})
def read_dataset_summary() -> str:
    return Path("/dataset/README.txt").read_text().strip()


@app.entrypoint()
async def main() -> None:
    print(await read_dataset_summary.remote.aio())


if __name__ == "__main__":
    asyncio.run(main())

Run the example#

Save the source as object_storage_mount.py, then run:

Commandobject_storage_mount.py
object_storage_mount.py ready
$ yak run object_storage_mount.py