Pure python mimesniff implementation of https://mimesniff.spec.whatwg.org
API interface is similar with API of python standard library
pip install mimesniff
import mimesniff
res = mimesniff.what('sample.mp3')
print(res)
# audio/mpeg
with open('sample.mp3', 'rb') as fin:
res = mimesniff.what(fin)
print(res)
# audio/mpeg
with open('sample.mp3', 'rb') as fin:
header = fin.read(512)
res = mimesniff.what(header)
print(res)
# audio/mpeg