# The CLI reference

> **CocoIndex v1.** This page documents CocoIndex **v1** — a ground-up redesign from v0. When writing code, ignore any v0 flow-builder DSL or deprecated decorators.
>
> Source: https://cocoindex.io/docs/cli/ · Docs index: https://cocoindex.io/docs/llms.txt · Agent skill: https://cocoindex.io/docs/skill.md
>
> v0→v1 quick map — if you reach for these v0 symbols, stop and use the v1 form: `@cocoindex.flow_def`/`FlowBuilder` → `coco.App` + a `@coco.fn` main function; `add_collector()`/`collect()`/`export()` → declare target states (`declare_row`, `declare_file`); `cocoindex.sources/functions/targets.*` → connector APIs (`localfs.walk_dir`, `coco.ops.*`, `postgres.declare_table_target`). Full mapping + API reference: https://cocoindex.io/docs/skill.md.

CocoIndex CLI is a standalone tool for managing and inspecting your apps. This page describes the CLI for Python projects, installed with the `cocoindex` package.

Rust projects have their own `cocoindex` binary with the same subcommands; see [the Rust CLI reference](/docs/rust/cli/). Both read the same state database format, so `show --db PATH --app-name NAME` works on either tool against an app the other SDK wrote.

## Invoke the CLI

Once CocoIndex is installed, you can invoke the CLI directly using the `cocoindex` command. Most commands require an `APP_TARGET` argument, which tells the CLI where your app definitions are located.

### APP_TARGET Format

The `APP_TARGET` can be:

1. A **Python module name** that contains your app definitions (e.g., `main`, `my_package.apps`).
    You can also use `--app-dir <path>` to specify the base directory to load the module from.

2. A **path to a Python file** defining your apps (e.g., `main.py`, `path/to/my_apps.py`).

    The file will be loaded as a top-level Python module, e.g. relative imports will not work as its parent package is not defined (similar to how `python main.py` resolves imports).

3. For commands that operate on a *specific app* (like `show`, `update`), you can combine the application reference with an app name:
    * `my_package.apps:MyApp`
    * `path/to/my_apps.py:MyApp`

### Environment Variables

You can set environment variables in an environment file.

* By default, the `cocoindex` CLI searches upward from the current directory for a `.env` file.
* You can use `--env-file <path>` to specify one explicitly:

    ```sh
    cocoindex --env-file path/to/custom.env <COMMAND> ...
    ```

Loaded variables do *NOT* override existing system ones.
If no file is found, only existing system environment variables are used.

### Global Options

CocoIndex CLI supports the following global options:

* `-e, --env-file <path>`: Load environment variables from a specified `.env` file. If not provided, `.env` in the current directory is loaded if it exists.
* `-d, --app-dir <path>`: Load apps from the specified directory. It will be treated as part of `PYTHONPATH`. Default to the current directory.
* `-V, --version`: Show the CocoIndex version and exit.
* `--help`: Show the main help message and exit.

## Subcommands Reference

### `auth`

Sign in to or out of the accounts connectors read (experimental).

**Usage:**

```bash
cocoindex auth [OPTIONS] COMMAND [ARGS]...
```

**Options:**

| Option | Description |
|--------|-------------|
| `--help` | Show this message and exit. |

---

### `auth sign-in`

Sign in to an account a connector reads.

**Usage:**

```bash
cocoindex auth sign-in [OPTIONS] COMMAND [ARGS]...
```

**Options:**

| Option | Description |
|--------|-------------|
| `--help` | Show this message and exit. |

---

### `auth sign-in google-docs`

Sign in with a Google account to keep Google Docs in its Drive.

Asks only for access to the files CocoIndex creates (drive.file): the docs
it creates and edits, nothing else in the Drive. The sign-in is kept apart
from `auth sign-in google-drive`'s.

Uses CocoIndex's own OAuth client when this release includes one. To use a
Desktop-app OAuth client of your own, pass CLIENT_SECRETS, the JSON file you
downloaded for it.

**Usage:**

```bash
cocoindex auth sign-in google-docs [OPTIONS] [CLIENT_SECRETS]
```

**Options:**

| Option | Description |
|--------|-------------|
| `--token-path FILE` | Where to keep the sign-in; default: cocoindex/google_docs_token.json under the user's config directory. |
| `--help` | Show this message and exit. |

---

### `auth sign-in google-drive`

Sign in with a Google account to read its Google Drive.

Uses CocoIndex's own OAuth client when this release includes one. To use a
Desktop-app OAuth client of your own, pass CLIENT_SECRETS, the JSON file you
downloaded for it.

Opens the consent page in the browser, or prints the link when this host has
none, and keeps the tokens in a file readable by this user only.

**Usage:**

```bash
cocoindex auth sign-in google-drive [OPTIONS] [CLIENT_SECRETS]
```

**Options:**

| Option | Description |
|--------|-------------|
| `--token-path FILE` | Where to keep the sign-in; default: cocoindex/google_drive_token.json under the user's config directory. |
| `--help` | Show this message and exit. |

---

### `auth sign-out`

Sign out of an account a connector reads.

**Usage:**

