tesseract Python API

class tesseract_core.Tesseract(url)[source]

A Tesseract.

This class represents a single Tesseract instance, either remote or local, and provides methods to run commands on it and retrieve results.

Communication between a Tesseract and this class is done either via HTTP requests or docker exec invocations (only possible for local instances spawned when instantiating the class).

apply(inputs)[source]

Run apply endpoint.

Parameters:

inputs (dict) – a dictionary with the inputs.

Return type:

dict

Returns:

dictionary with the results.

property available_endpoints: list[str]

Get the list of available endpoints.

Returns:

a list with all available endpoints for this Tesseract.

property input_schema: dict

Get the input schema of this Tessseract.

Returns:

dictionary with the input schema.

jacobian(inputs, jac_inputs, jac_outputs)[source]

Calculate the Jacobian of (some of the) outputs w.r.t. (some of the) inputs.

Parameters:
  • inputs (dict) – a dictionary with the inputs.

  • jac_inputs (list[str]) – Inputs with respect to which derivatives will be calculated.

  • jac_outputs (list[str]) – Outputs which will be differentiated.

Return type:

dict

Returns:

dictionary with the results.

jacobian_vector_product(inputs, jvp_inputs, jvp_outputs, tangent_vector)[source]

Calculate the Jacobian Vector Product (JVP) of (some of the) outputs w.r.t. (some of the) inputs.

Parameters:
  • inputs (dict) – a dictionary with the inputs.

  • jvp_inputs (list[str]) – Inputs with respect to which derivatives will be calculated.

  • jvp_outputs (list[str]) – Outputs which will be differentiated.

  • tangent_vector (dict) – Element of the tangent space to multiply with the Jacobian.

Return type:

dict

Returns:

dictionary with the results.

property openapi_schema: dict

Get the OpenAPI schema of this Tessseract.

Returns:

dictionary with the OpenAPI Schema.

property output_schema: dict

Get the output schema of this Tessseract.

Returns:

dictionary with the output schema.

vector_jacobian_product(inputs, vjp_inputs, vjp_outputs, cotangent_vector)[source]

Calculate the Vector Jacobian Product (VJP) of (some of the) outputs w.r.t. (some of the) inputs.

Parameters:
  • inputs (dict) – a dictionary with the inputs.

  • vjp_inputs (list[str]) – Inputs with respect to which derivatives will be calculated.

  • vjp_outputs (list[str]) – Outputs which will be differentiated.

  • cotangent_vector (dict) – Element of the cotangent space to multiply with the Jacobian.

Return type:

dict

Returns:

dictionary with the results.

tesseract_core.build_tesseract(src_dir, image_tag, build_dir=None, inject_ssh=False, config_override=(), keep_build_cache=False, generate_only=False)[source]

Build a new Tesseract from a context directory.

Parameters:
  • src_dir (Path) – path to the Tesseract project directory, where the tesseract_api.py and tesseract_config.yaml files are located.

  • image_tag (str | None) – name to be used as a tag for the Tesseract image.

  • build_dir (Path | None) – directory to be used to store the build context. If not provided, a temporary directory will be created.

  • inject_ssh (bool) – whether or not to forward SSH agent when building the image.

  • config_override (tuple[tuple[list[str], str], ...]) – overrides for configuration options in the Tesseract.

  • keep_build_cache (bool) – whether or not to keep the Docker build cache.

  • generate_only (bool) – only generate the build context but do not build the image.

Return type:

Image | Path

Returns:

docker.models.images.Image representing the built Tesseract image, or path to build directory if generate_only is True.

tesseract_core.run_tesseract(image, command, args, volumes=None, gpus=None)[source]

Start a Tesseract and execute a given command.

Parameters:
  • image (str | Image) – string or docker.models.images.Image object of the Tesseract to run.

  • command (str) – Tesseract command to run, e.g. apply.

  • args (list[str]) – arguments for the command.

  • volumes (list[str] | None) – list of paths to mount in the Tesseract container.

  • gpus (list[int | str] | None) – list of GPUs, as indices or names, to passthrough the container.

Return type:

tuple[str, str]

Returns:

Tuple with the stdout and stderr of the Tesseract.

tesseract_core.serve(images, port='', volumes=None, gpus=None)[source]

Serve one or more Tesseract images.

Start the Tesseracts listening on an available ports on the host.

Parameters:
  • images (list[str | Image]) – a list of Tesseract image IDs as strings or docker’s Image object.

  • port (str) – port or port range to serve the tesseract on.

  • volumes (list[str] | None) – list of paths to mount in the Tesseract container.

  • gpus (list[str] | None) – IDs of host Nvidia GPUs to make available to the Tesseracts.

Return type:

str

Returns:

A string representing the Tesseract Project ID.

tesseract_core.teardown(project_id)[source]

Teardown Tesseract image(s) running in a Docker Compose project.

Parameters:

project_id (str) – Docker Compose project ID to teardown.

Return type:

None