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!

PyZip is a package for handling zip-in-memory content as a dictionary.

Project Description

PyZip is a package for managing a zip content as a dictionary.

Is this zipping process simple enough?

>>> from pyzip import PyZip
>>> pyzip = PyZip()
>>> pyzip['key1'] = b"content_bytes"
>>> pyzip['key2'] = file_bytes
>>> zip_bytes = pyzip.to_bytes() # Alternatively, to bytes

It is run on top of the module zipfile, however, in addition to its functionality, PyZip accepts to edit and remove elements of a zip. Furthermore, it provides integrity checks to ensure that elements are successfully stored (SHA256 hash).


Currently it is only supported Python 3.4.1 onwards:

sudo pip3 install pyzip

Basic Usage

PyZip can easily store content into a zip on the fly. The usage is the same as a normal dictionary:

  • Add content to in-memory zip:
>>> from pyzip import PyZip
>>> pyzip = PyZip()
>>> pyzip['key1'] = b"content_bytes"
  • Get specific content:
>>> print(pyzip['key1'])
  • Edit content:
>>> pyzip['key1'] = b"replaced_content_bytes"
  • Remove content:
>>> del pyzip['key1']
  • Get zip bytes:
>>> zip_bytes = pyzip.to_bytes()
  • Load from bytes:
>>> pyzip = PyZip().from_bytes(zip_bytes)
  • Save to zip file:
  • Load from zip file:
>>> pyzip = PyZip().from_file("path/to/")
  • Convert existing dictionary into PyZip:
>>> pyzip = PyZip({'file1': b'example', 'file2': b'example2'})
  • It is also possible to convert a multiple level dict into a PyZip:
>>> pyzip = PyZip({'file1': b'example', 'file2': b'example2', 'folder1': {'file1': b'file1 in folder1'}})

Use case

PyZip can be used in along with PyFolder in order to ease the compression and decompression of folders and zips:

Compressing recursively a folder into a zip:

>>> from pyzip import PyZip
>>> from pyfolder import PyFolder
>>> path_to_compress = "route/to/files"
>>> pyzip = PyZip(PyFolder(path_to_compress, interpret=False))

Uncompressing recursively a previously compressed folder from a zip:

>>> from pyzip import PyZip
>>> from pyfolder import PyFolder
>>> destination = "route/for/uncompress"
>>> pyzip = PyZip(PyFolder(destination, interpret=False)).from_file("", inflate=False)


It is released under the MIT license.

Release History

This version
History Node


History Node


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.3 kB) Copy SHA256 Hash SHA256
Source None Oct 8, 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