```bash
cocoindex auth sign-out [OPTIONS] COMMAND [ARGS]...
```

**Options:**

| Option | Description |
|--------|-------------|
| `--help` | Show this message and exit. |

---

### `auth sign-out google-docs`

Revoke the Google Docs sign-in at Google and delete its token file.

Google revokes everything the OAuth client holds for the account, so an
`auth sign-in google-drive` made with the same client ends too.

**Usage:**

```bash
cocoindex auth sign-out google-docs [OPTIONS]
```

**Options:**

| Option | Description |
|--------|-------------|
| `--token-path FILE` | The sign-in to end; default: the one `auth sign-in google-docs` writes by default. |
| `--help` | Show this message and exit. |

---

### `auth sign-out google-drive`

Revoke the sign-in at Google and delete its token file.

**Usage:**

```bash
cocoindex auth sign-out google-drive [OPTIONS]
```

**Options:**

| Option | Description |
|--------|-------------|
| `--token-path FILE` | The sign-in to end; default: the one `auth sign-in google-drive` writes by default. |
| `--help` | Show this message and exit. |

---

### `drop`

Drop an app and all its target states.

This will:

- Revert all target states created by the app (e.g., drop tables, delete rows)
- Clear the app's internal state database

`APP_TARGET`: `path/to/app.py`, `module`, `path/to/app.py:app_name`, or
`module:app_name`.

**Usage:**

```bash
cocoindex drop [OPTIONS] APP_TARGET
```

**Options:**

| Option | Description |
|--------|-------------|
| `-f, --force` | Skip confirmation prompt. |
| `-q, --quiet` | Avoid printing anything to the standard output, e.g. statistics. |
| `--help` | Show this message and exit. |

---

### `init`

Initialize a new CocoIndex project.

Creates a new project directory with starter files: 1. main.py (Main
application file) 2. pyproject.toml (Project metadata and dependencies) 3.
README.md (Quick start guide)

`PROJECT_NAME`: Name of the project (defaults to current directory name if
not specified).

**Usage:**

```bash
cocoindex init [OPTIONS] [PROJECT_NAME]
```

**Options:**

| Option | Description |
|--------|-------------|
| `--dir DIRECTORY` | Directory to create the project in. |
| `--help` | Show this message and exit. |

---

### `ls`

List all apps.

If `APP_TARGET` (`path/to/app.py` or `module`) is provided, lists apps
defined in that module and their persisted status, grouped by environment.

If `APP_TARGET` is omitted and `--db` is provided, lists all apps from the
specified database.

**Usage:**

```bash
cocoindex ls [OPTIONS] [APP_TARGET]
```

**Options:**

| Option | Description |
|--------|-------------|
| `--db TEXT` | Path to database to list apps from (only used when APP_TARGET is not specified). |
| `--help` | Show this message and exit. |

---

### `show`

Show the app's stable paths.

If `APP_TARGET` is provided, loads the app from the module.
Otherwise, `--db` and `--app-name` can be used to inspect an app
directly from its database without loading the module.

**Usage:**

```bash
cocoindex show [OPTIONS] [APP_TARGET] [STABLE_PATH]
```

**Options:**

| Option | Description |
|--------|-------------|
| `--db TEXT` | Path to database (used with --app-name when APP_TARGET is not specified). |
| `--app-name TEXT` | App name to inspect (used with --db when APP_TARGET is not specified). |
| `--tree` | Display stable paths (or --target-states entries) as a tree. |
| `-l, --long` | Display detailed information in multi-line format. |
| `-r, --recursive` | Show all children recursively (requires stable_path). |
| `-p, --parents` | Show all parent paths (requires stable_path). |
| `--fingerprints` | Show target-state paths as raw fingerprints (as stored) instead of readable keys. |
| `--target-states` | List all tracked target states with their owner components. |
| `--help` | Show this message and exit. |

---

### `update`

Run an app in catch-up mode. With --live, run in live mode.

Exits with status 1 if a component failure goes unhandled: no exception
handler is registered for it, or every handler re-raised. Not with --live.

`APP_TARGET`: `path/to/app.py`, `module`, `path/to/app.py:app_name`, or
`module:app_name`.

**Usage:**

```bash
cocoindex update [OPTIONS] APP_TARGET
```

**Options:**

| Option | Description |
|--------|-------------|
| `-f, --force` | Skip confirmation prompt. |
| `-q, --quiet` | Avoid printing anything to the standard output, e.g. statistics. |
| `--reset` | Drop existing setup before updating (equivalent to running 'cocoindex drop' first). |
| `--full-reprocess` | Reprocess everything, bypassing all memoization caches: every component and memoized function executes again (external calls such as embeddings included). To force just one function's work to run again, bump its version= instead. |
| `-L, --live` | Run in live mode (live components continue processing after initial update). |
| `--preview` | Compute target actions without applying them. Prints planned actions. |
| `--select PATH` | Run only the component at PATH and the components below it; repeat to run several. Write PATH as `cocoindex show` prints it, such as '/@process_file/"docs/a.md"'. Other components are not run and not treated as gone. |
| `--help` | Show this message and exit. |

---
