Skip to main content

Common interface for compressed file manipulation

Project description

compfile Common interfaces for manipulating compressed files (lzma, gzip etc)

Build Status Documentation Status Coverage Status


Sometimes, we need to deal with different compressed files. There are several packages/modules for compressed file manipulation, e.g., gzip module for "*.gz" files, lzma module for "*.lzma" and "*.xz" files, etc. If we want to support different types of compressed file in our project, probably we need to do the following:

if fnmatch.fnmatch(fname, "*.gz"):
    f =, 'rb')
    # do something with f
elif fnmatch.fnmatch(fname, "*.bz2'):
    f =, 'rb')
    # do something with f
    # other stuffs

The problems of the above approch are:

  • We need to repeat the compression type inference logic everywhere we want to support different compression types.
  • Different compression type manipulation modules may have different API convention.

compfile is designed to solve the above problems. It abstracts the logic of compressed file manipulations and provides a single high level interface for users.


Install from PyPI

pip install compfile

Install from Anaconda

conda install -c liyugong compfile

Install from GitHub

pip install git+

Simple example

Using compfile is pretty simple. Just construct a compfile.CompFile object or call

with, 'r') as f:
    # do something with f

The object returned is a file object, so we can do ordinary file processing with it.


The compfile package is released under the MIT License


Download files

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

Files for compfile, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size compfile-0.0.3.tar.gz (5.0 kB) File type Source Python version None Upload date Hashes View
Filename, size compfile-0.0.3-py2.py3-none-any.whl (3.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page