Skip to main content

Unified interface for tar, zip, sevenzip, and rar files

Project description


Logo

Unified interface for tar, zip, sevenzip, and rar files

PyPI - Version PyPI - Python Version License Checked with mypy Ruff

GitHub Workflow Status (with event) GitHub Actions Workflow Status codecov

Table Of Contents

About

archivefile is a wrapper around tarfile, zipfile, py7zr, and rarfile.

The above libraries are excellent when you are dealing with a single archive format but things quickly get annoying when you have a bunch of mixed archives such as .zip, .7z, .cbr, .tar.gz, etc because each library has a slightly different syntax and quirks which you need to deal with.

archivefile wraps the common methods from the above libraries to provide a unified interface that takes care of said differences under the hood. However, it's not as powerful as the libraries it wraps due to lack of support for features that are unique to a specific archive format and library.

Installation

archivefile is available on PyPI, so you can simply use pip to install it.

pip install archivefile

Usage

archivefile offers a single class called ArchiveFile to deal with various archive formats. Some examples are given below:

from archivefile import ArchiveFile

with ArchiveFile("archive.tar") as archive:
    archive.extract("member.txt") # Extract a single member of the archive

with ArchiveFile("archive.zip", "w") as archive:
    archive.extractall(destination="./archive/") # Extract all members

with ArchiveFile("archive.cb7") as archive:
    archive.read_text("member.txt") # Read a member of the archive

with ArchiveFile("archive.rar") as archive:
    archive.get_members() # Get a tuple of all the members of the archive

with ArchiveFile("archive.zip", "w") as archive:
    archive.write("bar.txt") # write bar.txt to archive

Refer to the API reference for more details.

Docs

Checkout the complete documentation here.

License

Distributed under the Unlicense License. See UNLICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

archivefile-0.2.0.tar.gz (12.2 kB view hashes)

Uploaded Source

Built Distribution

archivefile-0.2.0-py3-none-any.whl (12.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page