Skip to main content

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

Project description

wren-engine

PyPI version Python License

Wren 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 and Ibis.

Installation

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

Requires Python 3.11+.

Quick start

1. Create ~/.wren/mdl.json — your semantic model:

{
  "catalog": "wren",
  "schema": "public",
  "models": [
    {
      "name": "orders",
      "tableReference": { "schema": "mydb", "table": "orders" },
      "columns": [
        { "name": "order_id",    "type": "integer" },
        { "name": "customer_id", "type": "integer" },
        { "name": "total",       "type": "double" },
        { "name": "status",      "type": "varchar" }
      ],
      "primaryKey": "order_id"
    }
  ]
}

2. Configure a connection profile — pick one of three ways:

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

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

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

Or create ~/.wren/connection_info.json manually:

{
  "datasource": "mysql",
  "host": "localhost",
  "port": 3306,
  "database": "mydb",
  "user": "root",
  "password": "secret"
}

3. (Optional) Create ~/.wren/config.json — security policy:

{
  "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.

4. Run querieswren auto-discovers all files from ~/.wren (override with WREN_HOME=/path/to/dir):

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

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

4. Index schema for semantic search (optional, requires wren-engine[memory]):

wren memory index                              # index MDL schema
wren memory fetch -q "customer order price"    # fetch relevant schema context
wren memory store --nl "top customers" --sql "SELECT ..."  # store NL→SQL pair
wren memory recall -q "best customers"         # retrieve similar past queries

Connection profiles

Profiles let you store named connection configurations in ~/.wren/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)
wren profile add prod --ui                        # opens http://localhost:<port>
wren profile add staging --interactive            # terminal prompts
wren profile add local --from-file conn.json      # import existing file

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

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

# Remove a profile
wren 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 'wren-engine[ui]'.

Once a profile is active, wren uses it automatically:

wren profile switch prod
wren --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

just install-dev    # Install with dev dependencies
just lint           # Ruff format check + lint
just format         # Auto-fix
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 wren-engine[ui]:

uv sync --extra dev --extra ui --find-links ../wren-core-py/target/wheels/
uv run 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

License

Apache-2.0

Project details


Download files

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

Source Distribution

wren_engine-0.2.0rc1.tar.gz (268.6 kB view details)

Uploaded Source

Built Distribution

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

wren_engine-0.2.0rc1-py3-none-any.whl (81.1 kB view details)

Uploaded Python 3

File details

Details for the file wren_engine-0.2.0rc1.tar.gz.

File metadata

  • Download URL: wren_engine-0.2.0rc1.tar.gz
  • Upload date:
  • Size: 268.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wren_engine-0.2.0rc1.tar.gz
Algorithm Hash digest
SHA256 63bfdb0d935bde9192dac199c44c2fc56f9ded368f7a75a6797b81b156913e16
MD5 5923ee573fc9c898c14f4de9bd96b408
BLAKE2b-256 f6e0df6d56bddf099f30d239059154e0e45215b958206e6e4e5b495e83f501d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for wren_engine-0.2.0rc1.tar.gz:

Publisher: wren-pypi-publish.yml on Canner/wren-engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wren_engine-0.2.0rc1-py3-none-any.whl.

File metadata

  • Download URL: wren_engine-0.2.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 81.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wren_engine-0.2.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 5a91ff8e906d6c54741911ee003b7155555f92f65c75d3cea9a954a848d44783
MD5 f02911351a20abb3d4c8fe5164467f21
BLAKE2b-256 1dc2a5f9ff4514f1b95be91dad01a3dd12c8ad31bb808e7717b97e5cd68f30cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for wren_engine-0.2.0rc1-py3-none-any.whl:

Publisher: wren-pypi-publish.yml on Canner/wren-engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page