Metadata-Version: 2.5
Name: enciva
Version: 0.1.2
Summary: Official Python SDK and CLI for the Enciva geospatial processing platform and API.
Project-URL: Homepage, https://enciva.com
Project-URL: Documentation, https://enciva.com/guides
Author: AcuGIS
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: cli,enciva,etl,geospatial,gis
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx<1,>=0.27
Requires-Dist: rich>=13
Requires-Dist: tomli-w>=1.0
Requires-Dist: tomli>=2.0.1; python_version < '3.11'
Requires-Dist: typer>=0.12
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: twine>=6; extra == 'dev'
Description-Content-Type: text/markdown

# enciva

Official Python SDK and CLI for the [Enciva](https://enciva.com) geospatial
processing platform and API.

`enciva` is an HTTPS client for an existing Enciva installation. Processing
stays on the server. It does **not** require Docker, GDAL, DuckDB, QGIS, Go, or
a local Enciva server.

Fuller product documentation: [Enciva Guides](https://enciva.com/guides),
including the [command-line client](https://enciva.com/guides/reference/cli/).

## Install

This package is published as `enciva`:

```bash
pip install enciva
```

or

```bash
pipx install enciva
```

From a source checkout, Python 3.10 or newer:

```bash
cd clients/python
python -m pip install -e .
```

That provides the `enciva` executable and the `enciva` Python package.

## Authenticate

Create a Personal Access Token in **Enciva → Account → API Tokens**, then:

```bash
enciva auth login
```

Enter the Enciva URL (your installation origin, for example
`https://enciva.example.com` — not an `/api/v1` path) and the token.
Token input is hidden. On success: `Authenticated successfully.`

## Use

```bash
enciva jobs list
enciva sources list
enciva destinations list
enciva recipes list
enciva jobs run <id>
enciva workspace upload roads.gpkg
enciva transformations list
```

`--json` writes machine-readable JSON to stdout:

```bash
enciva jobs list --json
ID=$(enciva workspace upload roads.gpkg --json | jq -r '.id')
```

## Automation

```bash
export ENCIVA_URL=https://enciva.example.com
export ENCIVA_TOKEN=gjp_...

enciva jobs list --json
```

Hosted Enciva is `https://app.enciva.com`. A self-hosted installation uses
its own origin. Pass that origin to the client.

Credential precedence, highest wins:

1. `--url` / `--token`
2. `ENCIVA_URL` / `ENCIVA_TOKEN`
3. Saved configuration

## Configuration

`enciva config set-url` and `enciva config set-token` write a user-level
file, never the current working directory:

| OS | Path |
| --- | --- |
| Linux | `~/.config/enciva/config.toml` (`$XDG_CONFIG_HOME` if set) |
| macOS | `~/Library/Application Support/enciva/config.toml` |
| Windows | `%APPDATA%\enciva\config.toml` |

That file may contain a Personal Access Token. Permissions are set to `0600`
on Unix. `enciva config show` prints a masked token only.

Logout removes the local token. It does not revoke the PAT. Revoke tokens in
**Account → API Tokens**.

```bash
enciva auth status
enciva auth logout
```

## Commands

```
enciva --help
enciva --version

enciva auth …
enciva config …
enciva sources list|get|create|delete
enciva destinations list|get|create|delete
enciva jobs list|get|run|enable|disable|delete|create|update|runs|retry
enciva recipes list|get|create|delete
enciva workspace upload|info|preview|convert|download
enciva workspace transform get|set|clear|preview
enciva transformations list|show
```

Workspace processing is remote. Discover operations with
`enciva transformations list` and `enciva transformations show <id>`.

```bash
enciva workspace transform set <id> --file pipeline.json
```

```json
{
  "layers": ["apiary"],
  "operations": [
    {"type": "buffer", "distance": 10, "units": "source"}
  ]
}
```

`--debug` prints HTTP method, URL, and status to stderr (never the token).
`--insecure` disables TLS verification for development certificates only and is
not saved. TLS verification is on by default.

`enciva jobs create --file job.json` sends the public API body
(`POST /api/v1/jobs`). Existing Job JSON without `pipeline` is unchanged
and keeps legacy/inferred stage presence.

Optional Canvas stage flags:

```json
{
  "name": "Neighborhoods",
  "source_id": "…",
  "transform_mode": "sql",
  "sql": "SELECT * FROM source WHERE population > 1000",
  "output_format": "GeoJSON",
  "destination_id": "…",
  "destination_target": {"schema": "public", "table": "neighborhoods", "write_mode": "replace"},
  "schedule": {"kind": "daily", "timezone": "UTC", "hour": 2, "minute": 0},
  "pipeline": {
    "transform": false,
    "convert": false,
    "python": false
  }
}
```

| `pipeline` | Meaning |
| --- | --- |
| omitted | Legacy/inferred behavior (stages stay present) |
| `{}` | Legacy/inferred behavior (stages stay present) |
| explicit `false` | That stage is absent |
| explicit `true` | That stage is present |

Create and update preserve explicit `false` flags. `enciva jobs get`
shows recorded stages when the Job includes `pipeline`.

## Python

Package version 0.1.2 speaks the Enciva 0.9.10 public API. The SDK keeps its
own version number.

Create a Personal Access Token in **Enciva → Account → API Tokens**. The
examples below use placeholders. Do not commit a real token.

Hosted Enciva:

```python
import os
from enciva import Enciva

client = Enciva(
    url="https://app.enciva.com",
    token=os.environ["ENCIVA_TOKEN"],
)
print(client.me())
```

Self-hosted Enciva uses the same client and a different origin:

```python
client = Enciva(
    url="https://enciva.example.com",
    token=os.environ["ENCIVA_TOKEN"],
)
```

`url` and `token` may also come from `ENCIVA_URL` and `ENCIVA_TOKEN` when
omitted. Explicit constructor arguments always win. The token is sent as
`Authorization: Bearer` and is never logged, stored, or included in
exceptions.

List saved Sources and Destinations:

```python
sources = client.sources.list()
destinations = client.destinations.list()
```

Create a manual Job, run it, and read the result. `run` calls
`POST /api/v1/jobs/{id}/run`. `wait=True` polls when the first response is
still `queued` or `running`. Run Now delivers to the Destination in the Job.

```python
job = client.jobs.create({
    "name": "Neighborhoods",
    "source_id": sources[0]["id"],
    "output_format": "GeoJSON",
    "destination_id": destinations[0]["id"],
    "destination_target": {
        "schema": "public",
        "table": "neighborhoods",
        "write_mode": "replace",
    },
    "schedule": {"kind": "manual"},
    "enabled": False,
})
run = client.jobs.run(job["id"], wait=True)
print(run["id"], run["status"])
latest = client.jobs.get_run(job["id"], run["id"])
history = client.jobs.list_runs(job["id"])
```

Preview a schedule without saving it, and search timezone names:

```python
client.jobs.preview_schedule(
    {"kind": "daily", "timezone": "UTC", "hour": 2, "minute": 0},
    enabled=False,
)
client.jobs.timezones("utc")
```

`schedule.kind` may be `manual`, `interval`, `hourly`, `daily`, `weekly`,
`monthly`, or `cron`. A saved Job may also include a `prepare` plan. The
field is sent unchanged.

The AI Assistant PAT routes build an unsaved draft. They require
`pipelines:compose`. Provider keys stay on the server. Creating and editing
providers stays in the browser session.

```python
client.assistant.list_providers()
draft = client.assistant.generate({
    "instructions": "Convert neighborhoods to GeoJSON.",
    "timezone": "UTC",
})
```

### Upload

```python
ws = client.workspaces.upload("roads.gpkg")
print(ws.id, ws.status, ws.layers)
```

A Workspace preparation plan uses that Workspace id on
`POST /api/v1/jobs/{id}/prepare`. `None` clears it:

```python
ws.prepare({
    "version": 1,
    "input_kind": "text",
    "output_kind": "geojson",
    "operations": [{"op": "extract_json"}],
})
ws.prepare(None)
```

### Preview

```python
rows = ws.preview_data("roads", limit=50)
geojson = ws.preview_map("roads")["geojson"]
```

`preview_data` and `preview_map` return the server JSON, including fields,
counts, truncation, and CRS. `preview_map()["geojson"]` is a GeoJSON
FeatureCollection. Visualization is up to the caller.

### Transform

Discover operations from the server (do not hard-code a catalog):

```python
ops = client.transformations.list()
```

```python
ws.set_transformations(
    layers=["roads"],
    operations=[{"type": "buffer", "distance": 10, "units": "source"}],
)
```

SQL and Python are sibling fields, not operation types:

```python
ws.set_transformations(layers=["roads"], sql="SELECT * FROM source")
ws.set_transformations(python={"script": script, "filename": "script.py"})
ws.clear_transformations()
```

### Transformed preview

Uses the stored pipeline. The SDK does not resend or execute it locally.

```python
ws.preview_transformed_data("roads", limit=50)
ws.preview_transformed_map("roads")
```

### Convert and download

```python
ws.convert(output_format="GeoJSON", layers=["roads"])
output = ws.download("roads.geojson")
```

Download streams to disk. An existing file is not overwritten unless you pass
`overwrite=True`. Convert is currently synchronous (`status=completed`).

Saved Sources, Destinations, Recipes, and Jobs keep their existing methods.
Job create/update accept the same public body, including optional `pipeline`
flags. Helpers inspect recorded stages without inventing missing keys:

```python
from enciva import (
    Enciva,
    PipelineStages,
    job_pipeline,
    job_write_body,
    pipeline_stages,
    stage_included,
)

jobs = client.jobs.list()
client.jobs.run(jobs[0]["id"])

created = client.jobs.create({
    "name": "Neighborhoods",
    "source_id": "...",
    "output_format": "GeoJSON",
    "pipeline": pipeline_stages(transform=True, convert=True, python=False),
})
job_pipeline(created)
stage_included(created, "python")
```

Omitting `pipeline`, or sending `pipeline: {}`, keeps /api/v1 legacy/inferred
behavior. Explicit `false` removes that stage; leftover operations, format, or
Python on the body do not restore it.

### Errors

```python
try:
    ws.preview_transformed_map("other_layer")
except ValidationError as exc:
    print(exc.status_code, exc.code, exc.message, exc.details)
```

`timeout` (default 30s) is the ordinary HTTP timeout. `run_timeout` (default
600s) is used for upload, preview, convert, and download.

## Exit codes

| Code | Meaning |
| --- | --- |
| 0 | Success |
| 1 | Failure (including a finished Run with status `failed`) |
| 2 | Usage / local config |
| 3 | Authentication (401 / missing credentials) |
| 4 | Authorization (403 / missing PAT scope) |
| 5 | Not found (404) |
| 6 | Validation (400 / 409 / 422) |
| 7 | Network (DNS, connection refused, TLS, timeout) |
| 8 | Enciva server error (5xx) |

## Security

- PAT is sent as `Authorization: Bearer`, never as a query parameter
- Full PAT is not printed by `config show`, `auth status`, or default errors
- Source and Destination secrets from the API are not displayed
