Provides utility functions for encoding/decoding datetime and tag types, and converting between schema and object representations in BentoML's cloud layer. Use it for custom type serialization, cloud deployment, or schema-based object mapping.
# Source: https://github.com/bentoml/BentoML | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
from __future__ import annotations
import typing as t
from datetime import datetime
import cattr
from dateutil.parser import parse
from bentoml._internal.tag import Tag
time_format = "%Y-%m-%d %H:%M:%S.%f"
T = t.TypeVar("T")
def datetime_encoder(time_obj: t.Optional[datetime]) -> t.Optional[str]:
if not time_obj:
return None
return time_obj.strftime(time_format)
def datetime_decoder(datetime_str: t.Optional[str], _: t.Any) -> t.Optional[datetime]:
if not datetime_str:
return None
return parse(datetime_str)
def tag_encoder(tag_obj: t.Optional[Tag]) -
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key