Open compressed files transparently
Project description
xopen
This small Python module provides a xopen function that works like the built-in open function, but can also deal with compressed files. Supported compression formats are gzip, bzip2 and xz. They are automatically recognized by their file extensions .gz, .bz2 or .xz.
The focus is on being as efficient as possible on all supported Python versions. For example, simply using gzip.open is slow in older Pythons, and it is a lot faster to use a gzip subprocess.
This module has originally been developed as part of the cutadapt tool that is used in bioinformatics to manipulate sequencing data. It has been in successful use within that software for a few years.
Usage
Open a file for reading:
with open('file.txt.xz') as f: content = f.read()
Or without context manager:
f = open('file.txt.xz') content = f.read() f.close()
Open a file for writing:
with open('file.txt.gz', mode='w') as f: f.write('Hello')
Credits
The name xopen was taken from the C function of the same name in the utils.h file which is part of BWA.
Kyle Beauchamp <https://github.com/kyleabeauchamp/> has contributed support for appending to files.
Some ideas were taken from the canopener project. If you also want to open S3 files, you may want to use that module instead.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file xopen-0.1.1.tar.gz
.
File metadata
- Download URL: xopen-0.1.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1320ca46ed464a59db4c27c7a44caf5e268301e68319f0295d06bf6a9afa6f3 |
|
MD5 | 4e0e955546ee6bee4ea736b54623a671 |
|
BLAKE2b-256 | 9ab78906d6b2c4f874c0aacc676709a3d533362ac93bebc4a656c9df19421c9b |