Implementation:Bentoml BentoML BentoBuildConfig
| Sources | Domains | Last Updated |
|---|---|---|
| BentoML, BentoML Build Options | ML_Serving, Build_System, Configuration | 2026-02-13 15:00 GMT |
Overview
The BentoBuildConfig class defines the complete build specification for packaging a BentoML service into a distributable Bento artifact.
Description
BentoBuildConfig is an attr-based dataclass that captures all configuration dimensions for a Bento build: service entry point, file inclusion/exclusion patterns, Docker options, Python dependencies, Conda options, model references, environment variables, and template arguments. It can be populated from a bentofile.yaml file or constructed programmatically. The with_defaults() method returns a FilledBentoBuildConfig with all optional fields resolved to their default values.
Usage
Typically loaded from a bentofile.yaml via the build CLI, or instantiated programmatically for dynamic build configurations and testing.
Code Reference
Source Location: Repository: bentoml/BentoML, File: src/bentoml/_internal/bento/build_config.py (L792-946)
Signature:
@attr.define
class BentoBuildConfig:
service: str
name: str | None = None
description: str | None = None
labels: dict = {}
include: list[str] | None = None
exclude: list[str] | None = None
docker: DockerOptions = DockerOptions()
python: PythonOptions = PythonOptions()
conda: CondaOptions = CondaOptions()
models: list[ModelSpec] = []
envs: list[BentoEnvSchema] = []
args: dict = {}
Import:
from bentoml._internal.bento.build_config import BentoBuildConfig
Related Classes:
# DockerOptions (L147-280)
@attr.define
class DockerOptions:
distro: str | None = None
python_version: str | None = None
cuda_version: str | None = None
system_packages: list[str] | None = None
setup_script: str | None = None
base_image: str | None = None
dockerfile_template: str | None = None
...
# PythonOptions (L435-676)
@attr.define
class PythonOptions:
packages: list[str] | None = None
requirements_txt: str | None = None
lock_packages: bool | None = None
index_url: str | None = None
extra_index_url: list[str] | None = None
trusted_host: list[str] | None = None
...
I/O Contract
Inputs:
| Parameter | Type | Required | Description |
|---|---|---|---|
| service | str | Yes | Service import string (e.g., "service:MyService") |
| name | str or None | No | Bento name (defaults to service name) |
| description | str or None | No | Human-readable description |
| labels | dict | No | Key-value metadata labels |
| include | list[str] or None | No | File glob patterns to include (default: all files) |
| exclude | list[str] or None | No | File glob patterns to exclude |
| docker | DockerOptions | No | Docker build options (base image, system packages, etc.) |
| python | PythonOptions | No | Python dependency options (pip packages, index URLs, etc.) |
| conda | CondaOptions | No | Conda environment options |
| models | list[ModelSpec] | No | Model references to include in the Bento |
| envs | list[BentoEnvSchema] | No | Environment variable declarations |
| args | dict | No | Template arguments for Dockerfile or setup scripts |
Outputs:
- BentoBuildConfig instance -- raw configuration object
- FilledBentoBuildConfig (from with_defaults()) -- configuration with all defaults resolved
Usage Examples
Example 1 -- bentofile.yaml format:
service: "service:Summarization"
include:
- "*.py"
- "requirements.txt"
exclude:
- "tests/"
python:
packages:
- torch
- transformers
docker:
distro: debian
python_version: "3.11"
system_packages:
- libgomp1
models:
- tag: "summarization-model:latest"
Example 2 -- Programmatic construction:
from bentoml._internal.bento.build_config import BentoBuildConfig
config = BentoBuildConfig(
service="service:MyService",
name="my-bento",
include=["*.py", "config/*.yaml"],
python=PythonOptions(packages=["torch", "transformers"]),
docker=DockerOptions(python_version="3.11"),
)
filled = config.with_defaults()