Python 3: working with files and digital assets/File/Compression

Compression of files

edit

Compression of entire directories

edit
from shutil import make_archive
def main():
    directory_to_save: str = 'C:\\Data_dir'
    output_to: str = 'C:\\Archived.zip'

    archive_location: str = make_archive(
        output_to,
        'zip',
        directory_to_save
    )


if __name__ == '__main__':
    main()

Compression with ZipFile

edit
from zipfile import ZipFile
def main():
    with ZipFile('test.zip', 'w') as object:
        object.write('D:\\main.py', 'main.py')


if __name__ == '__main__':
    main()