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 directly via Python calls to the Tesseract API.
- property available_endpoints: list[str]¶
Get the list of available endpoints.
- Returns:
a list with all available endpoints for this Tesseract.
- classmethod from_image(image, *, volumes=None, gpus=None)[source]¶
Create a Tesseract instance from a Docker image.
When using this method, the Tesseract will be spawned in a Docker container, serving the Tesseract API via HTTP. To use the Tesseract, you need to call the serve method or use it as a context manager.
Example
>>> with Tesseract.from_image("my_tesseract") as t: ... # Use tesseract here
This will automatically teardown the Tesseract when exiting the context manager.
- classmethod from_tesseract_api(tesseract_api)[source]¶
Create a Tesseract instance from a Tesseract API module.
Warning: This does not use a containerized Tesseract, but rather imports the Tesseract API directly. This is useful for debugging, but requires a matching runtime environment + all dependencies to be installed locally.
- Parameters:
tesseract_api (
str
|Path
|ModuleType
) – Path to the tesseract_api.py file, or an already imported Tesseract API module.- Return type:
- Returns:
A Tesseract instance.
- classmethod from_url(url)[source]¶
Create a Tesseract instance from a URL.
This is useful for connecting to a remote Tesseract instance.
- health()[source]¶
Check the health of the Tesseract.
- Return type:
- Returns:
dictionary with the health status.
- property input_schema: dict[source]¶
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.
- 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:
- Return type:
- Returns:
dictionary with the results.
- property openapi_schema: dict[source]¶
Get the OpenAPI schema of this Tessseract.
- Returns:
dictionary with the OpenAPI Schema.
- property output_schema: dict[source]¶
Get the output schema of this Tessseract.
- Returns:
dictionary with the output schema.
- server_logs()[source]¶
Get the logs of the Tesseract server.
- Return type:
- Returns:
logs of the Tesseract server.
- teardown()[source]¶
Teardown the Tesseract.
This will stop and remove the Tesseract container.
- Return type:
- tesseract_core.build_tesseract(src_dir, image_tag, build_dir=None, inject_ssh=False, config_override=(), generate_only=False)[source]¶
Build a new Tesseract from a context directory.
- Parameters:
src_dir (
str
|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.generate_only (
bool
) – only generate the build context but do not build the image.
- Return type:
Image
|Path
- Returns:
Image object 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:
- Return type:
- Returns:
Tuple with the stdout and stderr of the Tesseract.
- tesseract_core.serve(images, ports=None, volumes=None, gpus=None, debug=False)[source]¶
Serve one or more Tesseract images.
Start the Tesseracts listening on an available ports on the host.
- Parameters:
images (
list
[str
]) – a list of Tesseract image IDs as strings.ports (
list
[str
] |None
) – port or port range to serve each 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.debug (
bool
) – whether to enable debug mode.
- Return type:
- Returns:
A string representing the Tesseract Project ID.