How to extract Files and Folders from a Zip Archive in Python

Cloudmersive
1 min readMay 8, 2020

--

Zip archives are ubiquitous these days, making it all the more important to have compatibility for them in your project, whatever it may be. I’m guessing you don’t have hours to kill on setting this up from scratch, so I’ll be showing you the easy-as-pie method instead.

Get the Cloudmersive Documents and Conversion API client with pip install:

pip install cloudmersive-convert-api-client

We will next call zip_archive_zip_extract, which should be done using a newly instantiated API, like so:

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom cloudmersive_convert_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.ZipArchiveApi(cloudmersive_convert_api_client.ApiClient(configuration))input_file = '/path/to/file' # file | Input file to perform the operation on.try:# Extract, decompress files and folders from a zip archiveapi_response = api_instance.zip_archive_zip_extract(input_file)pprint(api_response)except ApiException as e:print("Exception when calling ZipArchiveApi->zip_archive_zip_extract: %s\n" % e)

And now you have zip extraction. Simple.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet