{"id":5529,"library":"truss","title":"Truss","description":"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.","status":"active","version":"0.15.12","language":"en","source_language":"en","source_url":"https://github.com/basetenlabs/truss","tags":["mlops","model serving","deployment","ai","containerization","machine learning"],"install":[{"cmd":"pip install truss","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires 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.","package":"python","optional":false}],"imports":[{"symbol":"truss","correct":"import truss"}],"quickstart":{"code":"import truss\nimport os\nimport pathlib\nimport shutil\n\n# Define model name and directory\nmodel_name = \"my_truss_model\"\nmodel_dir = pathlib.Path(f\"./{model_name}\")\n\n# Clean up previous runs if any\nif model_dir.exists():\n    shutil.rmtree(model_dir)\n\n# Initialize a new Truss model structure, creating the directory\ntruss.init(model_name)\n\n# Modify the model.py file to add a simple predict function\nmodel_py_path = model_dir / \"model\" / \"model.py\"\nwith open(model_py_path, \"w\") as f:\n    f.write(\"\"\"\nimport os\n\nclass Model:\n    def __init__(self):\n        self._data = None\n\n    def load(self):\n        # Simulate loading a model artifact or configuration\n        self._data = os.environ.get(\"TRUSS_MODEL_CONFIG\", \"default_config_value\")\n\n    def predict(self, model_input):\n        return f\"Hello, {model_input}! Model loaded with config: {self._data}\"\n\"\"\")\n\nprint(f\"Truss model initialized in: {model_dir.resolve()}\")\nprint(f\"To serve locally: Change directory to '{model_name}' (cd {model_name}) and run 'truss serve' in your terminal.\")\n\n# To clean up the created model directory (uncomment to run):\n# shutil.rmtree(model_dir)","lang":"python","description":"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."},"warnings":[{"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.","message":"Starting 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.","severity":"breaking","affected_versions":"0.15.13+"},{"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.","message":"Truss 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.","severity":"gotcha","affected_versions":"0.15.11+"},{"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.","message":"Since 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.","severity":"gotcha","affected_versions":"0.15.10+"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}