Implementation:Bentoml BentoML Bentos Build
| Sources | Domains | Last Updated |
|---|---|---|
| BentoML, BentoML Building Bentos | ML_Serving, Build_System, Artifact_Management | 2026-02-13 15:00 GMT |
Overview
The bentoml.bentos.build() and bentoml.bentos.build_bentofile() functions package a BentoML service into a self-contained Bento artifact stored in the local BentoStore.
Description
build() accepts all build parameters programmatically, while build_bentofile() reads configuration from a bentofile.yaml file. Both functions resolve the service module, collect source files, lock dependencies, reference models, and produce an immutable, versioned Bento artifact. The bare parameter in build_bentofile() enables lightweight builds without dependency resolution, useful for rapid iteration during development.
Usage
Call build() for fully programmatic builds in scripts or CI pipelines. Call build_bentofile() for YAML-driven builds from the CLI or when configuration is managed in version-controlled files.
Code Reference
Source Location: Repository: bentoml/BentoML, File: src/bentoml/bentos.py (L275-452)
Signature -- build():
def build(
service: str,
*,
name: str | None = None,
labels: dict = None,
description: str | None = None,
include: list[str] | None = None,
exclude: list[str] | None = None,
envs: list = None,
docker: DockerOptions = None,
python: PythonOptions = None,
conda: CondaOptions = None,
models: list = None,
version: str | None = None,
build_ctx: str | None = None,
platform: str | None = None,
args: dict = None,
) -> Bento
Signature -- build_bentofile():
def build_bentofile(
bentofile: str = None,
*,
service: str = None,
name: str = None,
version: str = None,
labels: dict = None,
build_ctx: str = None,
platform: str = None,
bare: bool = False,
reload: bool = False,
args: dict = None,
) -> Bento
Import:
import bentoml
# Direct function access
bentoml.bentos.build(...)
bentoml.bentos.build_bentofile(...)
I/O Contract
Inputs (build):
| 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) |
| labels | dict | No | Metadata labels for the Bento |
| description | str or None | No | Human-readable description |
| include | list[str] or None | No | File glob patterns to include |
| exclude | list[str] or None | No | File glob patterns to exclude |
| docker | DockerOptions | No | Docker build configuration |
| python | PythonOptions | No | Python dependency configuration |
| conda | CondaOptions | No | Conda environment configuration |
| models | list | No | Model references to include |
| version | str or None | No | Explicit version string (auto-generated if omitted) |
| build_ctx | str or None | No | Build context directory (defaults to current directory) |
| platform | str or None | No | Target platform (e.g., "linux/amd64") |
| args | dict | No | Template arguments |
Inputs (build_bentofile):
| Parameter | Type | Required | Description |
|---|---|---|---|
| bentofile | str | No | Path to bentofile.yaml (default: "bentofile.yaml") |
| service | str | No | Override service import string from bentofile |
| name | str | No | Override Bento name from bentofile |
| version | str | No | Explicit version string |
| build_ctx | str | No | Build context directory |
| platform | str | No | Target platform |
| bare | bool | No | Skip dependency resolution for fast iteration (default False) |
| reload | bool | No | Reload service module before build (default False) |
| args | dict | No | Template arguments |
Outputs:
- Bento -- built artifact saved to the local BentoStore
Usage Examples
Example 1 -- Programmatic build:
import bentoml
bento = bentoml.bentos.build(
service="service:Summarization",
include=["*.py"],
python=PythonOptions(packages=["torch", "transformers"]),
version="1.0.0",
)
print(f"Built: {bento.tag}")
Example 2 -- Build from bentofile.yaml:
import bentoml
bento = bentoml.bentos.build_bentofile(
bentofile="bentofile.yaml",
build_ctx="./my_project",
)
print(f"Built: {bento.tag}")
Example 3 -- Bare build for development:
import bentoml
bento = bentoml.bentos.build_bentofile(
bentofile="bentofile.yaml",
bare=True, # Skip dependency resolution
)