unrar

raw JSON →
0.4 verified Fri May 01 auth: no python maintenance

Python bindings for the UnRAR library using ctypes. Provides read-only access to RAR archives with extraction and listing capabilities. Current version 0.4 (stalled). Released on PyPI but no active development. The package wraps the UnRAR DLL/shared library from RARLab.

pip install unrar
error ImportError: No module named unrar
cause The package unrar is not installed.
fix
Run: pip install unrar
error unrar.rarfile.RarCannotExec: Cannot find unrar library
cause UnRAR shared library not found in system PATH or LD_LIBRARY_PATH.
fix
Install unrar: apt-get install unrar (Linux), brew install unrar (macOS). For Windows, ensure unrar.dll is in PATH.
error OSError: [WinError 193] %1 is not a valid Win32 application
cause Trying to use 64-bit Python with 32-bit unrar.dll (or vice versa).
fix
Ensure the architecture of unrar.dll matches your Python interpreter.
error unrar.rarfile.RarFileError: RAR archive is corrupt
cause The RAR file is damaged or not a valid archive.
fix
Verify the archive using external tools (unrar t file.rar).
gotcha UnRAR shared library must be installed separately. The Python package does not include the native library.
fix Install unrar-free (Linux: apt-get install unrar, macOS: brew install unrar). On Windows, place unrar.dll in PATH.
gotcha The package is unmaintained (last release 2013). May have compatibility issues with newer Python versions or platforms.
fix Consider alternatives like patool or rarfile (pure Python).
gotcha RarFile does not support writing. It is read-only.
fix Use a different library for creating RAR archives (e.g., patool with external unrar).
gotcha The unrar module must be importable; sometimes missing because of PYTHONPATH or install issues.
fix Ensure pip install unrar succeeded and the package is in sys.path.

List contents of a RAR file using RarFile as a context manager.

import os
from unrar import rarfile
rar_path = 'example.rar'
if not os.path.exists(rar_path):
    print('Place a RAR file named example.rar in the current directory.')
else:
    with rarfile.RarFile(rar_path) as rf:
        for info in rf.infolist():
            print(info.filename)