Skip to main content

larzarchive

zip/tar with safe extraction. Pure Python, zero dependencies.

Extracting an untrusted archive is a classic vulnerability: a member named ../../etc/cron.d/x or an absolute path escapes the destination ("Zip Slip"). larzarchive refuses those by resolving every member's real path and checking it stays inside the target - and it skips symlink/device members in tars. A clean create/extract/list API over the standard library, auto-detecting format.

from larzarchive import create, extract, listing

create("bundle.zip", "myfolder")
create("bundle.tar.gz", ["a.txt", "b.txt"])
extract("bundle.zip", "out/")        # raises UnsafeArchive on a malicious member
listing("bundle.zip")

Why

  • Safe by default. extract() validates every member's resolved path against the destination, so path-traversal ("Zip Slip") archives raise UnsafeArchive instead of overwriting files outside the target. It also skips symlink/hardlink/ device entries in tars. (safe=False is a documented escape hatch.)
  • One API, every format. zip, tar, tar.gz, tar.bz2, tar.xz - detected from the filename. create takes a directory, a single file, or a list of paths (or (path, arcname) pairs).
  • Zero dependencies. A thin, hardened layer over zipfile/tarfile.

Install

pip install larzarchive

Usage

from larzarchive import create, extract, listing

create("release.tar.gz", "dist")               # a directory
create("files.zip", ["a.txt", "b.txt"])         # a list of files
listing("release.tar.gz")                       # -> member names
paths = extract("release.tar.gz", "unpacked/")  # safe; returns extracted paths

Tests

python -m unittest discover -s tests -v   # 7 tests incl. zip-slip + tar-slip rejection

The Larz stack

One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.

License

MIT (c) larz-scripter

Download files

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

Source Distribution

larzarchive-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

larzarchive-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file larzarchive-0.1.0.tar.gz.

File metadata

  • Download URL: larzarchive-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzarchive-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f79201741badf3a9cb44606065fa5334147f78dbb566979111f4d730166e0e1e
MD5 89c7e56637394fa7b7743ab7fcbaad49
BLAKE2b-256 44e12647d9fad037a658027c8baecb0de9b5abaf3a7d811cb52c144e4daac6e4

See more details on using hashes here.

File details

Details for the file larzarchive-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larzarchive-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzarchive-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ace58a815a5b5a1628c0f7ef6016edfff8f413dfc565bb252e20b9aa2c7e05a
MD5 f7505d6e922741af71882b4d18c228b2
BLAKE2b-256 4c100410780724fc9ac78f6a9f4536d2f8350497fe7daa72296f8d124c4792f5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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