Skip to main content

Convert a string to bytes type or str type

Project description


A bulletproof way of converting a string to a byte string or a text string.

APIs are designed to encode or decode raise-free. In most cases, input object will be either a text string (str type) or a byte string (bytes type), and default encoding is 'utf-8'.


from textconv.text import to_text, to_bytes

# To text string
text_string = to_text(b'caf\xc3\xa9')

# To byte string
byte_string = to_bytes(u'caf\xe9', encoding="latin-1")

# A raise-free version of `str(obj)`
# if a non-string object is  provided
text_string = to_text(obj)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textconv-0.0.1.tar.gz (3.3 kB view hashes)

Uploaded source

Built Distribution

textconv-0.0.1-py3-none-any.whl (4.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page