Welcome to dispatches-data-packages’s documentation!#

API Reference#

dispatches_data.api.discovered(parent: str = 'dispatches_data.packages') Dict[str, PackageInfo]#

Get information about data packages that have been discovered in the current environment.

Returns:

A dict whose keys are the discovered data package directory’s name, and the values are PackageInfo instances for that data package.

dispatches_data.api.files(spec: str | PackageInfo | module, pattern: str = '**/*', relative: bool = False) List[Path]#

Get absolute paths to files inside a data package.

Only files (as opposed to directories) are returned.

By default, all files from all subdirectories are returned. The pattern argument can be specified to only return files matching the pattern.

Important

Note that certain patterns (most importantly the recursive directory pattern **) only match directories, rather than files, and therefore (somewhat counter-intuitively) might cause an empty list to be returned (since this function filters out directory paths from the result). In general, to match files, the ** pattern must be used in combination with at least a path separator and *. See e.g. the pattern matching all files recursively (which is the default): **/*.

Parameters:
  • spec – The data package specified in any of the supported ways (see path())

  • pattern – A glob pattern (as supported by glob or pathlib.Path.glob())

  • relative – If given, the returned paths will be relative to the data package directory

Returns:

Absolute paths of files found within the data package as a list of pathlib.Path objects.

dispatches_data.api.path(package: module, resource: str | None = None) Path#
dispatches_data.api.path(info: PackageInfo, resource: str | None = None) Path
dispatches_data.api.path(key: str, resource: str | None = None) Path

Get the absolute path to a data package as a pathlib.Path object.

The data package can be specified as any of the supported types (via functools.singledispatch()).

Parameters:
  • package – The data package, as one of the supported types

  • resource – If given, it must refer to a file (not a directory) located inside the data package directory (not in a subdirectory). If the file specified by resource is found, its path (rather than the package directory’s path) will be returned

Returns:

Absolute path to the data package or to the file specified by resource contained inside it.