Alpha Input/Output Components

API Documentation

pyterrier_alpha.io.finalized_open(path, mode)[source]

Opens a file for writing, but reverts it if there was an error in the process.

Return type:

IO

Parameters:
  • path (str) – Path of file to open

  • mode (str) – Either t or b, for text or binary mode

Example

Returns a contextmanager that provides a file object, so should be used in a “with” statement. E.g.:

with pta.io.finalized_open("file.txt", "t") as f:
    f.write("some text")
# file.txt exists with contents "some text"

If there is an error when writing, the file is reverted:

with pta.io.finalized_open("file.txt", "t") as f:
    f.write("some other text")
    raise Exception("an error")
# file.txt remains unchanged (if existed, contents unchanged; if didn't exist, still doesn't)
pyterrier_alpha.io.finalized_directory(path)[source]

Creates a directory, but reverts it if there was an error in the process.

Return type:

str

pyterrier_alpha.io.download(url, path, *, expected_sha256=None, verbose=True)[source]

Downloads a file from a URL to a local path.

Return type:

None

pyterrier_alpha.io.download_stream(url, *, expected_sha256=None, verbose=True)[source]

Downloads a file from a URL to a stream.

Return type:

IOBase

pyterrier_alpha.io.open_or_download_stream(path_or_url, *, expected_sha256=None, verbose=True)[source]

Opens a file or downloads a file from a URL to a stream.

Return type:

IOBase

pyterrier_alpha.io.entry_points(group)[source]

Returns the entry points for a given group.

Return type:

Tuple[EntryPoint, ...]

pyterrier_alpha.io.pyterrier_home()[source]

Returns pyterrier’s home directory. By default this is ~/.pyterrier, but it can also be set with the PYTERRIER_HOME env variable.

Return type:

str

class pyterrier_alpha.io.HashReader(reader, *, hashfn=<built-in function openssl_sha256>, expected=None)[source]

A reader that computes the sha256 hash of the data read.

Create a HashReader.

class pyterrier_alpha.io.HashWriter(writer, *, hashfn=<built-in function openssl_sha256>)[source]

A writer that computes the sha256 hash of the data written.

Create a HashWriter.

class pyterrier_alpha.io.TqdmReader(reader, *, total=None, desc=None, disable=False)[source]

A reader that displays a progress bar.

Create a TqdmReader.

class pyterrier_alpha.io.CallbackReader(reader, callback)[source]

A reader that calls a callback with the data read.

Create a CallbackReader.

class pyterrier_alpha.io.MultiReader(readers)[source]

A reader that reads from multiple readers in sequence.

Create a MultiReader.