Metadata-Version: 2.4
Name: xoople-cli
Version: 0.8.0
Summary: Command-line interface for the Xoople Products API.
License-Expression: LicenseRef-Xoople-Proprietary
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: xoople-sdk>=0.11.0
Requires-Dist: cyclopts>=4.18,<5
Requires-Dist: rich>=13.7
Requires-Python: >=3.12
Project-URL: Homepage, https://xoople.com
Description-Content-Type: text/markdown

# xoople-cli

Command-line interface for the Xoople Products API, over [`xoople-sdk`](../xoople-sdk).

```console
$ uv tool install xoople-cli
$ export XOOPLE_API_URL=https://api.xoople.com XOOPLE_TOKEN=...
$ xoople analyses list
```

Every command reads `--api-url` and `--token` from `XOOPLE_API_URL` and
`XOOPLE_TOKEN`. `--json` prints the response as the SDK parses it instead of a
table, so output pipes into `jq`. Every field the SDK model declares appears, and
one the API leaves out uses the SDK model's default, which may be `null`. A field
the API sends but this SDK version does not declare is dropped.

## Commands

| Group | Commands |
| --- | --- |
| `analyses` | `list` `get` `status` `create` `update` `cancel` `delete` `run-again` `estimate-run-again` `estimate` |
| `projects` | `list` `create` `get` `update` `members` `add-member` `remove-member` `move` `archive` `delete` `record-access` `recent` |
| `runs` | `list` `get` |
| `outputs` | `list` `get` `access-url` `summary` `preview` `refresh-summary` |
| `packages` | `create` `list` `get` `access-url` `delete` |
| `schedules` | `list` `get` `create` `pause` `resume` `cancel` `run` `estimate-run` |
| `aois` | `list` `get` `geometry` `create` `update` `delete` `duplicate` |
| `aoi-uploads` | `create` `lookup` `get` `rows` `delete` |
| `events` | `list` `get` |
| `usage` | `history` `limits` |
| `catalog` | `products` `measures` `projections` `cloud-mask-presets` `designs` |
| `questions` | `list` `show` `ask` |
| `access` | `me` `token` `rotate-token` `features` |
| `auth` | `login` `logout` `status` |
| `skills` | `install` `update` `uninstall` `status` |

`outputs access-url` works only for a product that declares the
`outputs.download` capability, which is Imagery Time Series today. On a tabular
output the API answers 422 `unsupported_operation` and the CLI exits `6`. Read
tabular rows over Delta Sharing (`access token`), or export a Tabular Time Series
analysis with `packages create`.

## Signing in

`auth login` signs in through the browser with PKCE and stores the session at
`$XDG_CONFIG_HOME/xoople/session.json` (`~/.config/xoople/session.json` by
default), readable only by you. Every later command uses that session when
no `--token` is given, and refreshes it when the
access token is close to expiry.

```console
$ export XOOPLE_API_URL=https://api.xoople.com
$ xoople auth login
$ xoople analyses list
```

`auth login` reads the CIAM client ID from the API. `--ciam-client-id`
(`XOOPLE_CIAM_CLIENT_ID`) overrides it. `auth status` exits `3` when there is no
stored session, so a script can test for a sign-in. `--ciam-redirect-uri` (`XOOPLE_CIAM_REDIRECT_URI`) overrides the
loopback URI the browser returns to; it must match a URI registered for the
CIAM client.

## API keys

An API key lets a script or a CI job run the CLI without a browser sign-in.
Create one on the **API keys** section of your Xoople profile page (`/profile`).
The key starts with `sk_` and is shown once, so store it in a secret manager.

A key belongs to one organization membership. It acts as you, in the
organization that was active when you created it, with that membership's roles.
To work in a different organization, create a key there.

Pass the key as the token. It takes precedence over a stored session:

```console
$ export XOOPLE_API_URL=https://api.xoople.com XOOPLE_TOKEN=sk_...
$ xoople access me
```

The API accepts at most 300 API key requests a minute from one IP address. The
CLI retries rate-limited GETs and replay-safe writes with backoff, then exits
`8`. Any other write exits `8` on the first 429, with no retry. Revoke a key on
the same profile page when you no longer need it.

## Submitting an analysis

