To create a zip archive of a directory you can use the shutil.make_archive() the function which supports the zip format. Below is the code for the same.
import shutil
shutil.make_archive(output_filename, 'zip', dir_name)
Another way is by using the zipfile. Below I have given the code that shows you how it can be used:
#!/usr/bin/env python
import os
import zipfile
def zipdir(path, ziph):
for root, dirs, files in os.walk(path):
for file in files:
ziph.write(os.path.join(root, file))
if __name__ == '__main__': #This is driver code
zipf = zipfile.ZipFile('Python.zip', 'w', zipfile.ZIP_DEFLATED)
zipdir('tmp/', zipf)
zipf.close()