Implementation:Bentoml BentoML Bentos Export Import
| Sources | Domains | Last Updated |
|---|---|---|
| BentoML, BentoML Managing Bentos | ML_Serving, Artifact_Management, Distribution | 2026-02-13 15:00 GMT |
Overview
The export_bento(), import_bento(), push(), and pull() functions in bentoml.bentos provide the complete artifact distribution API for Bento packages.
Description
These functions handle the four core distribution operations:
- export_bento() -- serializes a Bento from the local BentoStore to a file path or remote storage URI
- import_bento() -- deserializes a Bento from a file or remote URI into the local BentoStore
- push() -- uploads a Bento to the BentoCloud registry
- pull() -- downloads a Bento from the BentoCloud registry to the local BentoStore
Export and import support multiple output formats (tar, gz, zip, bentomodel) and transport protocols (local filesystem, S3, FTP).
Usage
Use export_bento() / import_bento() for file-based transfers (CI/CD pipelines, air-gapped deployments). Use push() / pull() for BentoCloud registry interactions (team collaboration, cloud deployment).
Code Reference
Source Location: Repository: bentoml/BentoML, File: src/bentoml/bentos.py (L84-272)
Signature -- export_bento():
def export_bento(
tag: Tag | str,
path: str,
output_format: str = None,
*,
protocol: str = None,
user: str = None,
passwd: str = None,
params: dict = None,
subpath: str = None,
) -> str
Signature -- import_bento():
def import_bento(
path: str,
input_format: str = None,
*,
protocol: str = None,
user: str = None,
passwd: str = None,
params: dict = None,
subpath: str = None,
) -> Bento
Signature -- push() and pull():
def push(tag: Tag | str, *, force: bool = False) -> None
def pull(tag: Tag | str, *, force: bool = False) -> Bento
Import:
import bentoml
bentoml.bentos.export_bento(...)
bentoml.bentos.import_bento(...)
bentoml.bentos.push(...)
bentoml.bentos.pull(...)
I/O Contract
Inputs (export_bento):
| Parameter | Type | Required | Description |
|---|---|---|---|
| tag | Tag or str | Yes | Bento tag to export (e.g., "my-service:abc123") |
| path | str | Yes | Destination path or URI (local path, S3 URI, etc.) |
| output_format | str | No | Archive format: "bentomodel", "tar", "gz", "zip" (auto-detected from extension) |
| protocol | str | No | Transport protocol override |
| user | str | No | Username for authenticated transports (FTP, etc.) |
| passwd | str | No | Password for authenticated transports |
| params | dict | No | Additional protocol-specific parameters |
| subpath | str | No | Subpath within the destination |
Inputs (import_bento):
| Parameter | Type | Required | Description |
|---|---|---|---|
| path | str | Yes | Source path or URI of the Bento archive |
| input_format | str | No | Archive format (auto-detected from extension) |
| protocol | str | No | Transport protocol override |
| user | str | No | Username for authenticated transports |
| passwd | str | No | Password for authenticated transports |
| params | dict | No | Additional protocol-specific parameters |
| subpath | str | No | Subpath within the source |
Inputs (push / pull):
| Parameter | Type | Required | Description |
|---|---|---|---|
| tag | Tag or str | Yes | Bento tag to push or pull |
| force | bool | No | Force overwrite if the Bento already exists (default False) |
Outputs:
| Function | Return Type | Description |
|---|---|---|
| export_bento | str | Destination path where the Bento was exported |
| import_bento | Bento | Imported Bento object in the local BentoStore |
| push | None | Bento uploaded to BentoCloud (no return value) |
| pull | Bento | Downloaded Bento object in the local BentoStore |
Usage Examples
Example 1 -- Export to local tar.gz:
import bentoml
path = bentoml.bentos.export_bento(
"my-service:latest",
"/tmp/my-service-latest.tar.gz",
)
print(f"Exported to: {path}")
Example 2 -- Export to S3:
import bentoml
bentoml.bentos.export_bento(
"my-service:abc123",
"s3://my-bucket/bentos/my-service-abc123.tar.gz",
)
Example 3 -- Import from file:
import bentoml
bento = bentoml.bentos.import_bento(
"/tmp/my-service-latest.tar.gz",
)
print(f"Imported: {bento.tag}")
Example 4 -- Push to BentoCloud:
import bentoml
bentoml.bentos.push("my-service:latest")
Example 5 -- Pull from BentoCloud:
import bentoml
bento = bentoml.bentos.pull("my-service:latest", force=True)
print(f"Pulled: {bento.tag}")