We currently have a function, open_or_gzopen(), in util/file.py that provides a unified and somewhat flexible way to open various types of compressed files and return a file handle with an interface (largely) compatible with Python's built-in open().
We may want to consider replacing open_or_gzopen() with a call out to the more flexible and modern smart_open() function provided by the eponymous library, while preserving a function stub of open_or_gzopen() (with deprecation warning) to maintain compatibility for existing calls to open_or_gzopen().
In addition to supporting various compression types, smart_open() can also open data stored on cloud storage services like S3, GCS, and Azure.