Create an encrypted ZIP file in Python
<p>I'm creating an ZIP file with ZipFile in Python 2.5, it works ok so far:</p>

<pre><code>import zipfile, os

locfile = "test.txt"
loczip = os.path.splitext (locfile)[0] + ".zip"
zip = zipfile.ZipFile (loczip, "w")
zip.write (locfile)
zip.close()
</code></pre>

<p>but I couldn't find how to encrypt the files in the ZIP file.
I could use system and call PKZIP -s, but I suppose there must be a more "Pythonic" way.  I'm looking for an open source solution.</p>

<p>I created a simple library to create a password encrypted zip file in python. - <a href="https://github.com/smihica/pyminizip"><strong>here</strong></a></p>

<pre><code>import pyminizip

compression_level = 5 # 1-9
pyminizip.compress("src.txt", "dst.zip", "password", compression_level)
</code></pre>

<p><strong>The library requires zlib.</strong></p>

<p>I have checked that the file can be extracted in WINDOWS/MAC.</p>
