Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Simple library that provides a common interface for extracting zip and tar archives.

Project Description

This package provides a simple, pure-Python interface for handling various archive file formats. Currently, archive extraction is the only supported action. Supported file formats include:

  • Zip formats and equivalents: .zip, .egg, .jar.
  • Tar and compressed tar formats: .tar, .tar.gz, .tgz, .tar.bz2, .tz2.

python-archive is compatible and tested with Python versions 2.5, 2.6, and 3.2.

Example usage

Using the Archive class:

from archive import Archive

a = Archive('files.tar.gz')

Using the extract convenience function:

from archive import extract
# Extract in current directory.
# Extract in directory 'unpack_dir'.
extract('files.tar.gz', 'unpack_dir')

By default, an archive.UnsafeArchive exception will be raised if any file(s) in the archive would be unpacked outside of the target directory (e.g. the archive contains absolute paths or relative paths that navigate up and out of the target directory). If you can trust the source of your archive files, then it’s possible to override this behavior, e.g.:

extract('files.tar.gz', method='insecure')

More examples

Passing a file-like object is also supported:

f = open('files.tar.gz', 'rb')

If a file does not have the correct extension, or is not recognized correctly, you may try explicitly specifying an extension (with leading period):

Archive('files.wrongext', ext='.tar.gz').extract()
# or
extract('files.wrongext', ext='.tar.gz')

Similar tools

Release History

Release History

This version
History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
python-archive-0.2.tar.gz (9.2 kB) Copy SHA256 Checksum SHA256 Source Jul 12, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting