Skip to content

radiens_data_catalog.catalog

The Catalog class: Drive scanning, local caching, and downloading behind one API.

CLASS DESCRIPTION
Catalog

Main interface for radiens-data-catalog.

PrefetchResult

Summary of a :meth:Catalog.prefetch call.

ScanResult

Summary of a :meth:Catalog.scan call.

UploadResult

Summary of a :meth:Catalog.upload_folder call.

FUNCTION DESCRIPTION
match_series

Filter a string pd.Series by query under mode, returning a boolean mask.

ATTRIBUTE DESCRIPTION
MatchMode

How a filter value is matched against a catalog field: an exact match, a

Attributes

MatchMode module-attribute

MatchMode = Literal['exact', 'prefix', 'contains', 'regex']

How a filter value is matched against a catalog field: an exact match, a prefix match, a substring match, or a regular expression searched anywhere in the field (anchor with ^/$ for a full match).

Classes

Catalog

Main interface for radiens-data-catalog.

Wraps Google Drive scanning, local JSON catalog management, and file download. Querying is done directly on the recordings_df and items_df DataFrames using standard pandas operations.

Recordings are uniquely identified by (drive_path, base_name) where drive_path is the slash-joined path from the Drive root to the containing folder.

Example
from radiens_data_catalog import Catalog, Config

config = Config.from_file("config.json")
catalog = Catalog(config)

catalog.scan()
hits = catalog.list_recordings(drive_path="2026-02", drive_path_mode="prefix")
path = catalog.get_recording_path("2026-02/reaching", "rat01")
catalog.prefetch(drive_path="2026-02", drive_path_mode="prefix")
print(catalog.file_tree())
print(catalog.summary())
METHOD DESCRIPTION
download_item

Download a Drive item (file or folder) to the local data directory.

download_recording

Download the xdat files for a recording to the local data directory.

file_tree

Return a string rendering of the Drive tree with local-presence indicators.

get_item_path

Return the local path for a Drive item, downloading if needed.

get_meta

Return one recording's parsed .xdat.json metadata, fetching only that file if needed.

get_recording

Look up a recording by base_name, requiring it to be unique.

get_recording_path

Return the local directory path for a recording, downloading if needed.

list_items

Query the Drive items catalog and return a filtered DataFrame.

list_recordings

Query the recording catalog and return a filtered DataFrame.

load_meta

Return the parsed .xdat.json metadata of every matching recording.

local_footprint

Return the total on-disk size, in bytes, of all downloaded data.

orphaned_downloads

Temp files left by interrupted recording downloads, by (drive_path, base_name).

prefetch

Bulk-download matching recordings and items, skipping already-local entries.

release_item

Delete a Drive item's local file or folder and clear its local_path.

release_recording

Delete a recording's local xdat files and clear its local_path.

scan

Scan Drive and rebuild the catalog JSON.

summary

Return a human-readable report summarizing the whole catalog.

upload_folder

Upload a local folder to {parent_drive_path}/{folder name} on Drive and add it to the catalog.

ATTRIBUTE DESCRIPTION
items_df

The full Drive items catalog as a pandas DataFrame.

TYPE: DataFrame

recordings_df

The full recording catalog as a pandas DataFrame.

TYPE: DataFrame

Attributes

items_df property
items_df: DataFrame

The full Drive items catalog as a pandas DataFrame.

Columns: name, is_folder, drive_path, drive_id, mime_type, local_path, upload_time, size

recordings_df property
recordings_df: DataFrame

The full recording catalog as a pandas DataFrame.

Columns: base_name, drive_path, drive_file_ids, local_path, upload_time, size, last_used, downloaded.

downloaded is whether every xdat file is actually on disk (local_path is only a hint, reconciled by :meth:scan).

last_used is when :meth:get_recording_path last returned the recording on this machine; for a downloaded recording never loaded that way, it falls back to when its data file was written (the download).

Functions

download_item
download_item(drive_path: str | Path, name: str) -> str

Download a Drive item (file or folder) to the local data directory.

Items are stored under {local_data_dir}/{drive_path}/{name}.

PARAMETER DESCRIPTION
drive_path

The slash-joined path to the item's parent folder. Accepts a str or Path; a Path is converted via str().

TYPE: str | Path

