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: |
ScanResult |
Summary of a :meth: |
UploadResult |
Summary of a :meth: |
| FUNCTION | DESCRIPTION |
|---|---|
match_series |
Filter a string |
| 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 |
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 |
local_footprint |
Return the total on-disk size, in bytes, of all downloaded data. |
orphaned_downloads |
Temp files left by interrupted recording downloads, by |
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 |
release_recording |
Delete a recording's local xdat files and clear its |
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 |
| ATTRIBUTE | DESCRIPTION |
|---|---|
items_df |
The full Drive items catalog as a pandas DataFrame.
TYPE:
|
recordings_df |
The full recording catalog as a pandas DataFrame.
TYPE:
|
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 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 |
name
|
The file or folder name.
TYPE:
|
| 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 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 |
base_name
|
The recording identifier (shared filename stem).
TYPE:
|
| 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
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 |
name
|
The file or folder name.
TYPE:
|
| 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
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:
|
drive_path
|
Exact |
| RETURNS | DESCRIPTION |
|---|---|
RecordingEntry
|
The matching :class: |
| RAISES | DESCRIPTION |
|---|---|
EntryNotFoundError
|
If no recording with this base_name (and
|
AmbiguousRecordingError
|
If more than one recording matches. |
get_recording_path
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 |
base_name
|
The recording identifier (shared filename stem).
TYPE:
|
| 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_mode
|
How
TYPE:
|
is_folder
|
When
TYPE:
|
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
TYPE:
|
base_name_mode
|
How
TYPE:
|
drive_path
|
Value to match against each recording's |
drive_path_mode
|
How
TYPE:
|
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_mode
|
How
TYPE:
|
base_name
|
Value to match against each recording's
TYPE:
|
base_name_mode
|
How
TYPE:
|
max_workers
|
Number of files to fetch concurrently. Each worker thread uses its own Drive service (the API client is not thread-safe).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[tuple[str, str], dict[str, object]]
|
Metadata keyed by |
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:
|
min_age_s
|
Minimum time since a temp file was last written.
TYPE:
|
| 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_mode
|
How
TYPE:
|
base_name
|
Value to match against each recording's
TYPE:
|
base_name_mode
|
How
TYPE:
|
recordings
|
When
TYPE:
|
items
|
When
TYPE:
|
is_folder
|
Restrict item downloads to folders (
TYPE:
|
keys
|
If given, only recordings whose
TYPE:
|
force
|
When
TYPE:
|
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
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
A
|
class:
TYPE:
|
| 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
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 |
name
|
The file or folder name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The number of bytes freed from disk. |
| RAISES | DESCRIPTION |
|---|---|
EntryNotFoundError
|
If the item is not found in the catalog. |
release_recording
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 |
base_name
|
The recording identifier (shared filename stem).
TYPE:
|
| 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
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
A
|
class:
TYPE:
|
summary
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
TYPE:
|
verbose
|
If
TYPE:
|
| 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. |
parent_drive_path
|
Drive path, from the root folder, of the folder to
upload into; |
confirm
|
Called with the :class:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
An
|
class:
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
CatalogError
|
If there's no catalog file yet; run :meth: |
NotADirectoryError
|
If |
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:
|
recordings_skipped |
Number of recordings already available locally.
TYPE:
|
items_downloaded |
Number of items fetched from Drive.
TYPE:
|
items_skipped |
Number of items already available locally.
TYPE:
|
ScanResult
dataclass
Summary of a :meth:Catalog.scan call.
| ATTRIBUTE | DESCRIPTION |
|---|---|
recordings_new |
Recordings found on Drive not in the previous catalog.
TYPE:
|
recordings_existing |
Recordings found on Drive already in the catalog.
TYPE:
|
recordings_removed |
Recordings in the previous catalog not on Drive.
TYPE:
|
items_new |
Items found on Drive not in the previous catalog.
TYPE:
|
items_existing |
Items found on Drive already in the catalog.
TYPE:
|
items_removed |
Items in the previous catalog not found on Drive.
TYPE:
|
UploadResult
dataclass
Summary of a :meth:Catalog.upload_folder call.
| ATTRIBUTE | DESCRIPTION |
|---|---|
drive_path |
Drive path the local folder landed at.
TYPE:
|
folders_created |
Folders created on Drive, missing parents included.
TYPE:
|
files_uploaded |
Files sent to Drive.
TYPE:
|
files_skipped |
Files already on Drive with the same contents.
TYPE:
|
bytes_sent |
Total size of the files sent.
TYPE:
|
Functions
match_series
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).