arpy
raw JSON → 2.3.0 verified Fri May 01 auth: no python
arpy is a Python library for reading and writing Unix archive (ar) files, commonly used for static libraries (.a) and Debian packages (.deb). Version 2.3.0 supports Python 3.6+. It provides a simple interface to iterate over archive members and extract or add files.
pip install arpy Common errors
error AttributeError: module 'arpy' has no attribute 'Archive' ↓
cause Importing incorrectly, e.g., 'import arpy' then using arpy.Archive instead of from arpy import Archive.
fix
Use 'from arpy import Archive'.
error TypeError: write() argument must be a bytes-like object, not 'str' ↓
cause Passing a string to Archive.write() instead of bytes.
fix
Encode string to bytes: archive.write('file.txt', 'content'.encode()).
error FileNotFoundError: [Errno 2] No such file or directory: 'test.ar' ↓
cause Trying to open a nonexistent archive for reading.
fix
Check the file path exists, or create a new archive with mode='w'.
Warnings
gotcha The Archive class context manager does not close the file on __exit__ in some versions; manually call .close() if needed. ↓
fix Explicitly call archive.close() after use, or upgrade to 2.3.0+.
gotcha Writing archives: the write() method expects bytes, not str. Passing a string will raise a TypeError. ↓
fix Ensure data is bytes: archive.write(entry_name, b'data').
breaking In version 2.0.0, the API changed from old-style (archive = Archive('file'); archive.read()) to context manager. Old code will break. ↓
fix Use 'with Archive(...) as archive:' pattern. See docs.
Imports
- Archive
from arpy import Archive
Quickstart
from arpy import Archive
with Archive('test.ar') as archive:
for entry in archive:
print(entry.name, entry.size)