The product spec is deeply nested and differs per product, so `create` and
`estimate` take it as JSON rather than as flags:

```console
$ xoople catalog designs --product tabular_time_series --json | jq '.[0].spec_fragment | {product: "tabular_time_series", period: {start: "2024-01-01", end: "2024-06-30"}, aoi: [-1.5, 52.0, -1.0, 52.5], spatial_partition: {type: "h3", target_cells: 5000}, measures}' > spec.json
$ xoople analyses create -f spec.json --display-name "South Wales NDVI" --wait
```

A design's `spec_fragment` holds only what to measure, so the `jq` filter adds the
product, period, area and grid around its `measures`. The cadence defaults to monthly.

The file holds either the bare spec or a whole create request (anything with a
`spec` key). `-f -` reads stdin. `--wait` polls the initial run and exits
non-zero if it does not reach `COMPLETE`.

## Saving an area from a file

`aoi-uploads create` checks a CSV, xlsx, GeoJSON or zipped Shapefile of at most
50 MiB row by row and prints the counts, the first rows that failed or warned,
and how to fix each reason. The API reads the file after the upload, so the
command waits for it, up to `--wait-timeout` seconds (default 1200, then exit
`13`). Nothing is saved yet. `aois create --from-upload`
saves the accepted rows:

```console
$ xoople aoi-uploads create orchards.csv --radius 250
$ xoople aoi-uploads rows <upload-id> --status fail --status warn
$ xoople aois create --from-upload <upload-id> --name "Orchards"
```

`aoi-uploads rows --output` saves the rows as a CSV file instead of printing them,
and prints its path and the number of rows. It takes the rows with status `fail`
unless you pass `--status`, and refuses `--limit`. Fix the cells in the file and upload
it again. If the upload is deleted during the download, the file can end early and
look complete, so download again after any delete or expiry:

```console
$ xoople aoi-uploads rows <upload-id> --output rejected.csv
```

A file of addresses (`id,address` and an optional `country`) waits for its lookup.
`aoi-uploads create` asks on a terminal before it looks them up, because an upload
counts its unique addresses once on the stored address lookup limit, on the first
lookup that sends them. Say no and it
prints how to look them up later and how to delete the upload. With no terminal,
or with `--json`, it prints the upload and exits `18` unless `--confirm-lookup`
is set. `aoi-uploads lookup` runs the lookup for an upload that waits:

```console
$ xoople aoi-uploads create sites.csv --radius 100 --confirm-lookup
$ xoople aoi-uploads lookup <upload-id>
```

A 429 or 503 on a lookup prints `retry in N s`. Run `lookup` again after that
wait. It sends only the addresses with no result, and a retry counts none again,
except after a 503 `AOI_LOOKUP_NOT_STORED` that came before any address was sent.
After a timeout the server may still run the lookup. Wait, then run
`xoople aoi-uploads get <upload-id>`. If the status is no longer `needs_lookup`,
the lookup finished. An immediate retry answers 409 `AOI_LOOKUP_IN_PROGRESS`. A
502 or 504 from a gateway is handled like a timeout. Ctrl-C during a lookup
prints the same advice and exits `130`.

An upload is deleted 24 hours after it is created. `aoi-uploads create` exits `0`
for an upload with status `failed` (no row accepted, nothing to save), so a script
reads `status` from `--json` or `aoi-uploads get`. A file the API refuses as a whole
prints its reason and hint and exits `6`. A 429 or 503 prints
`retry in N s` when the API sent a `Retry-After`. `aois create -f aoi.json`
saves an area from a JSON body instead. A file over 50 MiB exits `6` before
anything is sent.

## Exit codes

`0` success · `1` unexpected CLI error · `2` usage error ·
`3` unauthenticated, including a failed or absent sign-in · `4` forbidden ·
`5` not found · `6` bad request or validation · `7` conflict · `8` rate limited ·
`9` server error · `10` connection failure · `11` unreadable response ·
`12` run finished in a non-`COMPLETE` state · `13` `--wait` timed out ·
`14` the analysis was deleted · `15` the view a question reads is still
being built, ask again shortly · `16` that view's last build failed, refresh
it explicitly; `17` the project was deleted · `18` an upload of addresses waits
for its lookup · `130` Ctrl-C stopped an address lookup.
