archive-path
A package to provide pathlib like access to zip & tar archives.
Installation
$ pip install archive-path
Usage
For reading zip (ZipPath) or tar (TarPath) files:
from archive_path import TarPath, ZipPath
path = TarPath("path/to/file.tar.gz", mode="r:gz")
sub_path = path / "folder" / "file.txt"
assert sub_path.filepath == "path/to/file.tar.gz"
assert sub_path.at == "folder/file.txt"
assert sub_path.exists() and sub_path.is_file()
assert sub_path.parent.is_dir()
content = sub_path.read_text()
for sub_path in path.iterdir():
print(sub_path)
For writing files, you should use within a context manager, or directly call the close method:
with TarPath("path/to/file.tar.gz", mode="w:gz") as path:
(path / "new_file.txt").write_text("hallo world")
# there are also some features equivalent to shutil
(path / "other_file.txt").putfile("path/to/external_file.txt")
(path / "other_folder").puttree("path/to/external_folder", pattern="**/*")
Note that archive formats do not allow to overwrite existing files (they will raise a FileExistsError).
For performant access to single files:
from archive_path import read_file_in_tar, read_file_in_zip
content = read_file_in_tar("path/to/file.tar.gz", "file.txt", encoding="utf8")
These methods allow for faster access to files (using less RAM) in archives containing 1000's of files.
This is because, the archive's file index is only read until the path is found (discarding non-matches),
rather than the standard tarfile/zipfile approach that is to read the entire index into memory first.
Windows compatibility
Paths within the archives are always read and written as being / delimited.
This means that the package works on Windows,
but will not be compatible with archives written outside this package with \\ path delimiters.
Development
See CONTRIBUTING.md for details on how to contribute to this package.
Metadata
Release files for archive-path 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| archive-path-0.4.2.tar.gz | 19.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| archive_path-0.4.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.3 kB
Release files / archive-path-0.4.2.tar.gz
| Download URL | archive-path-0.4.2.tar.gz |
|---|---|
| Size | 19.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
75279003ea986a4f6748e299ba74d95e74ad75f1bd3ae02d35c125c749633a51
|
|
BLAKE2b-256 checksum How to use checksums |
f5cda4f37a093bcc424293c9eec88a20ff1881ad1983ebb7c7f95d4428981371
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.28.1
|
Release files / archive_path-0.4.2-py3-none-any.whl
| Download URL | archive_path-0.4.2-py3-none-any.whl |
|---|---|
| Size | 18.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
664909adb5b29c25f0c3e669637e2fa0f010b6458e6920d4e87a8c395ae5e93d
|
|
BLAKE2b-256 checksum How to use checksums |
75ff0c802d4d776db24570b309bfae4d15e3c3246c78b96bcc87893fe6979de9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.28.1
|