untar
Fast, safe, streaming extraction of tar archives that distribute software, in a single pure Python module without dependencies, for Python 3.6 and later.
import untar
# Extract an archive, from a path or any readable binary stream
untar.extract("pkg.tar.gz", "/opt/pkg")
# Extract the dir that contains `.meta`, wherever it is in the archive
root = untar.extract("pkg.tar.gz", "/opt/pkg", root_marker=".meta")
Scope
untar is for installing software from archives, not for restoring backups. Owners, groups,
timestamps and permissions recorded in an archive describe the machine it was made on; on
another machine they are meaningless at best and a liability at worst. So untar does not
restore them: files are created with file_mode (without executable bits where the archive
has none for the owner), dirs with dir_mode, optionally with group gid, and only regular
files, dirs, symlinks and hardlinks are extracted.
Features
- One pass. The archive is read front to back once, without seeking, from a file, pipe or network stream. Gzip is detected from the first bytes.
- Less work per member. Only the header fields that extraction needs are parsed (ustar,
pax and GNU long names), and a file costs an
open,writes and aclose. - A root only known from the contents. With
root_marker, the parent of the shallowest member with that name is extracted, liketar --strip-componentswith a count that is only known after the last member. - No path length limits. Entries are created relative to open dir file descriptors, so no path longer than one name is passed to the operating system.
Safety
Nothing is written outside the destination, whatever the archive contains. Absolute names and
.. are rejected, dirs are opened with O_NOFOLLOW so nothing is written through a symlink,
and files are created with O_EXCL | O_NOFOLLOW so existing entries are never replaced.
Symlinks may point anywhere, but untar never follows them. On Windows, which has no dir file
descriptors, these checks are path based and not safe against concurrent changes.
Archives that tar implementations read differently are rejected, so that no member can hide from one of them: numbers must be plain digits, a member's name and size come from one header only, and global pax headers cannot set them. The gzip checksum is always verified.
Development
$ pip install -e '.[dev]'
$ python tests/vendor/fetch_cpython_testdata.py cpython-testdata
$ UNTAR_CPYTHON_TESTDATA=cpython-testdata pytest
$ ruff check && ruff format --diff && mypy
tests/vendor/test_cpython.py is adapted from CPython's test_tarfile.py and is under the PSF
License Agreement included in it. The rest of untar is under the MIT license.
Metadata
Release files for untar 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| untar-0.1.0.tar.gz | 22.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| untar-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.8 kB
Release files / untar-0.1.0.tar.gz
| Download URL | untar-0.1.0.tar.gz |
|---|---|
| Size | 22.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b9e63ac5b3274c6b00784961a8432088c151980cf10b15831db0030321b992e
|
|
BLAKE2b-256 checksum How to use checksums |
6806e776cd2c8d68b15366faa1e051327e0cfbc8367f820b17a1a76ceaa177a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logRelease files / untar-0.1.0-py3-none-any.whl
| Download URL | untar-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
067a0c8a66532c1aedda0abc4e60357e6850b726fec7fd88167d6ed372aecb17
|
|
BLAKE2b-256 checksum How to use checksums |
a05c5c52afbc14adef66194fa8097a5c623bf6dfd036a664e8ddba5082068922
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logSecurity for untar 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for untar-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.