Use python-magic
to do the fingerprinting.
The library can determine file type from bytes data only:
import magic
magic.from_buffer(start_data_from_something)
The library provides access to the libmagic
file type identification library, which also drives the UNIX file
command.