# Command line

> Forecast, backtest, score anomalies and predict on CSV or parquet files from a terminal or a scheduler.

The `yhatlabs` command comes with the Python library (`yhat` works as a short alias). It runs on CSV, parquet or JSON files,
which suits shell scripts, schedulers and coding agents.

## A forecast from a file

This downloads the temperatures and forecasts 28 days ahead. The forecast table goes to standard output as CSV:

```python
import pandas as pd
from yhatlabs import Client

url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/"
temps = pd.read_csv(url + "daily-min-temperatures.csv")  # 10 years of daily data: Date, Temp

yh = Client()
fc = yh.forecast(temps, h=28, time_col="Date", target_col="Temp")
print(fc.df.head(3).round(1))
print(fc.quantile_levels, fc.usage)
```

Output:

```
  unique_id       Date   q10  median   q90
0  series_0 1991-01-01  11.6    13.7  16.5
1  series_0 1991-01-02  11.7    14.3  17.5
2  series_0 1991-01-03  11.9    14.5  17.9
[0.1, 0.5, 0.9] {'series': 1, 'requests': 1}
```

```bash
curl -sO https://raw.githubusercontent.com/jbrownlee/Datasets/master/daily-min-temperatures.csv
yhatlabs forecast daily-min-temperatures.csv --h 28 --time-col Date --target-col Temp | head -4
```

Output:

```
unique_id,Date,q10,median,q90
series_0,1991-01-01,11.577219009399414,13.704099655151367,16.45543670654297
series_0,1991-01-02,11.744003295898438,14.314477920532227,17.50626564025879
series_0,1991-01-03,11.87166976928711,14.514473915100098,17.941247940063477
```

Pick the CLI tab above. Add `-o forecast.csv` (or `.parquet`) to write a file instead.

## Commands

| Command | What it does | Main options |
|---|---|---|
| `check FILE` | checks the data locally, no key needed; exit code 2 on an error | `--h`, `--target` (or `--target-col`), `--id-col`, `--time-col` |
| `forecast FILE --h N` | forecasts every series | `--level`, `--quantiles`, `--known` with `--future FILE`, `--past`, `--static`, `--preset pro` and `--tune ID` (0.2.2), `--no-store` |
| `tune FILE --h N` (0.2.2) | [tunes](https://yhatlabs.com/models/docs/time-series/tuning) the model on your series (a few minutes); prints the tune and its id | `--steps`, `--name`, `--known` with `--future FILE` |
| `evaluate FILE --h N` | backtests; prints the summary | `--windows`, `--step`, `-o` for per-window scores |
| `anomalies FILE` | scores recent points | `--h`, `--windows`, `--threshold`, `--only` (flagged points only) |
| `fill-gaps FILE` | fills gaps inside series | `--max-gap` |
| `predict TRAIN --target COL` | tabular prediction | `--test FILE`, `--task`, `--preset fast\|medium\|pro`, `--quantiles`, `--groups`, `--time-col`, `--set-coverage`, `--compare` (adds a `prediction_<model>` column per standard model), `--no-store` |
| `evaluate-table FILE --target COL` | cross-validates on your table; prints accuracy and calibration | `--cv`, `--groups`, `--time-col`, `--task`, `--preset`, `-o` for every row's out-of-fold prediction |
| `whoami`, `models`, `usage`, `limits`, `fits`, `tunes` | account information, as JSON | |
| `--version` | prints the installed version | |
| `skills install` | installs the [agent skill](https://yhatlabs.com/models/docs/agents/skills) | `--dir` |

Time-series commands take `--id-col`, `--time-col`, `--target-col` and `--freq` when the columns are not found by name.
Every command takes `--base-url`. With `--no-store`, a `forecast` or `predict` call isn't shown in your Logs
([Data handling](https://yhatlabs.com/models/docs/resources/data-handling)).

## For scripts and agents

- `--json` prints JSON records on standard output instead of CSV or text. It goes before or after the command
  (`yhatlabs --json whoami` or `yhatlabs whoami --json`).
- Warnings go to standard error as one line each (`yhatlabs: warning: ...`).
- The exit code is 0 on success, 1 on an error from the API or the input, and 2 when `check` finds an error.
