Installing local dependencies into a Tesseract

Context

Sometimes it might be necessary to bundle local dependencies into a Tesseract; this can be done by simply adding their path to the tesseract_requirements.txt file. Both absolute and relative paths work, but in case they are relative paths, they should be relative to the Tesseract’s root folder (i.e., the one which contains the tesseract_api.py file)

Example Tesseract

Here’s an example: let’s initialize an empty tesseract via

$ tesseract init --name cowsay
 [i] Initializing Tesseract cowsay in directory: .
 [i] Writing template tesseract_api.py to tesseract_api.py
 [i] Writing template tesseract_config.yaml to tesseract_config.yaml
 [i] Writing template tesseract_requirements.txt to tesseract_requirements.txt

And let’s then edit the tesseract_api.py file to read

# Copyright 2025 Pasteur Labs. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

import cowsay
from pydantic import BaseModel, Field


class InputSchema(BaseModel):
    message: str = Field(description="A message for cowsay.")


class OutputSchema(BaseModel):
    cowsays: str = Field(description="The cowsay output string.")


def apply(inputs: InputSchema) -> OutputSchema:
    """Greet a person whose name is given as input."""
    return OutputSchema(cowsays=cowsay.get_output_string("cow", inputs.message))

This Tesseract will accept a message like “Hello, world!” as an input and return

 _______________
< Hello, World! >
 ---------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

but in order to do so, it will need the dependency cowsay installed. We could just add cowsay to the tesseract_requirements.txt file, but that would install it from PyPI every time. Let’s instead download it via pip download and then bundle it into a Tesseract; in order to do the former, we can run:

$ pip download cowsay==6.1
Collecting cowsay==6.1
  Obtaining dependency information for cowsay==6.1 from https://files.pythonhosted.org/packages/f1/13/63c0a02c44024ee16f664e0b36eefeb22d54e93531630bd99e237986f534/cowsay-6.1-py3-none-any.whl.metadata
  Downloading cowsay-6.1-py3-none-any.whl.metadata (5.6 kB)
Downloading cowsay-6.1-py3-none-any.whl (25 kB)
Saved ./cowsay-6.1-py3-none-any.whl
Successfully downloaded cowsay

We can then specify it as a local dependency in tesseract_requirements.txt by adding the following line:

./cowsay-6.1-py3-none-any.whl

Finally, let’s build the Tesseract, and verify it works

$ tesseract build .
 [i] Building image ...
 [i] Built image sha256:7d024, ['cowsay:latest']

$ tesseract run install_tarball apply '{"inputs": {"message": "Hello, World!"}}'
{"out":"  _____________\n| Hello, World! |\n  =============\n             \\\n              \\\n                ^__^\n                (oo)\\_______\n                (__)\\       )\\/\\\n                    ||----w |\n                    ||     ||"}