pyzip 0.2.0
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
>>>
>>> pyzip.save("/path/to/file.zip")
>>> 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).
Installation
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'])
b"content_bytes"
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:
>>> pyzip.save("path/to/file.zip")
Load from zip file:
>>> pyzip = PyZip().from_file("path/to/file.zip")
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))
>>> pyzip.save("compressed_folder.zip")
>>>
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("compressed_folder.zip", inflate=False)
>>>
LICENSE
It is released under the MIT license.
Metadata
Release files for pyzip 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyzip-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for pyzip-0.3.0-py3-none-any.whl |
Release files / pyzip-0.3.0-py3-none-any.whl
| Download URL | pyzip-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce5d9dd4514f09eaf5bfcc0a6b53d03b5ca92ec8dc71ee54ad6cfc5d3d07e4ae
|
|
BLAKE2b-256 checksum How to use checksums |
977b22676dcc1eab14509528863b9a429befc2a2b6ad79e41d2eb9e254141296
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.32.3 rfc3986/1.5.0 tqdm/4.66.4 urllib3/1.26.5 CPython/3.10.12
|
Security for pyzip 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.