Implementation:Bentoml BentoML Store Base
| Knowledge Sources | |
|---|---|
| Domains | Storage, Core Framework, Artifact Management |
| Last Updated | 2026-02-13 15:00 GMT |
Overview
Provides the abstract StoreItem base class and generic Store class that manages versioned BentoML artifacts (bentos, models) on the local filesystem.
Description
The StoreItem class is an abstract base extending Exportable that defines the interface for stored artifacts. Each item has a tag (name:version), creation_time, path, and file_size. The Store generic class manages a directory of StoreItem objects using a tag-based naming convention (name/version subdirectories). It provides core operations: list (enumerate all items or filter by tag), get (retrieve a specific item with support for "latest" version resolution and partial version matching), register (create a new item directory with a context manager that cleans up on failure and updates the "latest" pointer), and delete (remove an item and update latest). The "latest" version is tracked via a text file at <name>/latest that contains the version string of the most recently created item. The store has no consistency checks and assumes no external modification of its directory.
Usage
Use Store as the base for BentoML's BentoStore and ModelStore implementations. It provides filesystem-based versioned artifact management with automatic latest-version tracking.
Code Reference
Source Location
- Repository: Bentoml_BentoML
- File: src/bentoml/_internal/store.py
- Lines: 1-208
Signature
class StoreItem(Exportable):
@property
@abstractmethod
def tag(self) -> Tag: ...
@classmethod
def get_typename(cls) -> str: ...
@property
def _export_name(self) -> str: ...
@property
@abstractmethod
def creation_time(self) -> datetime.datetime: ...
@property
def path(self) -> str: ...
def path_of(self, item: str) -> str: ...
@property
def file_size(self) -> int: ...
class Store(t.Generic[Item]):
_item_type: t.Type[Item]
def __init__(self, base_path: PathType): ...
def list(self, tag: Tag | str | None = None) -> t.List[Item]: ...
def get(self, tag: Tag | str) -> Item: ...
@contextmanager
def register(self, tag: str | Tag) -> t.Generator[str, None, None]: ...
def delete(self, tag: str | Tag) -> None: ...
Import
from bentoml._internal.store import Store, StoreItem
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| base_path | PathType | Yes | Root filesystem path where the store directory resides |
| tag | Tag, str, or None | No | Tag to filter by in list/get/register/delete; supports "name", "name:version", or "name:latest" |
Outputs
| Name | Type | Description |
|---|---|---|
| List[Item] | List[StoreItem] | List of store items matching the query (list) |
| Item | StoreItem | The matching store item (get) |
| str | str | Path to the newly registered item directory (register context manager) |
Usage Examples
from bentoml._internal.store import Store
from bentoml._internal.tag import Tag
# Typically used through BentoStore or ModelStore:
# store = BentoStore(base_path="/home/user/bentoml/bentos")
# List all items
# items = store.list()
# Get a specific version
# item = store.get("my_model:v1.0.0")
# Get the latest version
# item = store.get("my_model")
# Register a new item
# with store.register(Tag("my_model", "v2.0.0")) as path:
# # write item files to path
# pass
# Delete an item
# store.delete("my_model:v1.0.0")