BentoML SDK#

Service decorator#

bentoml.service(inner: type[T], /) Service[T][source]#
bentoml.service(inner: None = None, /, **kwargs: Unpack) _ServiceDecorator

Mark a class as a BentoML service.

Example

@service(traffic={“timeout”: 60}) class InferenceService:

@api def predict(self, input: str) -> str:

return input

bentoml.runner_service(runner: Runner, **kwargs: Unpack) Service[Any][source]#

Make a service from a legacy Runner

Service API#

bentoml.api(func: t.Callable[t.Concatenate[t.Any, P], R]) APIMethod[P, R][source]#
bentoml.api(*, route: str | None = None, name: str | None = None, input_spec: type[_bentoml_sdk.io_models.IODescriptor] | None = None, output_spec: type[_bentoml_sdk.io_models.IODescriptor] | None = None, batchable: bool = False, batch_dim: int | tuple[int, int] = 0, max_batch_size: int = 100, max_latency_ms: int = 60000) t.Callable[[t.Callable[t.Concatenate[t.Any, P], R]], APIMethod[P, R]]

bentoml.depends#

bentoml.depends(on: Service[T]) Dependency[T][source]#

bentoml.validators#

class bentoml.validators.PILImageEncoder[source]#

Bases: object

decode(obj: bytes | t.BinaryIO | UploadFile | PILImage.Image) t.Any[source]#
encode(obj: PILImage.Image) bytes[source]#
class bentoml.validators.FileSchema(format: str = 'binary', content_type: str | None = None)[source]#

Bases: object

content_type: str | None#
decode(obj: bytes | BinaryIO | UploadFile | PurePath | str) Any[source]#
encode(obj: Path) bytes[source]#
format: str#
class bentoml.validators.TensorSchema(format: TensorFormat, dtype: t.Optional[str] = None, shape: t.Optional[t.Tuple[int, ...]] = None)[source]#

Bases: object

property dim: int | None#
dtype: t.Optional[str]#
encode(arr: TensorType) list[t.Any][source]#
format: TensorFormat#
property framework_dtype: Any#
shape: t.Optional[t.Tuple[int, ...]]#
validate(obj: Any) Any[source]#
class bentoml.validators.DataframeSchema(orient: str = 'records', columns: list[str] | None = None)[source]#

Bases: object

columns: list[str] | None#
encode(df: pd.DataFrame) list | dict[source]#
orient: str#
validate(obj: t.Any) pd.DataFrame[source]#
class bentoml.validators.ContentType(content_type: str)[source]#

Bases: BaseMetadata

content_type: str#
class bentoml.validators.Shape(dimensions: tuple[int, ...])[source]#

Bases: BaseMetadata

dimensions: tuple[int, ...]#
class bentoml.validators.DType(dtype: str)[source]#

Bases: BaseMetadata

dtype: str#