def compress_to_gzip(local_file_name): gzip_file_name = f'{local_file_name}.gz' fp = open(local_file_name, 'rb') with gzip.open(gzip_file_name, 'wb') as gz_fp: gz_fp.write(bytearray(fp.read())) return gzip_file_name