faust.utils.json

JSON utilities.

faust.utils.json.str_to_decimal(s: str, maxlen: int = 1000) → Optional[decimal.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

Optional[Decimal]

Returns

Converted number.

Return type

Decimal

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: Any, *, callback: Callable[Any, Any] = <function on_default>) → Any[source]

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

Return type

Any

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

Serialize to json. See json.dumps().

Return type

str

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

Deserialize json string. See json.loads().

Return type

Any