To open a gzip-compressed file in python, you can use gzip.open() function with "rt" as the mode argument.
E.g.
with gzip.open(inpfile, "rt") as fin:
The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', 'wb', 'x' or 'xb' for binary mode, or 'rt', 'at', 'wt', or 'xt' for text mode. The default is 'rb'.