camel_tools.data

This sub-module contains utilities for locating datastes for the various CAMeL Tools components.

Classes

class camel_tools.data.DownloaderError(msg)

Exception raised when an error occurs during data download.

class camel_tools.data.FileEntry(path: str, sha256: str)

Data class containing information about a given file.

path: str

Relative path of file in the package directory.

sha256: str

SHA256 hash of this file.

class camel_tools.data.PackageType(value)

Enum indicating the type of a package.

HTTP = 1

Indicates package is a zip file that can be downloaded via HTTP/HTTPS.

META = 0

Indicates a package is a meta package (ie. contains no files, only dependencies)

class camel_tools.data.PackageEntry(name: str, description: str, size: int | None, version: str | None, license: str, package_type: PackageType, url: str | None, destination: Path | None, dependencies: Set[str] | None, files: List[FileEntry] | None, private: bool, sha256: str | None, post_install: dict | None)

Data class containing information about a given package.

dependencies: Set[str] | None

Names of packages this package depends on.

description: str

Description of this package

destination: Path | None

Installation path of package. Is None for meta packages.

files: List[FileEntry] | None

List of files included in this package. Is None for meta packages.

license: str

License this package is distributed under. Is None for meta packages.

name: str

Name of this package.

package_type: PackageType

Type of this package.

post_install: dict | None

Post installation steps. Is ‘None’ for packages that require no post-installation

private: bool

Indicates if this package should be hidden when being listed.

sha256: str | None

SHA256 hash of package zip file. Is None for meta packages.

size: int | None

Size of this package in bytes. Is None for meta packages.

url: str | None

URL for downlading this package’s zip file. Is None for meta packages.

version: str | None

Package version. Is None for meta packages.

class camel_tools.data.DatasetEntry(name: str, component: str, path: str)

Data class containing information about an individual dataset.

component: str

Name of the component this dataset belongs to.

name: str

Name of this dataset.

path: str

Relative path of this dataset in the data directory.

class camel_tools.data.ComponentEntry(name: str, default: str, datasets: Mapping[str, DatasetEntry])

Data class that contains dataset information for a given component.

datasets: Mapping[str, DatasetEntry]

A mapping of dataset names to their respective entries.

default: str

The default dataset name for this component.

name: str

Name of this component.

class camel_tools.data.CatalogueError(msg: str)

Exception raised when an error occurs during data download.

class camel_tools.data.Catalogue(version: str, packages: Mapping[str, PackageEntry], components: Mapping[str, ComponentEntry])

This class allows downloading and querying datasets provided by CAMeL Tools.

components: Mapping[str, ComponentEntry]

Mapping of component names with their respective entries.

download_package(package: str, recursive: bool = True, force: bool = False, print_status: bool = False)

Download and install package with a given name.

Parameters:
  • package (str) – Name of package to download and install.

  • recursive (bool, Optional) – If True, dependencies are recursively installed. Otherwise, only the package contents are installed. Defaults to True.

  • force (bool, Optional) – If True, packages that are already installed and up-to-date will be reinstalled, otherwise they are ignored. Defaults to False.

  • print_status (bool, Optional) – If True, prints out the download status to standard output. Defaults to False.

get_component(component: str) ComponentEntry

Get component entry for a given component name.

Parameters:

component (str) – Name of component to query.

Returns:

Entry associated with given component name.

Return type:

PackageEntry

Raises:

CatalogueError – When component is not a valid component name.

get_dataset(component: str, dataset: str | None = None) DatasetEntry

Get dataset entry for a given component name and dataset name.

Parameters:
  • component (str) – Name of component.

  • dataset (str, Optional) – Name of dataset for given component to query. If set to None then the entry for the default dataset will be returned. Defaults to None.

Returns:

The dataset entry for the given component and dataset names.

Return type:

DatasetEntry

static get_default_catalogue_path() Path

Returns the default catalogue path, respecting the CAMELTOOLS_DATA environment variable if it is set.

Returns:

Path to the catalogue file.

Return type:

Path

get_package(package: str) PackageEntry

Get a package entry for a given package name.

Parameters:

package (str) – Name of package to query.

Returns:

Entry associated with given package name.

Return type:

ComponentEntry

Raises:

CatalogueError – When package is not a valid package name.

get_public_packages() List[str]

Returns a list of all package names marked as public in the catalogue.

Returns:

The list of names of all packages marked as public.

Return type:

list of str

static load_catalogue(path: Path | None = None) Catalogue

Load catalogue file at a given path.

Parameters:

path (Path) – Path to catalogue file.

Returns:

Catalogue instance populated by the contents of the catalogue file.

Return type:

Catalogue

packages: Mapping[str, PackageEntry]

Mapping of package names to their respective entries.

static update_catalogue()

Download latest catalogue for the current version of CAMeL Tools.

Raises:

DownloaderError – When an error occurs while downloading catalogue.

version: str

Catalogue version string.