Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

improvements over the standard zipfile package

Project Description

package ruamel.std.zipfile is a drop-in improvements over the standard zipfile package

You can just replace:

import zipfile


import ruamel.std.zipfile as zipfile

The package includes InMemoryZipFile, which allows easy creation of ZIP files in memory, and allows for streaming or writing out to disc after full creation:

with InMemoryZipFile() as imz:
    imz.append("test.txt", "Another test").append("test2.txt", "Still another")
    with open('', 'wb') as fp:

which will write a two file ZIP file, the first file of which is named test.txt with content Another test. The .data content can also be dynamically returned to a web browser, etc.

File deletion from ZIP

Taking advantage of the delayed writing of InMemoryZipFile, the function delete_from_zip_file(file_name, pattern, file_names), takes a string or pathlib.Path as file_name.

Any files matching the pattern, if provided, are deleted from the file, as well as are any files matching file_names (a list of string/Path, single non-list instances are allowed).

The following deletes any files ending in .pth and the file tmp/README.rst from a ZIP file

delete_from_zip_file('', pattern='.*.pth', file_names=['README.rst'])


delete_from_zip_file('', pattern='.*.pth', file_names='README.rst')


delete_from_zip_file('', pattern=re.compile('.*.pth'), file_names='README.rst')

Please note that this a ``re`` pattern not a ``glob`` pattern. You can, but don’t have to provide a pattern compiled with re.compile()

The ZIP file is recreated and recompressed, take this into account when deleting files (restrict the size of files you handle, combine patterns instead of doing multiple calls).

Release History

This version
History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(6.5 kB) Copy SHA256 Hash SHA256
Wheel py2.py3 Jan 1, 2017
(11.3 kB) Copy SHA256 Hash SHA256
Source None Jan 1, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers DreamHost DreamHost Log Hosting