Search documentation

Type to search the documentation.

Docs/Examples/Publish files to a Volume

Python example

Publish files to a Volume

Stage a checkpoint, publish it, and read it from a remote Task.

Before you run#

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

Source code#

Download volume_checkpoint.py

Canonical examplevolume_checkpoint.py
volume_checkpoint.py
import asyncio
from pathlib import Path

import yak

app = yak.App(name="volume-checkpoint", image="python:3.11")
volume = yak.Volume.from_name("quickstart-checkpoints")


@app.task(volumes={"/checkpoint": volume.mount(read_only=True, subpath="reports")})
def read_checkpoint() -> str:
    contents = Path("/checkpoint/summary.txt").read_text().strip()
    return f"checkpoint: {contents}"


@app.entrypoint()
async def main() -> None:
    with volume.open("reports/summary.txt", "w") as file:
        file.write("ready\n")
    volume.publish()
    print(await read_checkpoint.remote.aio())


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

Run the example#

Save the source as volume_checkpoint.py, then run:

Commandvolume_checkpoint.py
volume_checkpoint.py ready
$ yak run volume_checkpoint.py