Skip to main content

ontology-cli

PyPI version Python License

Ontology Engine CLI and Python SDK — semantic SQL layer for 20+ data sources.

Translate natural SQL queries through an MDL (Modeling Definition Language) semantic layer and execute them against your database. Powered by Apache DataFusion.

Installation

pip install ontology-cli                 # Core (DuckDB included)
pip install 'ontology-cli[postgres]'     # PostgreSQL
pip install 'ontology-cli[mysql]'        # MySQL
pip install 'ontology-cli[bigquery]'     # BigQuery
pip install 'ontology-cli[snowflake]'    # Snowflake
pip install 'ontology-cli[clickhouse]'   # ClickHouse
pip install 'ontology-cli[trino]'        # Trino
pip install 'ontology-cli[mssql]'        # SQL Server
pip install 'ontology-cli[databricks]'   # Databricks
pip install 'ontology-cli[redshift]'     # Redshift
pip install 'ontology-cli[spark]'        # Spark
pip install 'ontology-cli[athena]'       # Athena
pip install 'ontology-cli[oracle]'       # Oracle
pip install 'ontology-cli[memory]'       # Schema & query memory (LanceDB)
pip install 'ontology-cli[ui]'           # Browser-based profile form (starlette + uvicorn)
pip install 'ontology-cli[main]'         # memory + interactive prompts + ui
pip install 'ontology-cli[all]'          # All connectors + main

Requires Python 3.11+.

Quick start

1. Initialize a project — scaffolds a YAML-based MDL project:

mkdir my-project && cd my-project
ontology context init

This creates wren_project.yml, models/, and views/. Edit wren_project.yml to set your data_source and add models under models/:

# wren_project.yml
schema_version: 2
name: my_project
catalog: wren
schema: public
data_source: postgres
# models/orders/metadata.yml
name: orders
table_reference:
  schema: mydb
  table: orders
columns:
  - name: order_id
    type: integer
  - name: customer_id
    type: integer
  - name: total
    type: double
  - name: status
    type: varchar
primary_key: order_id

Already have an MDL JSON? Import it directly: ontology context init --from-mdl path/to/mdl.json

2. Configure a connection profile:

# Browser form (recommended, requires ontology-cli[ui])
ontology profile add my-db --ui

# Interactive terminal prompts
ontology profile add my-db --interactive

# Import from an existing connection file
ontology profile add my-db --from-file connection_info.json

3. Build the manifest:

ontology context build

This compiles YAML files into target/mdl.json. The CLI auto-discovers this file when you run queries from within the project directory.

4. Run queries:

ontology --sql 'SELECT order_id FROM "orders" LIMIT 10'

ontology walks up from the current directory to find wren_project.yml and uses target/mdl.json. You can also pass --mdl path/to/mdl.json explicitly.

For the full CLI reference and per-datasource connection field reference, see docs/cli.md and docs/connections.md.

4a. (Optional) Aggregation queries with cubes — define cubes under cubes/, then query them with a structured input instead of writing GROUP BY SQL by hand:

ontology cube list
ontology cube describe revenue
ontology cube query --cube revenue --measures total --time-dimension "order_date:month"

The translator produces DATE_TRUNC / GROUP BY / WHERE clauses for you and runs them through the same engine path as ontology --sql. See the Cube guide for full YAML structure and the CLI reference for all flags.

5. (Optional) Configure security policy — create ~/.ontology/config.json:

{
  "strict_mode": true,
  "denied_functions": ["pg_read_file", "dblink", "lo_import"]
}
Key Default Description
strict_mode false When true, every table in a query must be defined in the MDL. Queries referencing undeclared tables are rejected before execution.
denied_functions [] List of function names (case-insensitive) that are forbidden in queries.

6. (Optional) Index schema for semantic search (requires ontology-cli[memory]):

ontology memory index                              # index MDL schema
ontology memory fetch -q "customer order price"    # fetch relevant schema context
ontology memory store --nl "top customers" --sql "SELECT ..."  # store NL→SQL pair
ontology memory recall -q "best customers"         # retrieve similar past queries
ontology memory watch                              # auto-reindex on schema/query changes

7. (Optional) Build a shareable GenBI app — turn the context layer into a browser-side dashboard (powered by wren-core-wasm) and deploy it to Vercel or Cloudflare Pages. The CLI owns the build instruction + deterministic state; an agent authors the app from it:

ontology genbi build sales --prompt "orders dashboard" --data-mode snapshot  # print build instruction
# agent authors apps/sales/ from the instruction (mdl.json + data/*.parquet)
ontology genbi register sales --data-mode snapshot   # record the app
ontology genbi verify sales                          # preflight (files, MDL, data, secret scan)
ontology genbi open sales                            # local preview
ontology genbi deploy sales --provider vercel        # ship a shareable URL (preview; --prod for production)

Tokens come from the env / .env (VERCEL_TOKEN / CLOUDFLARE_API_TOKEN), never CLI flags; Cloudflare needs wrangler installed. See the GenBI guide and the CLI reference.

8. (Optional) Serve an MCP server — expose the project's query, schema, and knowledge tools to Claude Desktop/Code, Cursor, or any MCP client. Runs in-process against the compiled MDL — no ibis-server, no separate service:

