
Aspose.ZIP for Python via .NET
Python API to Create & Manage ZIP, RAR & TAR Archives
Python Compression API to Create Archives or Decompress Archives of types ZIP, 7Zip, RAR, TAR, GZIP, BZ2, LZ, CPIO, XZ, Z, CAB in Python Apps.
What is Aspose.ZIP for Python via .NET?
Aspose.ZIP for Python via .NET provides a powerful data compression and archive management solution, enabling software developers to optimize data storage and transmission within Python applications. By integrating seamlessly with .NET, it bridges two programming environments, offering a versatile toolkit for managing numerous archive formats including ZIP, 7Zip, RAR, TAR, GZIP, BZ2, LZ, CPIO, XZ, Z, and CAB. This library supports essential functionalities such as creating, editing, and compressing multiple files, as well as decompressing folders, extracting archives, and applying password protection or encryption.
Key features empower software developers to enhance application efficiency through flexible compression algorithms, process tracking, and direct file modifications within archives. The integration with the .NET framework ensures optimal compression ratios and performance, while comprehensive documentation simplifies implementation. Ultimately, Aspose.ZIP for Python via .NET equips developers to improve user experience by incorporating robust compression, decompression, and archive management capabilities directly into their Python projects.
Getting Started with Aspose.ZIP for Python via .NET
The recommend way to install Aspose.ZIP for Python via .NET is using pypi.org. Please use the following command for a smooth installation.
Install Aspose.ZIP via NuGet Command
pip install aspose-zip You can download the library directly from Aspose.ZIP product page.
Compression and Decompression via Python API
Aspose.ZIP for Python via .NET enables software engineers to compress as well as decompress various types to files inside their Python applications. The library allows software developers to compress multiple files and folders into various archive formats such as ZIP, 7Zip, RAR, TAR, GZIP, BZ2, GZIP, LZ, CPIO, XZ, and may more. Similarly, it provides the capability to extract compressed files from these archives. This feature is particularly useful when dealing with large sets of files that need to be shared or stored efficiently. The following example shows how software developers can create a compressed ZIP archive with just a couple of lines of Python code.
How to Create a Compressed ZIP Archive using Python?
import clr
clr.AddReference("Aspose.Zip")
from Aspose.Zip import Archive, ArchiveUpdateAction, CompressionLevel
# Create an instance of Archive
archive = Archive()
# Add files and folders to the archive
archive.CreateEntry("file.txt")
archive.CreateEntry("folder/")
# Set compression level
archive.CompressionLevel = CompressionLevel.Normal
# Save the archive
archive.Save("example.zip")
Encryption and Password Protection Support
Security is paramount when dealing with sensitive data. Aspose.ZIP for Python via .NET makes it easy for software engineers to apply encryption or password protection while compressing or decompressing various types of files and folders inside their Python applications, ensuring that only authorized individuals can access the data within them. The library supports encrypting as well as decrypting whole archive or specific entries inside an archive. It supports various archive encryption technique such as ZipCrypto, AES encryption and various others.
Archive Manipulation Support via Python API
Aspose.ZIP for Python via .NET is a very useful API that allows software developers to create and manage various types of archives using Python commands. The library offers methods for adding, updating, and deleting files within existing archives without having to extract and re-compress the entire archive. This not only saves time but also reduces the risk of data loss.
Create Self-extracting Compressed Archives via Python
Aspose.ZIP for Python via .NET has provided a very useful features for creating and managing self-extracting compressed archives using Python. A self-extracting (SFX) archive is an executable file with an embedded archive that can be extracted automatically after launch. It creates a self-extracting ZIP archive with just a couple lines of code and supports features like adding files to it, setting password, running self-extracting archive and many more. The following code demonstrates how to use the Aspose.ZIP library to create a self-extracting archive with specific properties, such as the title and the default extraction location.
How to Create a Self-Extracting Archive via Python API?
import clr
clr.AddReference("Aspose.Zip")
from Aspose.Zip import ZipFile, CompressionLevel, SelfExtractorFlavor
def create_self_extracting_archive(source_directory, output_path):
with ZipFile() as zip:
# Add files from the source directory to the ZIP archive
zip.AddDirectory(source_directory)
# Set the SelfExtractorFlavor to create a self-extracting archive
zip.SelfExtractorFlavor = SelfExtractorFlavor.Exe
# Set optional self-extractor properties
zip.SelfExtractorExeOptions.Title = "Self-Extracting Archive"
zip.SelfExtractorExeOptions.DefaultExtractLocation = "Extracted_Files"
# Save the self-extracting archive
zip.SaveSelfExtractor(output_path, "password123") # Set a password if desired
# Usage
create_self_extracting_archive("source_directory", "self_extracting_archive.exe")
