{"id":4376,"library":"patool","title":"patool","description":"patool is a portable archive file manager that supports a wide array of formats like 7z, RAR, ZIP, and TAR. It simplifies archive handling by abstracting away the complexities of various underlying compression programs. While it can natively handle formats like TAR, ZIP, BZIP2, LZMA, and GZIP, it often relies on helper applications installed on the system for other formats. The library is actively maintained, with frequent releases, and is currently at version 4.0.4, requiring Python 3.11 or later.","status":"active","version":"4.0.4","language":"en","source_language":"en","source_url":"https://github.com/wummel/patool","tags":["archive","compression","file-management","utility"],"install":[{"cmd":"pip install patool","lang":"bash","label":"Install patool"},{"cmd":"pip install 'patool[argcompletion]'","lang":"bash","label":"Install with Bash autocompletion"}],"dependencies":[{"reason":"Provides tab-completion for the command-line tool.","package":"argcomplete","optional":true}],"imports":[{"note":"The Python module is named `patoolib`, not `patool`.","wrong":"import patool","symbol":"patoolib","correct":"import patoolib"}],"quickstart":{"code":"import patoolib\nimport os\n\n# Create a dummy file for archiving\ndummy_file_path = 'my_document.txt'\nwith open(dummy_file_path, 'w') as f:\n    f.write('This is a test document for patool.\\n')\n    f.write('It contains some arbitrary text.')\n\narchive_name = 'my_archive.zip'\nextract_dir = 'extracted_content'\n\nprint(f\"Creating archive: {archive_name}\")\npatoolib.create_archive(archive_name, (dummy_file_path,))\n\nprint(f\"Extracting archive '{archive_name}' to '{extract_dir}'\")\nos.makedirs(extract_dir, exist_ok=True)\npatoolib.extract_archive(archive_name, outdir=extract_dir)\n\nprint(f\"Contents of '{extract_dir}':\")\nfor root, dirs, files in os.walk(extract_dir):\n    for name in files:\n        print(os.path.join(root, name))\n\n# Clean up dummy files and directory\nos.remove(dummy_file_path)\nos.remove(archive_name)\nos.remove(os.path.join(extract_dir, dummy_file_path))\nos.rmdir(extract_dir)\nprint(\"Cleaned up.\")","lang":"python","description":"This example demonstrates how to create and extract a ZIP archive programmatically using `patoolib`. It first creates a dummy text file, archives it into a .zip file, then extracts the contents to a new directory, and finally cleans up the created files and folders. Ensure you have the necessary system-level archiving tools (like `zip`/`unzip`) installed if you use formats not natively supported by patool."},"warnings":[{"fix":"Review code that might implicitly rely on `patool` failing when the primary program doesn't support a compression type. Consider explicitly specifying the `program` argument in `patoolib` functions if specific external tools are desired.","message":"Version 4.0.0 introduced a change in behavior when a program does not support a compression type; patool now tries to find other programs instead of failing. This primarily affects users relying on unofficial API usage that might have expected the previous failure mode.","severity":"breaking","affected_versions":"4.0.0 and later"},{"fix":"Install the appropriate command-line utilities for the archive formats you intend to use. For example, on Linux, `sudo apt-get install unrar p7zip-full xz-utils`. On Windows, you might need to manually install these tools and add their executable directories to your system's PATH environment variable.","message":"For many archive formats (e.g., RAR, 7z, XZ), `patool` relies on external command-line tools to be installed on the system (e.g., `unrar`, `7z`, `xz`, `tar`). Without these helper applications in the system's PATH, `patool` will raise a `PatoolError` for those formats.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `import patoolib` to access the library's functions.","message":"The correct way to import the library for programmatic use is `import patoolib`. Importing `patool` directly (e.g., `import patool`) will result in an `ImportError` or `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For non-interactive environments, set the `interactive=False` parameter in `patoolib` function calls (e.g., `patoolib.extract_archive('archive.rar', outdir='/tmp', interactive=False)`) or use the `--non-interactive` global option for the command-line tool. You can also provide passwords via the `password` argument if applicable.","message":"By default, `patoolib` functions like `extract_archive` are `interactive` (True). This means they might wait for user input if the underlying compression program requires it (e.g., for a password). In automated scripts, this can lead to indefinite hangs.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your Python environment meets the minimum `3.11` requirement. If you encounter issues with specific formats or wish to leverage the latest features, consider using Python 3.14 or newer.","message":"While `patool` requires Python >= 3.11, some advanced features or native support for certain formats may depend on newer Python versions. For instance, native support for the ZSTANDARD archive format is enabled with Python >= 3.14.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}