You can try using py7zr, which supports 7zip archive compression, decompression, encryption, decryption.
Here is a simple example to make 7-zip archive. https://py7zr.readthedocs.io/en/stable/user_guide.html#make-archive
import py7zr
with py7zr.SevenZipFile("Archive.7z", 'w') as archive:
archive.writeall("target/")