Registry / ai-ml / truss
library0.18.27pypypi✓ verified 23d ago

Truss is a Python library that provides a seamless bridge from model development to model delivery. It allows data scientists to containerize, test, and deploy machine learning models as production-ready services with ease, often to platforms like Baseten. The current stable version is 0.15.12, with a fairly active release cadence, frequently releasing patch versions.

pip install truss
INSTALL
IMPORT
SIG · TRUSS
T
truss
ai-mlpythonv0.18.27
Install
17.7s avg
Import
4529ms
Disk
196MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.18.27 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 4.806s · 194.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 17.7s · import 4.252s · 194MB
196MB installed
● package 196MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

truss
import truss

This quickstart demonstrates how to initialize a new Truss project and add a basic `predict` function. The example includes simulating model data loading via an environment variable. To actually serve and test the model, navigate into the created directory (`cd my_truss_model`) and run `truss serve` from your terminal. For deployment to platforms like Baseten, an API key (e.g., `os.environ.get('BASETEN_API_KEY', '')`) would typically be required for `truss.push()` operations.

import truss import os import pathlib import shutil # Define model name and directory model_name = "my_truss_model" model_dir = pathlib.Path(f"./{model_name}") # Clean up previous runs if any if model_dir.exists(): shutil.rmtree(model_dir) # Initialize a new Truss model structure, creating the directory truss.init(model_name) # Modify the model.py file to add a simple predict function model_py_path = model_dir / "model" / "model.py" with open(model_py_path, "w") as f: f.write(""" import os class Model: def __init__(self): self._data = None def load(self): # Simulate loading a model artifact or configuration self._data = os.environ.get("TRUSS_MODEL_CONFIG", "default_config_value") def predict(self, model_input): return f"Hello, {model_input}! Model loaded with config: {self._data}" """) print(f"Truss model initialized in: {model_dir.resolve()}") print(f"To serve locally: Change directory to '{model_name}' (cd {model_name}) and run 'truss serve' in your terminal.") # To clean up the created model directory (uncomment to run): # shutil.rmtree(model_dir)
truss --version
Debug
Known issues
breakingStarting with version 0.15.13, Truss will change its default Python version for new models to 3.13 and officially deprecate support for Python 3.9. Models currently using Python 3.9 will need to update their Python version.
fix
For models deployed with Truss 0.15.13 or newer, ensure your `config.yaml` explicitly specifies a supported Python version (e.g., `python_version: '3.10'`) or upgrade your model's environment to Python 3.10 or newer.
affects: 0.15.13+
gotchaTruss utilizes certain environment variables internally for its operations and configuration. Overriding these with your own custom environment variables can lead to unexpected behavior, build failures, or runtime errors within your deployed model.
fix
Consult the official Truss documentation for a list of reserved environment variables to avoid collisions. Consider prefixing your custom model-specific environment variables (e.g., `MY_MODEL_VAR_NAME`) to minimize the risk of conflict.
affects: 0.15.11+
gotchaSince version 0.15.10, the `config.yaml` file for Truss models adheres to a JSON schema, with validation occurring during build and push operations. This can cause older `config.yaml` files with deprecated or invalid syntax to fail validation.
fix
If you encounter validation errors, refer to the latest `config.yaml` schema documentation or try initializing a new Truss project and migrating your model code to ensure your configuration is up-to-date and compliant.
affects: 0.15.10+
Errors
Common errors & fixes
truss: command not found
The 'truss' command-line interface (CLI) is not installed or not available in the system's PATH.
fix
Install the truss library via pip: `pip install truss`
ModuleNotFoundError: No module named 'your_model_dependency'
A Python package required by your model's code (in model.py or predict.py) is missing from the Truss's requirements.txt file.
fix
Add the missing package and its version to the `requirements.txt` file inside your Truss directory (e.g., `transformers==4.30.0`) and restart the Truss.
OSError: [Errno 98] Address already in use
The port (defaulting to 8080) that `truss serve` attempts to use is already occupied by another running process.
fix
Stop the process currently using the port, or specify a different port for `truss serve` using `truss serve -p <new_port_number>`.
TypeError: predict() missing 1 required positional argument: 'model_input'
The `predict` method in your `model.py` (or `predict.py`) does not conform to the expected Truss signature, typically missing the `model_input` argument.
fix
Ensure the `predict` method is defined as `def predict(self, model_input):` within your model class.
Upgrade
Version history
0.18.27latest on PyPI · released Aug 26, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.9 to 3.14 for version 0.15.12. Upcoming versions (0.15.13+) will deprecate 3.9 and default to 3.13.
Agent activity
38 hits · last 30 days
node
34
OpenAI (training)
1
Resources
truss — pip install truss · libregistry