Thursday, October 23, 2025
HomeLanguagesPython | shutil.get_unpack_formats() method

Python | shutil.get_unpack_formats() method

Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating process of copying and removal of files and directories.

shutil.get_unpack_formats() method in Python is used to get the list of all supported formats available for unpacking archived files.
Following formats are available by default for unpacking archived files:

  • zip: ZIP file. If the zlib module is available
  • tar: uncompressed tar file.
  • gztar: gzip’ed tar-file. If the zlib module is available
  • bztar: bzip2’ed tar-file. If the bz2 module is available
  • xztar: xz’ed tar-file. If the lzma module is available

We can also register new formats or specify own function for unpacking existing formats using shutil.register_unpack_format() method or deregister a existing format using shutil.unregister_unpack_format() method.

Syntax: shutil.get_unpack_formats()

Parameter: No parameter is required

Return Type: This method returns a list which represents the available formats supported for unpacking archived files. Each element of the list is a tuple (name, extension description).

Code: Use of shutil.get_unpack_formats() method




# Python program to explain shutil.get_unpack_formats() method 
    
# importing shutil module 
import shutil
  
# Get the list of 
# supported unpacking formats
formats = shutil.get_unpack_formats()
  
  
# Print the list
print("Supported unpacking formats:\n", formats)


Output:

Supported unpacking formats:
Supported unpacking formats:
 [('bztar', ['.tar.bz2', '.tbz2'], "bzip2'ed tar-file"), ('gztar', ['.tar.gz', '.tgz'], "gzip'ed tar-file"), ('tar', ['.tar'], 'uncompressed tar file'), ('xztar', ['.tar.xz', '.txz'], "xz'ed tar-file"), ('zip', ['.zip'], 'ZIP file')]

Reference: https://docs.python.org/3/library/shutil.html

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS