
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Unified interface for tar, zip, sevenzip, and rar files
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.
archivefile
is available on PyPI, so you can simply use pip to install it.
Without optional dependencies:
pip install archivefile
With optional dependencies:
Required for ArchiveFile.print_tree()
pip install archivefile[bigtree]
Required for ArchiveFile.print_table()
pip install archivefile[rich]
With all dependencies:
pip install archivefile[all]
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
Checkout the complete documentation here.
Distributed under the Unlicense License. See UNLICENSE for more information.
FAQs
Unified interface for tar, zip, sevenzip, and rar files
We found that archivefile demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.