Skip to main content

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.

  1. Without optional dependencies:

    pip install archivefile
    
  2. With optional dependencies:

  3. With all dependencies:

    pip install archivefile[all]
    

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("../source.zip") as archive:
    archive.extract("pyproject.toml", destination="./dest/") # Extract a single member by it's name
    archive.extractall(destination="./dest/") # Extract all members
    archive.get_member("pyproject.toml")  # Get the ArchiveMember object for the member by it's name
    archive.get_members()  # Retrieve all members from the archive as a generator of ArchiveMember objects
    archive.get_names()  # Retrieve names of all members in the archive as a tuple of strings
    archive.read_bytes("pyproject.toml") # Read the contents of the member as bytes
    archive.read_text("pyproject.toml")  # Read the contents of the member as text
    archive.print_tree()  # Print the contents of the archive as a tree.
    archive.print_table()  # Print the contents of the archive as a table.

with ArchiveFile("../source.zip", "w") as archive:
    archive.write("foo.txt", arcname="bar.txt")  # Write foo.txt to the archive as bar.txt
    archive.writeall("./src/") # Recursively write the ./src/ directory to the archive
    archive.write_text("spam and eggs", arcname="recipe.txt") # Write a string to the archive as recipe.txt
    archive.write_bytes(b"0101001010100101", arcname="terminator.py")  # Write bytes to the archive as terminator.py

Docs

Checkout the complete documentation here.

License

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

Metadata

Release files for archivefile 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for archivefile 1.0.0
File Size Uploaded
archivefile-1.0.0.tar.gz 15.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for archivefile 1.0.0
File Interpreter ABI Platform
archivefile-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.1 kB

Release files / archivefile-1.0.0.tar.gz

Download URL archivefile-1.0.0.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bae4b6d02d4cd4c918446a76081180752125e57093694768e31fb9ed1e7da4cf
BLAKE2b-256 checksum
How to use checksums
6e3a81467c79572b654773da7ce4b6e9d52b14678e8b96a403e943e1ab044e13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1024-azure

Release files / archivefile-1.0.0-py3-none-any.whl

Download URL archivefile-1.0.0-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60d3bafd71abdfba4c301262345bfe3ff2381c0c7c4a73f072e0b85cf36209b0
BLAKE2b-256 checksum
How to use checksums
c0d2d2173f334db21c29fcc9d848f2a4145bd660f2dae9a8ee649d5c3fc7a09b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1024-azure

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page