code: def compress(data, compresslevel=9):
      
      buf = io.BytesIO()
      with GzipFile(fileobj=buf, mode='wb', compresslevel=compresslevel) as f:
          f.write(data)
      return buf.getvalue()
docs: Compress data in one shot and return the compressed string.
      Optional argument is the compression level, in range of 0-9.