Skip to main content
Tensorlake functions run in function containers. To install dependencies in the containers, we use container images that are built when you deploy an application. By default function images use a generic Debian based image python:{LOCAL_PYTHON_VERSION}-slim-bookworm. LOCAL_PYTHON_VERSION represents the Python version in your current Python environment. Functions can use any Python or system packages installed into their container images. Tensorlake provides a declarative API to define function container images with their dependencies. When you deploy an application, the function container images are automatically built as part of the deployment process.

How to define images

Tensorlake allows you to define your own function images with customized environments where the functions will run.
1

Define your image

An image is defined using an Image object. You can modify the base image, run commands to install dependencies at build time, and modify other image attributes, like its name.
from tensorlake.applications import Image

image = (
    Image(
        name="my-pdf-parser-image",
        base_image="ubuntu:24.04",
    )
    .run("apt update")
    .run("pip install torch")
    .run("pip install langchain")
)
2

Set the image used to run the function

from tensorlake.applications import function

@function(image=image)
def parse_pdf(pdf_path: str) -> str:
    import langchain
    # All the packages installed in the image are available inside the function.
    # They need to be imported here because they might not be available
    # in the Python environment used to deploy the application.
    ...