name

The file or folder name.

TYPE: str

RETURNS DESCRIPTION
str

The local path to the downloaded file or folder.

RAISES DESCRIPTION
EntryNotFoundError

If the item is not found in the catalog.

download_recording
download_recording(drive_path: str | Path, base_name: str) -> str

Download the xdat files for a recording to the local data directory.

Files are stored under {local_data_dir}/{drive_path}/.

PARAMETER DESCRIPTION
drive_path

The slash-joined path to the folder containing the recording. Accepts a str or Path; a Path is converted via str().

TYPE: str | Path

base_name

The recording identifier (shared filename stem).

TYPE: str

RETURNS DESCRIPTION
str

The local directory path where the files were written.

RAISES DESCRIPTION
EntryNotFoundError

If the recording is not found in the catalog.

file_tree
file_tree() -> str

Return a string rendering of the Drive tree with local-presence indicators.

Each entry is annotated as [recording], [folder], or [file] and [local] or [not local] based on whether it has been downloaded.

RETURNS DESCRIPTION
str

A multi-line indented string representing the Drive folder hierarchy.

get_item_path
get_item_path(drive_path: str | Path, name: str) -> str

Return the local path for a Drive item, downloading if needed.

PARAMETER DESCRIPTION
drive_path

The slash-joined path to the item's parent folder. Accepts a str or Path; a Path is converted via str().

TYPE: str | Path

name

The file or folder name.

TYPE: str

RETURNS DESCRIPTION
str

The local path to the downloaded file or folder.

RAISES DESCRIPTION
EntryNotFoundError

If the item is not found in the catalog.

get_meta
get_meta(drive_path: str | Path, base_name: str) -> dict[str, object]

Return one recording's parsed .xdat.json metadata, fetching only that file if needed.

See :meth:load_meta for caching; use it directly for many recordings.

RAISES DESCRIPTION
EntryNotFoundError

If the recording is not in the catalog, or has no metadata file on Drive.

get_recording
get_recording(base_name: str, drive_path: str | Path | None = None) -> RecordingEntry

Look up a recording by base_name, requiring it to be unique.

PARAMETER DESCRIPTION
base_name

The recording's filename stem.

TYPE: str

drive_path

Exact drive_path to disambiguate recordings that share a base_name at different Drive locations. Accepts a str or Path; a Path is converted via str().

TYPE: str | Path | None DEFAULT: None

RETURNS DESCRIPTION
RecordingEntry

The matching :class:RecordingEntry.

RAISES DESCRIPTION
EntryNotFoundError

If no recording with this base_name (and drive_path, if given) exists.

AmbiguousRecordingError

If more than one recording matches.

get_recording_path
get_recording_path(drive_path: str | Path, base_name: str) -> str

Return the local directory path for a recording, downloading if needed.

PARAMETER DESCRIPTION
drive_path

The slash-joined path to the folder containing the recording. Accepts a str or Path; a Path is converted via str().

TYPE: str | Path

base_name

The recording identifier (shared filename stem).

TYPE: str

RETURNS DESCRIPTION
str

The local directory path where the xdat files reside.

RAISES DESCRIPTION
EntryNotFoundError

If the recording is not found in the catalog.

list_items
list_items(
    *,
    drive_path: str | Path | None = None,
    drive_path_mode: MatchMode = "exact",
    is_folder: bool | None = None,
) -> DataFrame

Query the Drive items catalog and return a filtered DataFrame.

All filters are applied together (AND semantics). Omitting all arguments returns the full items catalog.

PARAMETER DESCRIPTION
drive_path

Value to match against each item's parent drive_path. Accepts a str or Path; a Path is converted via str().

TYPE: str | Path | None DEFAULT: None

drive_path_mode

How drive_path is matched: "exact" (default), "prefix", "contains", or "regex".

TYPE: MatchMode DEFAULT: 'exact'

is_folder

When True return only folders; when False return only files; when None (default) return both.

TYPE: bool | None DEFAULT: None

list_recordings
list_recordings(
    *,
    base_name: str | None = None,
    base_name_mode: MatchMode = "exact",
    drive_path: str | Path | None = None,
    drive_path_mode: MatchMode = "exact",
) -> DataFrame

Query the recording catalog and return a filtered DataFrame.

