Encoding Tools
This module aims to provide a wrapper to deal with encoding in Python.
Features
Encode str to bytes
from encoding_tools import TheSoCalledGreatEncoder
encoder = TheSoCalledGreatEncoder()
encoder.load_str('hellò')
encoder.encode('latin-1')
encoded_string = encoder.encoded_data
Yes, this is a much complicated than a simple 'hellò'.encode('latin-1'), but it deals with encoding errors.
By default, it will fallback to ASCII if an error is encountered.
from encoding_tools import TheSoCalledGreatEncoder
encoder = TheSoCalledGreatEncoder()
encoder.load_str('cœur') # œ is not supported by latin-1
encoder.encode('latin-1')
encoded_string = encoder.encoded_data # equals to b'coeur'
If you want to force ASCII conversion, you can do it by specifying force_ascii=True when
calling .encode().
Decode bytes to str
from encoding_tools import TheSoCalledGreatEncoder, GuessEncodingFailedException
encoder = TheSoCalledGreatEncoder()
encoder.load_bytes(b'hell\xf2')
try:
encoder.decode()
except GuessEncodingFailedException as e:
# Deal with it
raise ValueError('Wrong input...') from e
decoded_string = encoder.decoded_data # equals to 'hellò'
encoding = encoder.encoding # equals to 'ISO-8859-1'
The decoder will guess encoding for you using the great Chardet library. You can as well provide the encoding
if you know when you load the data: .load_bytes(b'hell\xf2', encoding='latin-1')
To change data encoding, proceed this way:
from encoding_tools import TheSoCalledGreatEncoder, GuessEncodingFailedException
encoder = TheSoCalledGreatEncoder()
encoder.load_bytes(b'hell\xf2') # latin-1
try:
encoder.decode()
except GuessEncodingFailedException as e:
# Deal with it
raise ValueError('Wrong input...') from e
encoder.encode('utf-8')
encoded_string = encoder.encoded_data # equals to b'hell\xc3\xb2'
encoding = encoder.encoding # equals to 'utf-8'
Roadmap
- Deals with decoding errors
- Support more encoding (test suite)
Metadata
Release files for encoding-tools 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| encoding_tools-0.0.3.tar.gz | 3.2 kB | Without provenance | Details for encoding_tools-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| encoding_tools-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for encoding_tools-0.0.3-py3-none-any.whl |
Total release size: 7.2 kB
Release files / encoding_tools-0.0.3.tar.gz
| Download URL | encoding_tools-0.0.3.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d2fd169266044dca39310a753f0c9dd8c82ff6c38102e1e5cbf7c96a135aac4
|
|
BLAKE2b-256 checksum How to use checksums |
46111846b95662b0723016d99db9da18fdd302313ecb71695b856d62a5cf8807
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
|
Release files / encoding_tools-0.0.3-py3-none-any.whl
| Download URL | encoding_tools-0.0.3-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a54385750b1610d71ab16e706905bcd3abb334537da16586b748ac3326cd4f6
|
|
BLAKE2b-256 checksum How to use checksums |
b712c0a77cd173766f90dd21f3267c145480074a59e8f43614334b1f98dda709
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
|
Security for encoding-tools 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.