This tutorial creates one self-contained model and queries it from the CLI. You do not need to configure a database or install SQLCtx first.

## 1. Create a Model

Create `models/orders.yml`:

```yaml doc-file=models/orders.yml
models:
  - name: orders
    sql: |
      select * from (values
        (1, 'paid',    120.00),
        (2, 'paid',     80.00),
        (3, 'pending',  50.00)
      ) as t(id, status, amount)
    primary_key: id

    dimensions:
      - name: status
        type: categorical
        sql: status

    metrics:
      - name: revenue
        agg: sum
        sql: amount

      - name: order_count
        agg: count
```

The model uses inline DuckDB data so it runs anywhere. In a real project, replace `sql` with a table name or SQL query and configure your warehouse connection.

## 2. Query the Metrics

Run SQLCtx directly with `uvx`:

```bash doc-test
uvx sqlctx query "SELECT orders.status, orders.revenue, orders.order_count FROM orders ORDER BY orders.status" --models ./models
```

Expected:

```csv doc-expected
status,revenue,order_count
paid,200.00,2
pending,50.00,1
```

SQLCtx resolved the named dimension and metrics, generated DuckDB SQL, executed it, and returned the governed result.

## 3. Inspect the Generated SQL

Add `--dry-run` to compile without executing:

```bash doc-test
uvx sqlctx query "SELECT orders.status, orders.revenue FROM orders" --models ./models --dry-run
```

This is useful when reviewing metric logic or debugging warehouse-specific SQL.

## Where to Go Next

- Open the interactive terminal explorer: `uvx --from "sqlctx[workbench]" sqlctx workbench ./models`
- Connect a warehouse: [Connections](connections)
- Import existing Cube, MetricFlow, LookML, Power BI, or other models: [Import Existing Models](adapters)
- Build a multi-model layer: [Models](models), [Metrics](metrics), and [Relationships](relationships)
- Pick a consumption or deployment workflow: [Choose Your Path](choose-your-path)

## Install in a Project

Use `uv add sqlctx` to install SQLCtx from PyPI as a project dependency. Run project commands with `uv run sqlctx`. Optional features are installed as extras:

```bash doc-validate=lint
# Terminal workbench
uv add "sqlctx[workbench]"

# HTTP API, browser UI, and MCP (sqlctx serve)
uv add "sqlctx[api,mcp]"

# PostgreSQL wire server
uv add "sqlctx[serve]"

# Power BI TMDL and DAX
uv add "sqlctx[dax]"

# Optional native Rust engine (installs the sqlctx-rs wheel)
uv add "sqlctx[rust]"

# Malloy
uv add "sqlctx[malloy]"

# Jupyter or Marimo widget
uv add "sqlctx[widget]" jupyterlab
```

Python remains the default engine. After installing the `rust` extra, select the native runtime with `uv run sqlctx query "SELECT orders.revenue FROM orders" --models ./models --engine rust` (or `--engine auto` for automatic selection).

Native models can also be authored with [semantic SQL DDL](sql-ddl-reference) or the [Python API](python-api). The guides use YAML as the canonical tutorial syntax.