All filters are applied together (AND semantics). Omitting all arguments returns the full catalog.

PARAMETER DESCRIPTION
base_name

Value to match against each recording's base_name.

TYPE: str | None DEFAULT: None

base_name_mode

How base_name is matched: "exact" (default), "prefix", "contains", or "regex".

TYPE: MatchMode DEFAULT: 'exact'

drive_path

Value to match against each recording's drive_path. Accepts a str or Path; a Path is converted via str().

TYPE: str | Path | None DEFAULT: None

drive_path_mode

How drive_path is matched: "exact" (default), "prefix", "contains", or "regex".

TYPE: MatchMode DEFAULT: 'exact'

load_meta
load_meta(
    *,
    drive_path: str | Path | None = None,
    drive_path_mode: MatchMode = "exact",
    base_name: str | None = None,
    base_name_mode: MatchMode = "exact",
    max_workers: int = 8,
) -> dict[tuple[str, str], dict[str, object]]

Return the parsed .xdat.json metadata of every matching recording.

Never downloads recording data: a downloaded recording's own metadata file is read in place, and any other is fetched alone (~100 KB) into {catalog dir}/meta_cache/, keyed by Drive file ID so a re-upload is never served stale. Recordings with no metadata file on Drive, or whose file fails to fetch (summarized in one warning) or parse, are left out. A file Drive refuses permanently (403/404) is cached as empty so it isn't refetched. Filters match like :meth:list_recordings.

PARAMETER DESCRIPTION
drive_path

Value to match against each recording's drive_path.

TYPE: str | Path | None DEFAULT: None

drive_path_mode

How drive_path is matched, as in :meth:list_recordings.

TYPE: MatchMode DEFAULT: 'exact'

base_name

Value to match against each recording's base_name.

TYPE: str | None DEFAULT: None

base_name_mode

How base_name is matched, as in :meth:list_recordings.

TYPE: MatchMode DEFAULT: 'exact'

max_workers

Number of files to fetch concurrently. Each worker thread uses its own Drive service (the API client is not thread-safe).

TYPE: int DEFAULT: 8

RETURNS DESCRIPTION
dict[tuple[str, str], dict[str, object]]

Metadata keyed by (drive_path, base_name).

local_footprint
local_footprint() -> int

Return the total on-disk size, in bytes, of all downloaded data.

Sums each recording's own xdat files and each downloaded item's file or folder subtree. Use this to drive caller-managed eviction — e.g. release recordings until local_footprint() drops below a chosen cap.

RETURNS DESCRIPTION
int

The total local footprint in bytes.

orphaned_downloads
orphaned_downloads(
    *, drive_path: str | None = None, min_age_s: float = 600.0
) -> dict[tuple[str, str], list[Path]]

Temp files left by interrupted recording downloads, by (drive_path, base_name).

A download normally removes its temp file when it fails or is interrupted; a hard kill leaves it behind, unused and uncounted by :meth:local_footprint. Temp files modified in the last min_age_s seconds are left out, since a download in progress may be writing them. Item downloads' temp files are not listed.

PARAMETER DESCRIPTION
drive_path

Look only in this recording folder instead of the whole local data directory.

TYPE: str | None DEFAULT: None

min_age_s

Minimum time since a temp file was last written.

TYPE: float DEFAULT: 600.0

RETURNS DESCRIPTION
dict[tuple[str, str], list[Path]]

Each recording's orphaned temp files; recordings with none are absent.

prefetch
prefetch(
    *,
    drive_path: str | Path | None = None,
    drive_path_mode: MatchMode = "exact",
    base_name: str | None = None,
    base_name_mode: MatchMode = "exact",
    recordings: bool = True,
    items: bool = True,
    is_folder: bool | None = None,
    keys: Collection[tuple[str, str]] | None = None,
    force: bool = False,
    max_workers: int = 8,
) -> PrefetchResult

Bulk-download matching recordings and items, skipping already-local entries.

PARAMETER DESCRIPTION
drive_path

Value to match against each entry's drive_path. Accepts a str or Path; a Path is converted via str().

TYPE: str | Path | None DEFAULT: None

drive_path_mode

How drive_path is matched: "exact" (default), "prefix", "contains", or "regex".

