This document is for Kombu's development version, which can be significantly different from previous releases. Get the stable docs here: 5.3.

# String Encoding Utilities - `kombu.utils.encoding`

Text encoding utilities.

Utilities to encode text, and to safely emit text from running applications without crashing from the infamous `UnicodeDecodeError` exception.

kombu.utils.encoding.bytes_to_str(s)

  Convert bytes to str.

kombu.utils.encoding.default_encode(obj)

  Encode using default encoding.

kombu.utils.encoding.default_encoding(file=None)

  Get default encoding.

kombu.utils.encoding.default_encoding_file = None

  safe_str takes encoding from this file by default. `set_default_encoding_file()` can used to set the default output file.

kombu.utils.encoding.ensure_bytes(s)

  Ensure s is bytes, not str.

kombu.utils.encoding.from_utf8(s, *args, **kwargs)

  Get str from utf-8 encoding.

kombu.utils.encoding.get_default_encoding_file()

  Get file used to get codec information.

kombu.utils.encoding.safe_repr(o, errors='replace')

  Safe form of repr, void of Unicode errors.

kombu.utils.encoding.safe_str(s, errors='replace')

  Safe form of str(), void of unicode errors.

kombu.utils.encoding.set_default_encoding_file(file)

  Set file used to get codec information.

kombu.utils.encoding.str_to_bytes(s)

  Convert str to bytes.