zipfile – Read and write ZIP archive files - Python Module of the Week
Always use with zipfile.ZipFile(...) as zipf: to ensure the file is closed properly, even if errors occur.
This is essential for adding new files to an existing archive without destroying the previous contents. Best Practices for Python Zipping
If you need to compress files rather than just archive them, use compression=zipfile.ZIP_DEFLATED when opening the ZipFile .