ontology serve mcp                                # stdio (default) — client spawns this as a child process
ontology serve mcp --transport http --port 8080   # local Streamable HTTP for other clients

Requires ontology context build to have already run and the mcp extra: pip install 'ontology-cli[mcp]'. See the MCP guide and the CLI reference for the full tool/resource list and client wiring.


Connection profiles

Profiles let you store named connection configurations in ~/.ontology/profiles.yml and switch between them easily — useful when working across multiple databases or environments.

# Add a profile (browser form, interactive prompts, or file import)
ontology profile add prod --ui                        # opens http://localhost:<port>
ontology profile add staging --interactive            # terminal prompts
ontology profile add local --from-file conn.json      # import existing file

# List and switch profiles
ontology profile list                                 # * marks the active profile
ontology profile switch prod

# Inspect a profile (sensitive fields masked)
ontology profile debug prod

# Remove a profile
ontology profile rm old-profile --force

The --ui flag opens a browser-based form that auto-derives fields from each datasource's schema — including file upload for BigQuery credentials, variant selection for Databricks/Redshift, and sensible defaults for all 20+ supported sources. Requires pip install 'ontology-cli[ui]'.

Once a profile is active, ontology uses it automatically:

ontology profile switch prod
ontology --sql 'SELECT COUNT(*) FROM "orders"'        # connects using prod profile

Python SDK

import base64, orjson
from wren import WrenEngine, DataSource

manifest = { ... }  # your MDL dict
manifest_str = base64.b64encode(orjson.dumps(manifest)).decode()

with WrenEngine(manifest_str, DataSource.mysql, {"host": "...", ...}) as engine:
    result = engine.query('SELECT * FROM "orders" LIMIT 10')
    print(result.to_pandas())

Development

Prerequisites: just and uv. (Rust + Cargo are only needed for the local-engine recipes below.)

Standard setup (no Rust toolchain)

just install        # uv sync — pulls the prebuilt wren-core-py wheel from PyPI
just lint           # Ruff format check + lint
just format         # Auto-fix

just install is a plain uv sync: it installs the locked prebuilt wren-core-py engine binding and the development tools from uv's default dev dependency group. No compilation required. This is enough for all Python-side development. Use just install-extra <extra> or just install-all for data-source extras.

Engine development (changing the Rust core)

Only needed when you modify ../wren-core-py (or ../wren-core) and want core/wren to run against your local build. Requires Rust + Cargo.

just install-local    # uv sync + build the local wheel + overlay it into .venv
just use-local-core   # rebuild + re-overlay after each subsequent Rust change

The run recipes (just test*, just lint, just dev) use uv run --no-sync, so they never revert a locally overlaid engine back to the lockfile version. If dependencies change, re-run an install recipe first.

Command What it runs Docker needed
just test-unit Unit tests (engine, CTE rewriter, field registry, profiles) No
just test-duckdb DuckDB connector tests No
just test-postgres PostgreSQL connector tests Yes
just test-mysql MySQL connector tests Yes
just test All tests Yes

Profile web tests (test_profile_web.py) require ontology-cli[ui]:

uv sync --extra ui
uv run --no-sync pytest tests/test_profile_web.py -v

Publishing

./scripts/publish.sh            # Build + publish to PyPI
./scripts/publish.sh --test     # Build + publish to TestPyPI
./scripts/publish.sh --build    # Build only

Package identity

This distribution is ontology-cli (Ontology Engine). It is a fork of WrenAI (Apache-2.0) by Canner, Inc. Internal Python imports remain import wren. The engine dependency remains upstream wren-core-py.

  • CLI entrypoint: ontology (not wren)
  • Home directory: ~/.ontology via ONTOLOGY_HOME (no fallback to ~/.wren)
  • PyPI name: ontology-cli (not published in v0)
pip install -e ./core/wren
ontology --version                      # ontology-cli 0.13.4

License

Apache-2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ontology_cli-0.13.4.tar.gz (638.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ontology_cli-0.13.4-py3-none-any.whl (298.3 kB view details)

Uploaded Python 3

File details

Details for the file ontology_cli-0.13.4.tar.gz.

File metadata

  • Download URL: ontology_cli-0.13.4.tar.gz
  • Upload date:
  • Size: 638.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.5

File hashes

Hashes for ontology_cli-0.13.4.tar.gz
Algorithm Hash digest
SHA256 f6d5aedac7888fa33e40444dfdb7fceb508800b65068e2bbb83181b2713e90db
MD5 e86bc887ce41326afb76b4496a863322
BLAKE2b-256 aef4b44cd01853b6816d9331a9e38cda8802baef622e2c881c165ee03fe41ba6

See more details on using hashes here.

File details

Details for the file ontology_cli-0.13.4-py3-none-any.whl.

File metadata

  • Download URL: ontology_cli-0.13.4-py3-none-any.whl
  • Upload date:
  • Size: 298.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.5

File hashes

Hashes for ontology_cli-0.13.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f26e49e41cbc5858fa02067715cd6f79c459bc11af0f9c40bb15004def2d0d36
MD5 fc9ee2dd0f89f0807647c05b79991aea
BLAKE2b-256 a28a626f6b7bdeabdb09aaff37a9b4af6d99c809ba60e184ee785c17aaca045a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.13.4 This release

2 files

0.13.3

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page