open_remote_file#

gwpy.io.remote.open_remote_file(
url: str,
*,
cache: bool | None = None,
show_progress: bool = False,
encoding: Literal['binary'] = 'binary',
**kwargs,
) AbstractContextManager[BinaryIO][source]#
gwpy.io.remote.open_remote_file(
url: str,
*,
cache: bool | None = None,
show_progress: bool = False,
encoding: str | None,
**kwargs,
) AbstractContextManager[TextIO]

Download a file and open it.

This function is a wrapper around astropy.utils.data.get_readable_fileobj with the following customisations:

  • Default to cache=True if the GWPY_CACHE environment variable is set to something ‘truthy’.

  • If the URL looks like a Pelican URL, hand off to a dedicated Pelican download wrapper to attempt the remote access.

Parameters:
urlstr, file-like

The name of the resource to access. Can be a local path, or a file:// URL, or any remote URL supported by Astropy.

cachebool

Whether to cache the contents of remote URLs. Default is True if the GWPY_CACHE environment variable is set to something ‘truthy’.

show_progress: `bool`, optional

Print verbose progress information to the screen.

encodingstr, optional

When 'binary' (default), returns a file-like object where its read method returns bytes objects.

When None, returns a file-like object with a read method that returns str (unicode) objects, using locale.getpreferredencoding as an encoding. This matches the default behavior of the built-in open when no mode argument is provided.

When another string, it is the name of an encoding, and the file-like object’s read method will return str (unicode) objects, decoded from binary using the given encoding.

kwargs

All other positional and keyword arguments are passed directly to astropy.utils.data.get_readable_fileobj.

Returns:
filefile-like

The file opened in binary format.

See also

astropy.utils.data.get_readable_fileobj

For details of the underlying downloader.

gwpy.io.pelican.open_remote_file

For details of the Pelican-aware download wrapper.