python-chardetを使った文字コード推定
使い方
>>> import chardet
>>> s = 'こんにちは'
>>> chardet.detect(s)
{'confidence': 0.9690625, 'encoding': 'utf-8'}
>>> s.decode(chardet.detect(s)['encoding'])
u'\u3053\u3093\u306b\u3061\u306f'
リンク
chardet · PyPI
https://pypi.org/project/chardet/
GitHub – chardet/chardet: Python 2/3 compatible character encoding detector.
https://github.com/chardet/chardet