Python 3.2+shutilfunction
shutil.get_unpack_formats()
archives
Returns the formats unpack_archive() can unpack: (name, extensions, description) triples.
Syntax
shutil.get_unpack_formats() -> list[tuple[str, list[str], str]]
This is where unpack_archive gets its extension-to-format mapping: '.tgz' and '.tar.gz' are gztar, while the 'tar' format has just one extension, '.tar'. Like the creation formats, the set depends on the Python build (bz2, lzma, zstd). Checking a file against it is more reliable than hard-coding extensions.
Examples
import shutil
ext = {name: exts for name, exts, desc in shutil.get_unpack_formats()}
print(ext['gztar']) # → ['.tar.gz', '.tgz']
print(ext['zip']) # → ['.zip']
See also
Open in the full glossarydocs.python.orgReport an inaccuracy