TYPE: MatchMode DEFAULT: 'exact'

base_name

Value to match against each recording's base_name. Only constrains recordings — items have no base_name and are unaffected by this filter.

TYPE: str | None DEFAULT: None

base_name_mode

How base_name is matched: "exact" (default), "prefix", "contains", or "regex".

TYPE: MatchMode DEFAULT: 'exact'

recordings

When False, no recordings are downloaded.

TYPE: bool DEFAULT: True

items

When False, no items are downloaded.

TYPE: bool DEFAULT: True

is_folder

Restrict item downloads to folders (True) or files (False).

TYPE: bool | None DEFAULT: None

keys

If given, only recordings whose (drive_path, base_name) is in keys are downloaded (on top of the other filters).

TYPE: Collection[tuple[str, str]] | None DEFAULT: None

force

When True, re-download regardless of local presence.

TYPE: bool DEFAULT: False

max_workers

Number of recordings/items to download concurrently. Downloads are I/O-bound on the Drive API, which throttles each stream well below typical link bandwidth, so several concurrent streams give near-linear speedup. Each worker thread uses its own Drive service (the API client is not thread-safe). Use 1 to download strictly sequentially.

TYPE: int DEFAULT: 8

RETURNS DESCRIPTION
A

class:PrefetchResult with per-category download and skip counts.

TYPE: PrefetchResult

RAISES DESCRIPTION
Exception

Re-raises the first download failure after recording all successful downloads in the catalog. Because prefetch is idempotent (already-local entries are skipped), re-running resumes only the failed downloads.

release_item
release_item(drive_path: str | Path, name: str) -> int

Delete a Drive item's local file or folder and clear its local_path.

A file item's local path is removed with unlink; a folder item's local path is an entire subtree owned by that item and is removed with shutil.rmtree. Safe to call when the item is not downloaded — it is a no-op that returns 0.

Only this item's own local_path is cleared. Deleting a folder also removes any nested files/subfolders that were cataloged as separate entries (see :meth:scan), so their stored local_path becomes stale until the next :meth:scan. This is by design: local_path is a hint reconciled by :meth:scan, and all download/size operations (:meth:get_item_path, :meth:prefetch, :meth:local_footprint) re-check the disk, so a stale value never causes a wrong result.

PARAMETER DESCRIPTION
drive_path

The slash-joined path to the item's parent folder. Accepts a str or Path; a Path is converted via str().

TYPE: str | Path

name

The file or folder name.

TYPE: str

RETURNS DESCRIPTION
int

The number of bytes freed from disk.

RAISES DESCRIPTION
EntryNotFoundError

If the item is not found in the catalog.

release_recording
release_recording(drive_path: str | Path, base_name: str) -> int

Delete a recording's local xdat files and clear its local_path.

Temp files its interrupted downloads left behind (see :meth:orphaned_downloads) go too, even when the recording was never fully downloaded. Only the recording's own files are removed; the containing drive_path directory is left in place because sibling recordings and downloaded items may share it. Safe to call when the recording is not downloaded — it is a no-op that returns 0.

PARAMETER DESCRIPTION
drive_path

The slash-joined path to the folder containing the recording. Accepts a str or Path; a Path is converted via str().

TYPE: str | Path

base_name

The recording identifier (shared filename stem).

TYPE: str

RETURNS DESCRIPTION
int

The number of bytes freed from disk.

RAISES DESCRIPTION
EntryNotFoundError

If the recording is not found in the catalog.

scan
scan(*, flat: bool = True) -> ScanResult

Scan Drive and rebuild the catalog JSON.

Any existing local_path entries are preserved so a rescan doesn't forget which recordings or items have already been downloaded.

PARAMETER DESCRIPTION
flat

If True (the default), use a flat scan of all files visible to the service account. Set to False for a recursive traversal from the root folder.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
A

class:ScanResult with new/existing/removed counts.

TYPE: ScanResult

summary
summary(*, rescan: bool = False, verbose: bool = False) -> str

Return a human-readable report summarizing the whole catalog.

The default report is headline-only: recording/item counts, local-download progress, the upload-date range, Drive size (broken out separately for recordings and items, plus local storage size), average recording size, and an incomplete-recording count. Pass verbose=True to additionally get an item-type breakdown, the largest entries by size, the itemized incomplete-recordings list, a per-top-level-folder breakdown, and a full per-entry listing — sections whose length scales with the size of the catalog, so they're opt-in rather than pushing the headline stats out of view.

