import gzip import StringIO fileobj = StringIO.StringIO(open("t.gz").read()) print gzip.GzipFile('', 'rb', 9, fileobj).read()