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

Python convenience function for opening compressed URLs and files.

Project Description

Python convenience function canopener(filename, mode='r') for opening files.

Local files behave identically to open():

>>> canopener('local_file.txt')

URLs can also be passed as the filename and opened for reading. urllib2.urlopen() is used under the covers, so it has equivalent support:

>>> canopener('http://remote/file.txt')

S3 URLs can also be read if the boto module is installed and the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are set. The file is downloaded to a temporary local file on open:

>>> os.environ['AWS_ACCESS_KEY_ID'] = 'key'
>>> os.environ['AWS_SECRET_ACCESS_KEY'] = 'secret'
>>> canopener('s3://bucket/file.txt')

Any paths with “.gz” or “.bz2” extensions are transparently decompressed:

>>> canopener('local_file.txt.gz')
>>> canopener('local_file.txt.bz2')
>>> canopener('http://remote/file.txt.gz')
>>> canopener('s3://bucket/file.txt.gz')

There’s also transparent compression when writing to local files:

>>> canopener('local_file.txt.gz', 'w')
Release History

Release History

This version
History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

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
canopener-0.1.6.tar.gz (3.9 kB) Copy SHA256 Checksum SHA256 Source Apr 13, 2015

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