Implementation:Bentoml BentoML Models Export Import
Appearance
| Implementation Metadata | |
|---|---|
| Implementation Name | Models Export Import |
| API | bentoml.models.export_model(), bentoml.models.import_model()
|
| Source | src/bentoml/models.py:L62-207
|
| Workflow | Model_Store_Management |
| Domain | ML_Serving, Model_Management |
| Implements | Principle:Bentoml_BentoML_Model_Export_Import |
| Last Updated | 2026-02-13 15:00 GMT |
Overview
The bentoml.models.export_model() and bentoml.models.import_model() functions provide portable serialization and deserialization of BentoML models. Export packages a model from the local store into an archive file (or folder), while import reconstructs a model from such an archive into the local store.
Import
import bentoml
Signatures
export_model()
def export_model(
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
import_model()
def import_model(
path: str,
input_format: str = None,
*,
protocol: str = None,
user: str = None,
passwd: str = None,
params: dict = None,
subpath: str = None,
) -> Model
Parameters
export_model() Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
tag |
str | required | The model tag to export from the local store. |
path |
str |
required | Destination path. Can be a local filesystem path or a remote URI (e.g., s3://bucket/path).
|
output_format |
str |
None |
Archive format. If None, inferred from the file extension. Supported: "bentomodel", "gz", "xz", "bz2", "tar", "zip", "folder".
|
protocol |
str |
None |
Remote protocol override (e.g., "s3", "ftp"). Usually inferred from the URI scheme.
|
user |
str |
None |
Username for remote protocol authentication. |
passwd |
str |
None |
Password for remote protocol authentication. |
params |
dict |
None |
Additional parameters for the fsspec filesystem backend. |
subpath |
str |
None |
Subpath within the remote filesystem. |
import_model() Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
str |
required | Source path to import from. Can be local or remote. |
input_format |
str |
None |
Archive format. If None, inferred from file extension.
|
protocol |
str |
None |
Remote protocol override. |
user |
str |
None |
Username for authentication. |
passwd |
str |
None |
Password for authentication. |
params |
dict |
None |
Additional fsspec parameters. |
subpath |
str |
None |
Subpath within the remote filesystem. |
Inputs and Outputs
export_model()
Inputs:
- Model tag (must exist in local store) + destination path
Outputs:
str— the path where the model was exported
import_model()
Inputs:
- Source path (local file, remote URI, or folder)
Outputs:
Model— the imported model, now available in the local store
Supported Formats
| Format String | File Extension | Description |
|---|---|---|
"bentomodel" |
.bentomodel |
Default BentoML archive format |
"gz" |
.gz |
Gzip-compressed tar |
"xz" |
.xz |
XZ-compressed tar |
"bz2" |
.bz2 |
Bzip2-compressed tar |
"tar" |
.tar |
Uncompressed tar |
"zip" |
.zip |
ZIP archive |
"folder" |
(directory) | Direct folder copy |
Usage Examples
import bentoml
# Export to a local file (format inferred from extension)
path = bentoml.models.export_model(
"text_classifier:latest",
"/tmp/text_classifier.bentomodel",
)
print(f"Exported to: {path}")
# Export with explicit gzip compression
bentoml.models.export_model(
"text_classifier:latest",
"/tmp/text_classifier.tar.gz",
output_format="gz",
)
# Export to S3
bentoml.models.export_model(
"text_classifier:latest",
"s3://my-bucket/models/text_classifier.bentomodel",
)
# Import from a local file
model = bentoml.models.import_model("/tmp/text_classifier.bentomodel")
print(f"Imported: {model.tag}")
# Import from S3
model = bentoml.models.import_model(
"s3://my-bucket/models/text_classifier.bentomodel"
)
Behavior Details
- Format is auto-detected from the file extension when
output_format/input_formatisNone. - Remote protocol support is powered by fsspec, enabling seamless integration with S3, GCS, FTP, HDFS, and other backends.
- The exported archive is self-contained, including the
model.yamldescriptor, all artifact files, and custom objects. - On import, the model is added to the local store with its original tag. If a model with the same tag already exists, the import will fail unless the existing model is deleted first.
Source Reference
File: src/bentoml/models.py, lines 62-207.
Knowledge Sources
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment