You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
Copy file name to clipboardExpand all lines: docs/docs/core/basics.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -101,4 +101,4 @@ As an indexing flow is long-lived, it needs to store intermediate data to keep t
101
101
CocoIndex uses internal storage for this purpose.
102
102
103
103
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.
Copy file name to clipboardExpand all lines: docs/docs/core/cli.mdx
+33-34Lines changed: 33 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -8,60 +8,59 @@ import TabItem from '@theme/TabItem';
8
8
9
9
# CocoIndex CLI
10
10
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.
13
12
14
-
## Enable CocoIndex CLI
13
+
## Invoke the CLI
15
14
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.
17
16
18
-
The easiest way is to use a packaged main function:
17
+
### APP_TARGET Format
19
18
20
-
<Tabs>
21
-
<TabItemvalue="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`
22
25
23
-
```python title="main.py"
24
-
import cocoindex
26
+
### Environment Variables
25
27
26
-
@cocoindex.main_fn()
27
-
defmain():
28
-
...
29
-
```
28
+
Environment variables are needed as CocoIndex library settings, as described in [CocoIndex Settings](settings#list-of-environment-variables).
30
29
31
-
</TabItem>
32
-
</Tabs>
30
+
You can set environment variables in an environment file.
33
31
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:
35
34
36
-
```sh
37
-
$ python main.py cocoindex ls # Run "ls" subcommand: list all flows
Loaded variables do *NOT* override existing system ones.
40
+
If no file is found, only existing system environment variables are used.
39
41
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
41
43
42
-
### Explicitly CLI Invoke
44
+
CocoIndex CLI supports the following global options:
43
45
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.
46
49
47
-
<Tabs>
48
-
<TabItemvalue="python"label="Python"default>
50
+
:::caution Deprecated Usage
49
51
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.
53
53
54
-
</TabItem>
55
-
</Tabs>
54
+
:::
56
55
57
56
## Subcommands
58
57
59
58
The following subcommands are available:
60
59
61
60
| Subcommand | Description |
62
61
| ---------- | ----------- |
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. |
65
64
|`setup`| Check and apply backend setup changes for flows, including the internal and target storage (to export). |
66
65
|`drop`| Drop the backend setup for specified flows. |
67
66
|`update`| Update the index defined by the flow. |
@@ -71,6 +70,6 @@ The following subcommands are available:
71
70
Use `--help` to see the full list of subcommands, and `subcommand --help` to see the usage of a specific one.
72
71
73
72
```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
Copy file name to clipboardExpand all lines: docs/docs/core/flow_def.mdx
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -313,7 +313,7 @@ Following metrics are supported:
313
313
314
314
### Getting App Namespace
315
315
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,
317
317
to organize flows across different environments (e.g., dev, staging, production), team members, etc.
318
318
319
319
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:
0 commit comments