# CLI: install, sign in and work
Source: https://sovaria.in/docs/cli-guide

Install sovaria-cli, sign in (browser, email or CI tokens), choose the organization and project, link a folder, everyday workflows, output for scripts, exit codes and troubleshooting.

## Install

pipx:
```bash
pipx install sovaria-cli
sov --version
```

pip:
```bash
pip install sovaria-cli
```

Python 3.11 or newer. The command is `sov`. This page and the [CLI reference](https://sovaria.in/docs/cli-reference) describe the current CLI; run `pipx upgrade sovaria-cli` if a command is missing.

### More command groups

| Group | What for | Example |
|---|---|---|
| `sov iam` | Organizations, projects, members and their roles, and organization settings | `sov iam members` |
| `sov project export` | Download a project's data bundle (waits for it and saves it) | `sov project export -o backup.zip` |
| `sov saml` | App-user SAML connections ([SAML single sign-on for your app (Okta, Entra ID, Google Workspace)](https://sovaria.in/docs/saml-sso)) | `sov saml list` |
| `sov attest` | App attestation: which services require it, the provider and debug tokens | `sov attest show` |
| `sov auth-config`, `sov auth-orgs`, `sov auth-product` | Sign-in settings, app organizations, and your app's users and roles | `sov auth-product users` |
| `sov sms` | The SMS provider and which countries may receive codes | `sov sms countries` |
| `sov sovariq` | Sovariq usage, credits and credit packs | `sov sovariq credits` |
| `sov context`, `sov schema describe`, `sov inspect`, `sov shell` | What the CLI is pointed at, the database schema, a quick health look, an interactive SQL shell | `sov schema describe` |

Every command and flag is in the [CLI reference](https://sovaria.in/docs/cli-reference); `sov <group> --help` lists a group's commands.

## Sign in

| How | Command | Use |
|---|---|---|
| Browser | `sov login` | Your own machine. Opens the console to approve the sign-in. |
| Email | `sov login --email you@example.com` (password from the prompt or `SOVARIA_PASSWORD`) | Machines without a browser. |
| Token or key | `SOVARIA_ACCESS_TOKEN` or `SOVARIA_API_KEY` in the environment | CI — no login step, nothing stored. |

The session is stored in your OS keyring (or `~/.sovaria/credentials.toml`, readable only by you, with `--file-storage`). `sov whoami` shows who you are; `sov logout` signs out.

### Profiles and hosts

Use `--profile <name>` (or `SOVARIA_PROFILE`) to keep several accounts side by side, for example a work and a personal organization. A saved login is only ever sent to the API host it was made on, so a profile pointed at a different host signs in again instead of reusing another host's token.

On a machine with no `~/.sovaria/config.yaml`, `sov login` says it is signing in to Sovaria Cloud. From a script (no terminal, or `SOVARIA_PASSWORD` set) it refuses until you name the target with `--profile prod` or `SOVARIA_PROFILE`, so a test login can't land on production by accident.

CLI:
```bash
sov login --profile work           # one account
sov login --profile prod           # another, on Sovaria Cloud
SOVARIA_PROFILE=prod sov whoami
```

`sov gen types` writes table and enum names only as quoted strings or checked identifiers, so an oddly named table can't put code into the generated file.

## Choose the project

CLI:
```bash
sov scope pick              # choose organization and project interactively
sov scope show
sov init                    # in a project folder: pick and write sovaria.config.json
sov link                    # link this folder to an existing project
```

Commands use, in order: flags (`--org`, `--project`), the folder's `sovaria.config.json`, then the scope from `sov scope set`. Commit `sovaria.config.json` — it holds ids and the URL, no secrets.

## Everyday workflows

| Task | Commands |
|---|---|
| Run SQL | `sov db sql "select count(*) from orders"` |
| Migrations | `sov db migrations new add_reviews` → edit → `sov db migrations push --dry-run` → `sov db migrations push` ([Migrations](https://sovaria.in/docs/migrations)) |
| Pull the live schema | `sov db pull`, `sov db diff` |
| Generate types | `sov gen types` |
| Functions | `sov fn serve` (run locally) → `sov fn deploy` → `sov fn logs <name>` ([Deploying and running functions](https://sovaria.in/docs/functions-deploy-and-run)) |
| Access checks | `sov policy check …`, `sov rules test`, `sov sim run --fail-on critical` ([CI/CD](https://sovaria.in/docs/ci-cd)) |
| Storage | `sov storage upload`, `sov storage ls` |
| Keys | `sov keys list`, `sov keys create`, `sov keys revoke` |

## In scripts

- `--json` (or `SOV_JSON=1`) prints raw JSON for `jq` and other tools.
- `SOV_DEBUG=1` shows full error traces.
- Exit codes: `0` success; `1` a request failed or a check found problems (failing rules tests, simulation findings at `--fail-on`); `2` invalid usage or input.

## Troubleshooting

| Message | Fix |
|---|---|
| Not signed in / session expired | `sov login` again, or set `SOVARIA_ACCESS_TOKEN` in CI. |
| No project selected | `sov scope pick`, `sov link`, or pass `--project`. |
| `403` on a command | Your member role doesn't allow it ([Organizations, members and roles](https://sovaria.in/docs/organizations)) or a plan limit applies. |
| `No such command` | Upgrade: `pipx upgrade sovaria-cli`. |
| Keyring errors on a server | Use `sov login --file-storage`, or environment variables. |
