A compressed file can be classified into below logical groups
a. The operating system which you are working on (*ix, Win) etc.
b. Different types of compression algo
2019 update:
I was looking for a solution to detect if a .csv file was gzipped or not. The answer @Lauritz gave was throwing errors for me, i imagine it's just because the way files are read has changed in the past 7 years.
This library worked perfectly for me! https://pypi.org/project/filetype/