Skip to content

Commit f0c5618

Browse files
migrate: update docs and examples for new standalone CLI (#530)
* Update docs and examples for new standalone CLI (#524) * Update docs for standalond CLI usage * Update examples for standalond CLI usage * Refine some expressions to make docs clearer * docs: update to `cocoindex main.py ...` * docs: fix ordering * chore: update example main function to call `cocoindex.init()` if needed * docs: add `cocoindex.init()` call for quickstart * docs: further update docs for new CLI * chore: bump examples dep versions for cocoindex * chore: further cleanups for examples --------- Co-authored-by: Miao <one.lemorage@gmail.com>
1 parent f0bc9fe commit f0c5618

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+274
-340
lines changed

docs/docs/core/basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ As an indexing flow is long-lived, it needs to store intermediate data to keep t
101101
CocoIndex uses internal storage for this purpose.
102102

103103
Currently, CocoIndex uses Postgres database as the internal storage.
104-
See [Initialization](initialization) for configuring its location, and `cocoindex setup` CLI command (see [CocoIndex CLI](cli)) creates tables for the internal storage.
104+
See [Settings](settings#databaseconnectionspec) for configuring its location, and `cocoindex setup` CLI command (see [CocoIndex CLI](cli)) creates tables for the internal storage.

docs/docs/core/cli.mdx

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,60 +8,59 @@ import TabItem from '@theme/TabItem';
88

99
# CocoIndex CLI
1010

11-
CocoIndex CLI embeds CLI functionality in your program.
12-
It provides a bunch of commands for easily managing and inspecting your flows and indexes.
11+
CocoIndex CLI is a standalone tool for easily managing and inspecting your flows and indexes.
1312

14-
## Enable CocoIndex CLI
13+
## Invoke the CLI
1514

16-
### Use Packaged Main
15+
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 flow definitions are located.
1716

18-
The easiest way is to use a packaged main function:
17+
### APP_TARGET Format
1918

20-
<Tabs>
21-
<TabItem value="python" label="Python" default>
19+
The `APP_TARGET` can be:
20+
1. A **path to a Python file** defining your flows (e.g., `main.py`, `path/to/my_flows.py`).
21+
2. An **installed Python module name** that contains your flow definitions (e.g., `my_package.flows`).
22+
3. For commands that operate on a *specific flow* (like `show`, `update`, `evaluate`), you can combine the application reference with a flow name:
23+
* `path/to/my_flows.py:MyFlow`
24+
* `my_package.flows:MyFlow`
2225

23-
```python title="main.py"
24-
import cocoindex
26+
### Environment Variables
2527

26-
@cocoindex.main_fn()
27-
def main():
28-
...
29-
```
28+
Environment variables are needed as CocoIndex library settings, as described in [CocoIndex Settings](settings#list-of-environment-variables).
3029

31-
</TabItem>
32-
</Tabs>
30+
You can set environment variables in an environment file.
3331

34-
With this, when the program is executed with `cocoindex` as its first argument, CocoIndex CLI will take over the control. For example:
32+
* By default, the `cocoindex` CLI searches upward from the current directory for a `.env` file.
33+
* You can use `--env-file <path>` to specify one explicitly:
3534

36-
```sh
37-
$ python main.py cocoindex ls # Run "ls" subcommand: list all flows
38-
```
35+
```sh
36+
cocoindex --env-file path/to/custom.env <COMMAND> ...
37+
```
38+
39+
Loaded variables do *NOT* override existing system ones.
40+
If no file is found, only existing system environment variables are used.
3941

40-
You may also provide a `cocoindex_cmd` argument to the `main_fn` decorator to change the command from `cocoindex` to something else.
42+
### Global Options
4143

42-
### Explicitly CLI Invoke
44+
CocoIndex CLI supports the following global options:
4345

44-
An alternative way is to use `cocoindex.cli.cli` (with type [`click.Group`](https://click.palletsprojects.com/en/stable/api/#click.Group)).
45-
For example, you may invoke the CLI explicitly with additional arguments:
46+
* `--env-file <path>`: Load environment variables from a specified `.env` file. If not provided, `.env` in the current directory is loaded if it exists.
47+
* `--version`: Show the CocoIndex version and exit.
48+
* `--help`: Show the main help message and exit.
4649

47-
<Tabs>
48-
<TabItem value="python" label="Python" default>
50+
:::caution Deprecated Usage
4951

50-
```python
51-
cocoindex.cli.cli.main(args)
52-
```
52+
The old method of invoking the CLI using `python main.py cocoindex ...` via the `@cocoindex.main_fn()` decorator is now deprecated. Please remove `@cocoindex.main_fn()` from your scripts and use the standalone cocoindex command as described.
5353

54-
</TabItem>
55-
</Tabs>
54+
:::
5655

5756
## Subcommands
5857

5958
The following subcommands are available:
6059

6160
| Subcommand | Description |
6261
| ---------- | ----------- |
63-
| `ls` | List all flows present in the current process. Or list all persisted flows under the current app namespace if `--all` is specified. |
64-
| `show` | Show the spec for a specific flow. |
62+
| `ls` | List all flows present in the given file/module. Or list all persisted flows under the current app namespace if no file/module specified. |
63+
| `show` | Show the spec and schema for a specific flow. |
6564
| `setup` | Check and apply backend setup changes for flows, including the internal and target storage (to export). |
6665
| `drop` | Drop the backend setup for specified flows. |
6766
| `update` | Update the index defined by the flow. |
@@ -71,6 +70,6 @@ The following subcommands are available:
7170
Use `--help` to see the full list of subcommands, and `subcommand --help` to see the usage of a specific one.
7271

7372
```sh
74-
python main.py cocoindex --help # Show all subcommands
75-
python main.py cocoindex show --help # Show usage of "show" subcommand
73+
cocoindex --help # Show all subcommands
74+
cocoindex show --help # Show usage of "show" subcommand
7675
```

docs/docs/core/flow_def.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Following metrics are supported:
313313

314314
### Getting App Namespace
315315

316-
You can use the [`app_namespace` setting](initialization#app-namespace) or `COCOINDEX_APP_NAMESPACE` environment variable to specify the app namespace,
316+
You can use the [`app_namespace` setting](settings#app-namespace) or `COCOINDEX_APP_NAMESPACE` environment variable to specify the app namespace,
317317
to organize flows across different environments (e.g., dev, staging, production), team members, etc.
318318

319319
In the code, You can call `flow.get_app_namespace()` to get the app namespace, and use it to name certain backends. It takes the following arguments:

docs/docs/core/flow_methods.mdx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: Flow Running
2+
title: Run a Flow
33
toc_max_heading_level: 4
44
description: Run a CocoIndex Flow, including build / update data in the target storage and evaluate the flow without changing the target storage.
55
---
66

77
import Tabs from '@theme/Tabs';
88
import TabItem from '@theme/TabItem';
99

10-
# Running a CocoIndex Flow
10+
# Run a CocoIndex Flow
1111

1212
After a flow is defined as discussed in [Flow Definition](/docs/core/flow_def), you can start to transform data with it.
1313

@@ -30,17 +30,7 @@ def demo_flow(flow_builder: cocoindex.FlowBuilder, data_scope: cocoindex.DataSco
3030
```
3131

3232
It creates a `demo_flow` object in `cocoindex.Flow` type.
33-
To enable CLI, you also need to make sure you have a main function decorated with `@cocoindex.main_fn()`:
3433

35-
36-
```python title="main.py"
37-
@cocoindex.main_fn()
38-
def main():
39-
...
40-
41-
if __name__ == "__main__":
42-
main()
43-
```
4434
</TabItem>
4535
</Tabs>
4636

@@ -78,7 +68,7 @@ The `cocoindex update` subcommand creates/updates data in the target storage.
7868
Once it's done, the target data is fresh up to the moment when the function is called.
7969

8070
```sh
81-
python main.py cocoindex update
71+
cocoindex update main.py
8272
```
8373

8474
#### Library API
@@ -115,7 +105,7 @@ Change capture mechanisms enable CocoIndex to continuously capture changes from
115105
To perform live update, run the `cocoindex update` subcommand with `-L` option:
116106

117107
```sh
118-
python main.py cocoindex update -L
108+
cocoindex update main.py -L
119109
```
120110

121111
If there's at least one data source with change capture mechanism enabled, it will keep running until the aborted (e.g. by `Ctrl-C`).
@@ -232,7 +222,7 @@ It takes the following options:
232222
Example:
233223

234224
```sh
235-
python main.py cocoindex evaluate --output-dir ./eval_output
225+
cocoindex evaluate main.py --output-dir ./eval_output
236226
```
237227

238228
### Library API

docs/docs/core/initialization.mdx

Lines changed: 0 additions & 134 deletions
This file was deleted.

0 commit comments

Comments
 (0)