Watcher configuration
Every config.yaml field, the ~/.data-hub file layout, environment variables, run-detection presets, upload modes, and the initial-scan behavior.
This page is the complete reference for the watcher’s configuration. It covers the config.yaml schema, where the watcher’s files live, and the environment variables that affect it. It also covers the behavior those fields control: run detection, upload modes, and the initial scan.
File locations
The watcher keeps all its files under ~/.data-hub/:
| Path | Contents |
|---|---|
~/.data-hub/config.yaml | The main config, described below. Use --config or DATA_HUB_CONFIG_PATH to read a different file. |
~/.data-hub/.env.<environment> | The API key for an environment (for example .env.staging, .env.production, .env.preview). The watcher still loads the older ~/.data-hub/.env, but the file for the environment takes precedence. |
~/.data-hub/watcher-<environment>.db | The watcher’s SQLite state for one environment: uploaded files, runs, detected files, and the baseline. |
~/.data-hub/watcher.log | Rotating log (10 MB × 5 backups). On Windows: C:\ProgramData\DataHubWatcher\watcher.log. |
~/.data-hub/upgrade-worker.log | Transcript of Windows upgrades that run through uv tool. |
Environment variables
| Variable | Purpose |
|---|---|
DATA_HUB_API_KEY | Supplies the API key, so init doesn’t ask for it. The watcher saves it into the .env file for the environment. |
DATA_HUB_CONFIG_PATH | Reads the config from a different path, like --config. |
DATA_HUB_WATCHER_LOG_LEVEL | Set to DEBUG in the service’s .env file to turn on debug logging without a reinstall. Needs watcher 1.4.2 or later. |
config.yaml
version: 1
environment: production # "staging", "production", or "preview"
api_base_urls: # one API base URL per environment
production: https://datahub.example.org/api/v1
watcher_ids: # one registration id per environment
production: your_watcher_id # assigned by the API when the watcher registers
initial_scan: null # null (default), "full", or "new-only"
instrument:
id: akta-fplc # kebab-case instrument ID
watch_directory: /path/to/data
file_patterns:
- "*.csv"
- "*.xlsx"
enabled: true
upload_mode: auto # "auto" or "manual"
stability_period_seconds: 5 # 1–300
max_stability_wait_seconds: 300 # 1–86400; must be >= stability_period_seconds
upload_parallelism: 4 # 1–32
run_detection:
pattern: '^([^/]+)/' # regex with one capture group (run ID)
recursive: trueField reference
An admin can also change the fields marked Web from the web app, and the watcher saves those changes to this file. See Change a watcher’s settings.
| Field | Type | Web | Description |
|---|---|---|---|
version | int | Config schema version. Currently 1. | |
environment | enum | staging, production, or preview. | |
api_base_urls | map | One API base URL per environment, keyed by environment name. Set at init, or by config set-environment --api-base-url. A config with a single top-level api_base_url is moved into this map on load. | |
watcher_ids | map | One watcher registration ID per environment. The API assigns them. | |
initial_scan | enum | null | null (the environment’s default), full, or new-only. See Initial scan. | |
instrument.id | string | Kebab-case instrument ID. It never changes, and it starts every storage key. | |
instrument.watch_directory | string | Web | Absolute path of the watch folder, where the instrument writes its files. |
instrument.file_patterns | string[] | Web | Glob patterns matched against each file’s name, case-sensitive. The watcher uploads only matching files. 1–50 patterns. |
instrument.enabled | bool | Whether the watcher processes this instrument. | |
instrument.upload_mode | enum | Web | auto or manual. See Upload modes. |
instrument.stability_period_seconds | int (1–300) | Web | Seconds a file must stay unchanged before the watcher treats it as finished. Default 5. |
instrument.max_stability_wait_seconds | int (1–86400) | Web | Seconds a file that’s still changing may stay pending before the watcher gives up on it and records a stability_timeout event. Must be at least stability_period_seconds. Default 300 (5 minutes). |
instrument.upload_parallelism | int (1–32) | Web | The most uploads the watcher runs at the same time. Each part of a large file counts as one upload, so a single file can use several connections. Default 4. Raise it on PCs with a fast network link; lower it on a slow or shared one. |
instrument.run_detection.pattern | regex | Web | Regular expression with one capture group, applied to each file’s path relative to watch_directory. |
instrument.run_detection.recursive | bool | Web | true also watches subfolders; false watches only the top level. Default true. |
A config written by an older watcher has a single top-level watcher_id and api_base_url. When the watcher loads that config, it moves both values into watcher_ids and api_base_urls under the active environment. It removes the old fields the next time it saves the config, so you don’t need to edit anything.
Run detection
The watcher applies the pattern regular expression (regex) with re.search to each file’s path relative to watch_directory, with backslashes changed to /. Capture group 1 is the run ID, and the pattern must have exactly one capture group. In YAML, put patterns in single quotes so backslash sequences like \d don’t need escaping.
The web app also checks patterns in JavaScript, so it refuses syntax that only Python supports, such as named groups ((?P<name>…)). Use a plain capture group instead.
The init wizard offers these presets, or you can enter your own regex:
| Preset | Pattern | Recursive | Run ID is… |
|---|---|---|---|
| Filename prefix | ^([^_]+) | no | everything before the first _: RUN001_data.csv → RUN001 |
| Top subdirectory | ^([^/]+)/ | yes | the top-level folder: RUN001/data.csv → RUN001 |
| Deepest subdirectory | ([^/]+)/[^/]+$ | yes | the immediate parent folder: plate-a/well-b/data.csv → well-b |
| Timestamp subdirectory | (?:^|/)(\d{8}_\d{6}_\d{3})/ | yes | a YYYYMMDD_HHMMSS_fff folder anywhere in the path |
| Filename stem | ^(?:.+/)?([^/]+?)\.[^/.]+$ | no | the filename without its extension (each file is its own run) |
Upload modes
auto: files upload to cloud storage as soon as the watcher detects their run. The watcher also uploads files requested from the run page. It retries an upload that didn’t finish the next time it starts, for up to three starts.manual: the watcher reports runs without uploading. The server decides which files to upload through a queue that the watcher checks once a minute. Use it when someone must approve uploads. See Manage the watcher fleet → Approving manual uploads.
Files of 100 MB or more upload in 64 MB parts, and the parts of one file upload at the same time. The watcher can upload files larger than 5 GB. Several queued files can also upload at the same time. Together, parts and files stay within instrument.upload_parallelism uploads at once, so a large file doesn’t depend on a single connection.
Initial scan
The first time the watcher enters an environment, through init or config set-environment, initial_scan decides what happens to files already in the watch folder. The default depends on the environment:
production→full: the watcher uploads the existing files, because production is the deployment your lab uses for its real data.stagingandpreview→new-only: the watcher records the files already on disk as a baseline and skips them. It uploads only files created afterwards.
So a new init on staging or preview doesn’t upload a PC’s history. Set initial_scan: full to upload it anyway, for example to fill staging on purpose. Set initial_scan: new-only on production to skip its backlog.
Upgrading an existing watcher doesn’t change any of this. The watcher’s state database for that environment already lists files it uploaded or detected, so the watcher doesn’t record a new baseline.
Switching environments
One PC can move between staging, production, and preview. These are separate deployments with separate databases, so each keeps its own registration in watcher_ids and its own credentials in ~/.data-hub/.env.<environment>.
# Switch to staging (reuses a stored registration, or registers one).
data-hub-watcher config set-environment staging
# Point at a preview deployment (the base URL is required).
data-hub-watcher config set-environment preview \
--api-base-url https://data-hub-git-my-branch.vercel.app/api/v1A switch does these things:
- checks that it can reach the target API with the key
- reuses the watcher ID stored for that environment, or registers a new one
- sends the config to the new environment
- records a
watcher_stoppedevent in the old environment, with a message that names the environment it switched to
A running watch process or service keeps using the old environment until you restart it. On Windows, run service stop && service start; elsewhere, restart watch.