import os, zipfile def deflate(paths, zip_path): z = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED, allowZip64=True, compresslevel=9) for path in paths: path = os.path.normpath(path) if os.path.isfile(path): z.write(path, path.split(os.sep)[-1]) elif os.path.isdir(path): for root, dirnames, filenames in os.walk(path): for filename in filenames: full_path = os.path.join(root, filename) arcname = full_path[len(path):].strip(os.sep) z.write(path, arcname) z.close()