unisafe
A stand-in replacement for builtins.open to read unknown or mixed text file encodings into UTF-8.
Optionally automatically converts UTF-8 or Windows-1252 smart quotes into UTF-8 or ASCII.
from unisafe import uread
# API is same as builtins.open, use read() for all lines
with uread('file.csv') as f:
lines = f.read()
# Use an iterator to get each text line
with uread('file.csv') as f:
for line in f:
print(line)
The uread function returns a TextIOWrapper, just like Python's built-in open
(when using the 'r' mode). API behavior is exactly the same as the built-in method, besides the additional runtime encoding detection and conversions.
A file handle will opened in the 'rb' or read binary mode. Writing is not supported.
from unisafe import uread
f1 = open('test.txt', 'r', encoding='utf-8')
type(f1)
# -> _io.TextIOWrapper
f2 = uread('test.txt')
type(f2)
# -> _io.TextIOWrapper
Works with the csv library and third party libraries such as pandas
from unisafe import uread
import pandas as pd
import csv
with uread('file.csv') as f:
table = csv.reader(f)
with uread('file.csv') as f:
df = pd.read_csv(f, encoding='utf-8')
License
The code in this project is released under the MIT License.
Metadata
Release files for unisafe 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| unisafe-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for unisafe-0.1.0-py3-none-any.whl |
Release files / unisafe-0.1.0-py3-none-any.whl
| Download URL | unisafe-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6863c0bb4d95d7fec9f1abeda9f04aff9b6af032552e8716a868dff335719d0
|
|
BLAKE2b-256 checksum How to use checksums |
885da3febd547a9b0012f16207dedd9bc2b35d558a626dae6f496923c84dbfa8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Security for unisafe 0.1.0
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.