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[all]'       # All connectors + memory

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. Create ~/.wren/connection_info.json — your connection:

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

3. Run querieswren auto-discovers both files from ~/.wren:

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

For the full CLI reference and per-datasource connection_info.json formats, 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

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 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

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.1.0.tar.gz (230.3 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.1.0-py3-none-any.whl (44.3 kB view details)

Uploaded Python 3

File details

Details for the file wren_engine-0.1.0.tar.gz.

File metadata

  • Download URL: wren_engine-0.1.0.tar.gz
  • Upload date:
  • Size: 230.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for wren_engine-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd6f9e26b80527a272baa2ca7dadcab71ef61a9d016ab542675f8873403f2bd3
MD5 f53bbfd9c92f63edca6c8d11fe7699d2
BLAKE2b-256 35f37140605490d7d74cda05d6a4dbf3dcd340afe98fe760f56c95f86d26b6ef

See more details on using hashes here.

File details

Details for the file wren_engine-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wren_engine-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 44.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for wren_engine-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 411c014337ec190064ca3280c7f0717e4477c58a315c8580345c570c77db4d05
MD5 073d3bc5de19791a1942afbebcb7dea1
BLAKE2b-256 25f4233d9bf1ec285e161e57ddc025ce0cfb5ff891f49404ff2af74c5b06380c

See more details on using hashes here.

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