Python client
A list of the functions available with
import truss
and their arguments and properties.Cleans up
.truss
directory.Get a handle to a Truss. A Truss is a build context designed to be built as a container locally or uploaded into a model serving environment.
args
:truss_directory
(str
): The local directory of an existing Truss
Returns:
TrussHandle
: A handle to the generated Truss that provides easy access to content inside.
Initialize an empty placeholder Truss. A Truss is a build context designed to be built as a container locally or uploaded into a model serving environment. This placeholder structure can be filled to represent ML models.
args
:target_directory
(str
): Absolute or relative path of the directory to create Truss in. The directory is created if it doesn't exist.
Create a Truss with the given model. A Truss is a build context designed to be built as a container locally or uploaded into a model serving environment.
args
:model
(an in-memory model object): A model object to be deployed (e.g. a keras sklearn, or pytorch model object)target_directory
(str
, optional): The local directory target for the Truss. Otherwise a temporary directory will be generateddata_files
(List[str]
, optional): Additional files required for model operation. Can be a glob that resolves to files for the root directory or a directory path.requirements_file
(str
, optional): A file of packages in a PIP requirements format to be installed in the container environment.
Returns:
TrussHandle
: A handle to the generated Truss that provides easy access to content inside.
Add a bundled package to a truss model.
Accepts a file path, a directory path or a glob. Everything is copied under the truss model's packages directory.
Add data to a truss model.
Accepts a file path, a directory path or a glob. Everything is copied under the truss model's data directory.
Add an environment variable to truss model's config.
Add example for truss model.
If the example with the given name already exists then it is overwritten.
Add a python requirement to truss model's config.
Add a system package requirement to truss model's config.
Builds docker image
Set up a directory to build docker image from.
Returns:
- docker build command.
Builds docker image, runs that as a docker container and makes a prediction request to the server running on the container. Kills the container afterwards. Mostly useful for testing.
Builds a docker image and runs it as a container.
Returns: Container, which can be used to get information about the running, including its id. The id can be used to kill the container.
Enable gpu use for given model.
This is suggestive, model serving environment may still use cpu, e.g. if the setup doesn't have access to a GPU.
Note that truss would typically use a larger docker base image when this is enabled, for example to include the cuda libraries.
Return lookup an example by name or index.
Index is 0 based. e.g. example(0) returns the first example.
List truss model's examples.
Examples are a simple
name to input
dictionary.Run the prediction flow locally.
Update truss model's examples.
Existing examples are replaced whole with the given ones.
Update requirements in truss model's config.
Replaces requirements in truss model's config with the provided list.
Update requirements in truss model's config.
Replaces requirements in truss model's config with those from the file at the given path.
Last modified 1mo ago