Как уже предлагалось в некоторых ответах, вы можете заглянуть в первые байты файла:
#!/usr/bin/env python
# $ cat hello.txt
# Hello World. I'm plaintext.
# $ cat hello.txt | gzip > hello.txt.gz
from struct import unpack
# 1F 8B 08 00 / gz magic number
magic = ('\x1f', '\x8b', '\x08', '\x00')
for filename in ['hello.txt', 'hello.txt.gz']:
with open(filename, 'rb') as handle:
s = unpack('cccc', handle.read(4))
if s == magic:
print filename, 'seems gzipped'
else:
print filename, 'seems not gzipped'
# =>
# hello.txt seems not gzipped
# hello.txt.gz seems gzipped