serialize_datetime

def serialize_datetime(v: dt.datetime) -> str

Serialize a datetime including timezone info.

Uses the timezone info provided if present, otherwise uses the current runtime’s timezone info.

UTC datetimes end in “Z” while all other timezones are represented as offset from UTC, e.g. +05:00.

EventSerializer Objects

class EventSerializer(JSONEncoder)

Custom JSON encoder to assist in the serialization of a wide range of objects.

is_js_safe_integer

@staticmethod
def is_js_safe_integer(value: int) -> bool

Ensure the value is within JavaScript’s safe range for integers.

Python’s 64-bit integers can exceed this range, necessitating this check. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

serialize_to_str

def serialize_to_str(input_data: Any) -> str

Safely serialize data to a JSON string.

convert_to_string_dict

def convert_to_string_dict(input_: dict) -> dict[str, str]

Convert a dict with arbitrary values to a dict[str, str] by converting

all values to their string representations.

convert_time_delta_to_ns

def convert_time_delta_to_ns(time_delta: dt.timedelta) -> int

Convert a timedelta object to nanoseconds.