Create Password Protected Zip of a file using Python
ZIP is an archive file format that supports lossless data compression. By lossless compression, we mean that the compression algorithm allows the original data to be perfectly reconstructed from the compressed data. So, a ZIP file is a single file containing one or more compressed files, offering an ideal way to make large files smaller and keep related files together.
In this article, we will learn how to Create Password-Protected Zip of a file using Python. For this, we are using pyminizip module from python.
The pyminizip module can be installed using the below command:
pip install pyminizip
For creating zip, we are using compress() method from pyminizip. So, we discuss first its syntax and arguments.
pyminizip.compress(“/srcfile/path.txt”, “file_path_prefix”, “/distfile/path.zip”, “password”, int(compress_level))
- src file path (string)
- src file prefix path (string) or None (path to prepend to file)
- dst file path (string)
- password (string) or None (to create no-password zip)
- compress_level(int) between 1 to 9, 1 (more fast) <—> 9 (more compress) or 0 (default)
Return value: Always returns None
Please Login to comment...