A file interface for handling local and remote data files.
The goal of datasource is to abstract some of the file system operations when dealing with data files so the researcher doesn't have to know all the low-level details. Through datasource, a researcher can obtain and use a file with one function call, regardless of location of the file.
DataSource is meant to augment standard python libraries, not replace them. It should work seamlessly with standard file IO operations and the os module.
DataSource files can originate locally or remotely:
DataSource files can also be compressed or uncompressed. Currently only gzip, bz2 and xz are supported.
Example:
>>> # Create a DataSource, use os.curdir (default) for local storage. >>> from numpy import DataSource >>> ds = DataSource() >>> >>> # Open a remote file. >>> # DataSource downloads the file, stores it locally in: >>> # './www.google.com/index.html' >>> # opens the file and returns a file object. >>> fp = ds.open('http://www.google.com/') # doctest: +SKIP >>> >>> # Use the file as you normally would >>> fp.read() # doctest: +SKIP >>> fp.close() # doctest: +SKIP
Class | _FileOpeners |
Container for different methods to open (un-)compressed files. |
Class | Repository |
Repository(baseurl, destpath='.') |
Function | _check_mode |
Check mode and that encoding and newline are compatible. |
Function | open |
Open path with mode and return the file object. |
Variable | _file_openers |
Undocumented |
Check mode and that encoding and newline are compatible.
Open path
with mode
and return the file object.
If path is an URL, it will be downloaded, stored in the
DataSource
destpath
directory and opened from there.
path
. Mode 'r' for reading, 'w' for writing, 'a' to
append. Available modes depend on the type of object specified by
path. Default is 'r'.destpath
is None, a temporary directory will be created.
The default path is the current directory.io.open
uses.This is a convenience function that instantiates a DataSource
and
returns the file object from DataSource.open(path).