faust.utils.json

JSON utilities.

class faust.utils.json.JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Faust customized json.JSONEncoder.

Our version supports additional types like UUID, and importantly includes microsecond information in datetimes.

default(o: ~typing.Any, *, callback: ~typing.Callable[[~typing.Any], ~typing.Any] = <function on_default>) Any[source]

Try to convert non-built-in json type to json.

Return type:

Any

faust.utils.json.dumps(obj: ~typing.Any, json_dumps: ~typing.Callable = <function dumps>, cls: ~typing.Type[~faust.utils.json.JSONEncoder] = <class 'faust.utils.json.JSONEncoder'>, **kwargs: ~typing.Any) str[source]

Serialize to json. See json.dumps().

Return type:

str

faust.utils.json.loads(s: str, json_loads: ~typing.Callable = <function loads>, **kwargs: ~typing.Any) Any[source]

Deserialize json string. See json.loads().

Return type:

Any

faust.utils.json.str_to_decimal(s: str, maxlen: int = 1000) Optional[Decimal][source]

Convert string to Decimal.

Parameters:
  • s (str) – Number to convert.

  • maxlen (int) – Max length of string. Default is 100.

Raises:

ValueError – if length exceeds maximum length, or if value is not a valid number (e.g. Inf, NaN or sNaN).

Return type:

_UnionGenericAlias[Decimal, None]

Returns:

Converted number.

Return type:

Decimal