This package once had (and deliberately removed) a similar convenience method, status(), in favor of operating on the DataFrames directly. summary() is justified where status() wasn't: it's a genuine multi-source rollup across both DataFrames plus a live local-disk walk, not a one-column derivation a caller could trivially replicate.

PARAMETER DESCRIPTION
rescan

If True, call :meth:scan first to refresh the catalog and backfill size on older entries before computing the report. Defaults to False (fast, read-only).

TYPE: bool DEFAULT: False

verbose

If True, additionally include the item-type breakdown, largest entries, itemized incomplete recordings, per-top-level-folder breakdown, and a full per-entry listing.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
str

A multi-line report string.

upload_folder
upload_folder(
    local_dir: str | Path,
    parent_drive_path: str | Path,
    *,
    confirm: Callable[[UploadPlan], bool] | None = None,
) -> UploadResult | None

Upload a local folder to {parent_drive_path}/{folder name} on Drive and add it to the catalog.

Nothing on Drive is ever overwritten, trashed or deleted. Missing folders on the way are created. A file already on Drive with the same MD5 is skipped, so rerunning after a failure picks up where it stopped. The new catalog entries get local_path=None: the local folder is the upload's source, not a download.

Uploading needs Contributor access to the Shared Drive holding the root folder; a service account has no storage of its own for a My Drive.

PARAMETER DESCRIPTION
local_dir

Local folder to upload.

TYPE: str | Path

parent_drive_path

Drive path, from the root folder, of the folder to upload into; "" for the root itself.

TYPE: str | Path

confirm

Called with the :class:UploadPlan before anything is created or sent; returning False stops the upload.

TYPE: Callable[[UploadPlan], bool] | None DEFAULT: None

RETURNS DESCRIPTION
An

class:UploadResult with what was created, sent and skipped, or None if confirm declined.

TYPE: UploadResult | None

RAISES DESCRIPTION
CatalogError

If there's no catalog file yet; run :meth:scan first.

NotADirectoryError

If local_dir isn't a directory.

UploadConflictError

Before anything is sent, if Drive already holds something different at a target path.

UploadError

If an uploaded file's MD5 on Drive doesn't match the local file.

PrefetchResult dataclass

Summary of a :meth:Catalog.prefetch call.

ATTRIBUTE DESCRIPTION
recordings_downloaded

Number of recordings fetched from Drive.

TYPE: int

recordings_skipped

Number of recordings already available locally.

TYPE: int

items_downloaded

Number of items fetched from Drive.

TYPE: int

items_skipped

Number of items already available locally.

TYPE: int

ScanResult dataclass

Summary of a :meth:Catalog.scan call.

ATTRIBUTE DESCRIPTION
recordings_new

Recordings found on Drive not in the previous catalog.

TYPE: int

recordings_existing

Recordings found on Drive already in the catalog.

TYPE: int

recordings_removed

Recordings in the previous catalog not on Drive.

TYPE: int

items_new

Items found on Drive not in the previous catalog.

TYPE: int

items_existing

Items found on Drive already in the catalog.

TYPE: int

items_removed

Items in the previous catalog not found on Drive.

TYPE: int

UploadResult dataclass

Summary of a :meth:Catalog.upload_folder call.

ATTRIBUTE DESCRIPTION
drive_path

Drive path the local folder landed at.

TYPE: str

folders_created

Folders created on Drive, missing parents included.

TYPE: int

files_uploaded

Files sent to Drive.

TYPE: int

files_skipped

Files already on Drive with the same contents.

TYPE: int

bytes_sent

Total size of the files sent.

TYPE: int

Functions

match_series

match_series(series: Series[str], query: str | None, mode: MatchMode) -> Series[bool]

Filter a string pd.Series by query under mode, returning a boolean mask.

Use this to filter an already-fetched DataFrame (e.g. a cached recordings_df, or your own subset of it) with the same exact/prefix/contains/regex semantics :meth:Catalog.list_recordings and :meth:Catalog.list_items use internally. A None query matches everything (an all-True mask).