Skip to main content

Automatically compress or decompress files on open by filename.

Project description

autoopen

autoopen is a small drop-in replacement for the most common use cases of Python’s built-in open() function that will automatically handle compressed files based on the filename.

Usage

For example:

from autoopen import autoopen

filename = "example.txt.xz"
with autoopen(filename, "rt", encoding="utf-8") as file:
    contents = file.read()

autoopen will check the given filename’s last suffix. If it indicates one of the supported compressors, the corresponding compressor or decompressor will be used, otherwise it falls back to built-in open.

Support for .gz, .bz2, .xz, .lzma, and .zst/.zstd is built-in (the latter requires the python-zstandard package). The special filename - indicates reading from stdin or writing to stdout.

Project details


Download files

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

Source Distribution

autoopen-0.1.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

autoopen-0.1.0-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page