The standard python mimetype module maps file names to mime types and vice versa. To use it, you will need a file name or a mime type, in which case it will return you a possible file extension.
/ mime . . Libmagic, unix, . (https://pypi.python.org/pypi/filemagic/1.6) python libmagic.
import urllib2
import magic
img_data = urllib2.urlopen('https://www.google.com/images/srpr/logo11w.png').read()
m = magic.Magic()
print m.id_buffer(img_data)
m.close()