Example datasets API reference#

cytearc.datasets lists and downloads the public example datasets that the CyteArc tutorials use. They live in top-level repositories of the public Nygen/cytebase Hugging Face bucket, such as cytearc_docs for the documentation datasets. Downloads need network access but no credentials. A repository names each dataset by its directory.

import cytearc

repository = cytearc.datasets.connect("cytearc_docs")
repository.list_datasets()

# Download and extract a prepared CyteArc store, then open it read-only.
path = repository.download_dataset(
    "tenx_5K_pbmc_rnaseq", destination="cytearc_datasets", zarr=True
)
ds = cytearc.DataStore(f"{path}/data.zarr", zarr_mode="r")

download_dataset(name, zarr=True) downloads the dataset’s data.zarr.tar.gz archive and extracts it to data.zarr in the returned directory, keeping the archive beside it. Without zarr=True, it downloads the dataset’s other files, such as its source count files, and skips the store: its archive and the files under data.zarr/ that some datasets also list unpacked for remote reads.

A later call into the same destination reuses what is already there. A file is not downloaded again while the bucket lists it with the size and Xet hash recorded when it was downloaded, and its local copy has that size. An existing data.zarr is returned with the results saved in it, and is never replaced without overwrite=True. The call raises FileExistsError instead when:

  • the bucket now lists another archive than the one data.zarr was extracted from, a newer version of the dataset;

  • data.zarr was made from another source, such as a copy from a local catalog;

  • nothing records what data.zarr was made from, and the archive beside it is missing or has another size than the bucket’s, as for a store from an earlier CyteArc whose archive was deleted;

  • data.zarr is not a directory;

  • another call placed data.zarr while this one was downloading or extracting it, and has not recorded it as current. A call that has recorded it makes this one return the store instead.

A directory extracted from any other archive that a dataset lists follows the same rules. overwrite=True downloads the current version, deleting anything saved in data.zarr.

download(path) downloads one file, or every file under a directory, on every call, and keeps its path within the repository.

cytearc.datasets.list_repositories()#

Return the top-level example repositories in the public bucket.

Return type:

list[str]

cytearc.datasets.connect(repository)#

Connect to a public example repository, such as cytearc_docs.

Return type:

Repository

class cytearc.datasets.Repository(name)#

Read files from one top-level example repository.

download(path, destination='.')#

Download a file or directory while preserving its repository path.

Return type:

list[Path]

download_dataset(name, destination='.', *, zarr=False, overwrite=False)#

Download one dataset into destination/name and return that directory.

Without zarr, the call downloads the dataset’s files other than its Zarr store, such as its source count files. It skips the store’s archive and the files under the store’s directory, which some datasets also list unpacked for remote reads. With zarr=True, it downloads the dataset’s data.zarr.tar.gz archive and extracts it to data.zarr, keeping the archive beside it.

A later call reuses what an earlier call placed in destination. Each call records the bucket’s listing of each file it placed, its path, size and Xet hash, in .cytebase-sources.json in the returned directory, together with the archive that each extracted directory came from. A file is not downloaded again while the bucket’s listing of it equals the recorded one and the local copy has the listed size. An existing data.zarr is returned untouched, with everything saved in it, while the record says that it was extracted from the archive that the bucket lists now; its archive is not needed for that. A data.zarr extracted before CyteArc kept this record is reused when the archive beside it has the size of the bucket’s archive; no bytes are compared.

Parameters:
  • name (str) – The dataset’s directory in the repository.

  • destination (str | Path) – The directory that receives the dataset’s directory.

  • zarr (bool) – Download and extract the dataset’s Zarr archive instead of its other files.

  • overwrite (bool) – Download the selected files again and replace their local copies. With zarr=True, the extracted data.zarr replaces the existing one, deleting anything saved in it. Without overwrite, an existing data.zarr is never replaced, even one that another call places while this one runs.

Raises:
  • TypeError – If zarr or overwrite is not a boolean.

  • KeyError – If the repository holds no such dataset.

  • FileNotFoundError – If zarr is set and the dataset has no Zarr archive, or if it is not set and the dataset lists no files besides its Zarr store.

  • FileExistsError – If overwrite is not set and data.zarr exists but the record does not say that it was extracted from the archive that the bucket lists now, or if another call places data.zarr while this one runs and has not recorded it as current.

  • ValueError – If .cytebase-sources.json is not a record that CyteArc wrote, or if the archive kept beside a deleted data.zarr cannot be extracted.

Return type:

Path

list_datasets()#

Return immediate dataset directories in this repository.

Return type:

list[str]

CyteBase catalog#

The CyteBase catalog of public datasets stored as cloud-hosted CyteArc DataStores is the separate cytebase package, which CyteArc does not install. CyteArc opens CyteBase datasets by their hf:// URIs, as https://docs.nygen.io/CyteArc/tutorials/cytebase-datasets shows. To search the catalog, install and import the package:

# Install the catalog client first: pip install cytebase
import cytebase

catalog = cytebase.Catalog()

See the CyteBase documentation at https://docs.nygen.io/CyteBase/ for its API and tutorials.

cytearc.cytebase keeps the earlier names of the example downloads through CyteArc 1.x: Repository, connect, and list_repositories are the cytearc.datasets objects. The catalog names it once exported, such as Catalog, releases, and embedding, moved to the cytebase package, and reading one from cytearc.cytebase raises an AttributeError that says so. The catalog build pipeline moved to the CyteBase repository at NygenAnalytics/CyteBase.