code: def gzip_dir(path, compresslevel=6):
      
      for f in os.listdir(path):
          full_f = os.path.join(path, f)
          if not f.lower().endswith("gz"):
              with open(full_f, 'rb') as f_in, \
                  GzipFile('{}.gz'.format(full_f), 'wb',
                           compresslevel=compresslevel) as f_out:
                  shutil.copyfileobj(f_in, f_out)
              shutil.copystat(full_f,'{}.gz'.format(full_f))
              os.remove(full_f)
docs: Gzips all files in a directory. Note that this is different from
      shutil.make_archive, which creates a tar archive. The aim of this method
      is to create gzipped files that can still be read using common Unix-style
      commands like zless or zcat.
  
      Args:
          path (str): Path to directory.
          compresslevel (int): Level of compression, 1-9. 9 is default for
              GzipFile, 6 is default for gzip.