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]]

Make a BentoML API method. This decorator can be used either with or without arguments.

Parameters:
  • func – The function to be wrapped.

  • route – The route of the API. e.g. β€œ/predict”

  • name – The name of the API.

  • input_spec – The input spec of the API, should be a subclass of pydantic.BaseModel.

  • output_spec – The output spec of the API, should be a subclass of pydantic.BaseModel.

  • batchable – Whether the API is batchable.

  • batch_dim – The batch dimension of the API.

  • max_batch_size – The maximum batch size of the API.

  • max_latency_ms – The maximum latency of the API.

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, info: core_schema.SerializationInfo) 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, info: core_schema.SerializationInfo) t.Any[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#