Search documentation

Type to search the documentation.

Docs/Examples/Use invocation scratch storage

Python example

Use invocation scratch storage

Write a temporary file to a bounded Ephemeral Disk.

Before you run#

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

Source code#

Download ephemeral_disk.py

Canonical exampleephemeral_disk.py
ephemeral_disk.py
import asyncio
from pathlib import Path

import yak

app = yak.App(name="ephemeral-scratch", image="python:3.11")


@app.task(ephemeral_disks={"/scratch": yak.EphemeralDisk(size="1GiB")})
def write_temporary_file() -> str:
    path = Path("/scratch/intermediate.txt")
    path.write_text("temporary\n")
    return path.read_text().strip()


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


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

Run the example#

Save the source as ephemeral_disk.py, then run:

Commandephemeral_disk.py
ephemeral_disk.py ready
$ yak run ephemeral_disk.py