Search documentation

Type to search the documentation.

Docs/Examples/Use a custom runtime image

Python example

Use a custom runtime image

Package dependencies and local files into a Task’s image.

Before you run#

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

Source code#

Download custom_image.py

Canonical examplecustom_image.py
custom_image.py
import asyncio

import yak


image = yak.Image.python_3_11().pip_install("requests==2.31.0")

app = yak.App(
    name="custom-image",
    image=image,
)


@app.task()
def package_version() -> str:
    import requests

    return requests.__version__


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


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

Run the example#

Save the source as custom_image.py, then run:

Commandcustom_image.py
custom_image.py ready
$ yak run custom_image.py