Skip to main content

Python SDK for Wvlet - A flow-style query language

Project description

Wvlet Python SDK

Python SDK for Wvlet - A flow-style query language for functional data modeling and interactive data exploration.

Features

  • 🚀 Fast native compilation - Uses bundled native library for high-performance query compilation
  • 🎯 Multiple SQL targets - Supports DuckDB, Trino, and other SQL engines
  • 📦 Zero dependencies - Pure Python with native acceleration
  • 🐍 Pythonic API - Simple and intuitive interface

Installation

From PyPI

pip install wvlet

From Source

# Install latest development version
pip install git+https://github.com/wvlet/wvlet.git#subdirectory=sdks/python

# Install editable version for development
git clone https://github.com/wvlet/wvlet.git
cd wvlet/sdks/python
pip install -e .

Quick Start

from wvlet import compile

# Compile a simple query
sql = compile("from users select name, age where age > 18")
print(sql)
# Output: SELECT name, age FROM users WHERE age > 18

# Use model references
sql = compile("""
model UserStats = {
  from users
  group by user_id
  agg count(*) as event_count
}

from UserStats
where event_count > 100
""")

Usage Guide

Basic Compilation

from wvlet import compile

# Simple select
sql = compile("from products select name, price")

# With filtering
sql = compile("from orders where status = 'completed' select order_id, total")

# With joins
sql = compile("""
from orders o
join customers c on o.customer_id = c.id
select o.order_id, c.name, o.total
""")

Using the Compiler Class

from wvlet.compiler import WvletCompiler

# Create compiler with specific target
compiler = WvletCompiler(target="trino")

# Compile multiple queries
queries = [
    "from users select count(*)",
    "from products where price > 100 select name, price"
]

for query in queries:
    sql = compiler.compile(query)
    print(sql)

Advanced Features

Window Functions

sql = compile("""
from sales
select 
  date,
  amount,
  sum(amount) over (order by date rows 7 preceding) as rolling_7day_sum
""")

CTEs and Models

sql = compile("""
model ActiveUsers = {
  from users 
  where last_login > current_date - interval '30' day
  select user_id, email
}

from ActiveUsers
select count(*) as active_user_count
""")

Pivoting Data

sql = compile("""
from sales
group by date
pivot sum(amount) for category in ('Electronics', 'Clothing', 'Food')
""")

Error Handling

from wvlet import compile
from wvlet.compiler import CompilationError

try:
    sql = compile("invalid query syntax")
except CompilationError as e:
    print(f"Compilation failed: {e}")
    # Access detailed error information
    if hasattr(e, 'line'):
        print(f"Error at line {e.line}: {e.message}")

API Reference

wvlet.compile(query: str, target: str = None) -> str

Compile a Wvlet query to SQL.

Parameters:

  • query (str): The Wvlet query to compile
  • target (str, optional): Target SQL dialect ("duckdb", "trino", etc.)

Returns:

  • str: The compiled SQL query

Raises:

  • CompilationError: If the query cannot be compiled
  • NotImplementedError: If the native library is not available for the current platform

wvlet.compiler.WvletCompiler

Main compiler class for more control over compilation.

__init__(self, target: str = None, wvlet_home: str = None)

Initialize a new compiler instance.

Parameters:

  • target (str, optional): Default target SQL dialect
  • wvlet_home (str, optional): Path to Wvlet home directory

compile(self, query: str, target: str = None) -> str

Compile a Wvlet query to SQL.

Parameters:

  • query (str): The Wvlet query to compile
  • target (str, optional): Override default target for this compilation

Returns:

  • str: The compiled SQL query

Supported Platforms

Native Library Support

Platform Architecture Status
Linux x86_64 ✅ Supported
Linux aarch64 ✅ Supported
macOS arm64 ✅ Supported
Windows x86_64 ✅ Supported
Windows arm64 ✅ Supported

Performance

The native library provides high-performance query compilation:

import time
from wvlet import compile

# Benchmark native compilation
start = time.time()
for _ in range(100):
    compile("from users select * where age > 21")
print(f"Compiled 100 queries in {time.time() - start:.2f}s")

Integration Examples

With Pandas and DuckDB

import pandas as pd
import duckdb
from wvlet import compile

# Compile Wvlet to SQL
wvlet_query = """
from sales.csv
where region = 'North America'
group by date
agg sum(amount) as total_sales
order by date
"""

sql = compile(wvlet_query, target="duckdb")

# Execute with DuckDB
conn = duckdb.connect()
df = conn.execute(sql).fetchdf()

With SQLAlchemy

from sqlalchemy import create_engine, text
from wvlet import compile

engine = create_engine("postgresql://user:pass@localhost/db")

wvlet_query = """
from orders o
join customers c on o.customer_id = c.id
where o.created_at > current_date - 7
group by c.name
agg sum(o.total) as weekly_total
"""

sql = compile(wvlet_query)  # Uses default SQL dialect

with engine.connect() as conn:
    result = conn.execute(text(sql))
    for row in result:
        print(row)

Development

Setting up Development Environment

# Clone the repository
git clone https://github.com/wvlet/wvlet.git
cd wvlet/sdks/python

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=wvlet

# Run specific test
pytest tests/test_compiler.py::test_basic_compilation

Building Wheels

# Build source distribution and wheel
python -m build

# Build platform-specific wheel
python -m build --wheel

Troubleshooting

Native Library Not Found

If you see an error about the native library not being found:

  1. Check your platform is supported (see Supported Platforms)
  2. Ensure you have the latest version: pip install --upgrade wvlet
  3. Try reinstalling: pip install --force-reinstall wvlet
  4. Use CLI fallback by installing the Wvlet CLI

Compilation Errors

For query compilation errors:

  1. Check query syntax matches Wvlet documentation
  2. Use the CLI to validate: wvlet compile "your query"
  3. Enable debug logging:
    import logging
    logging.basicConfig(level=logging.DEBUG)
    

Contributing

Contributions are welcome! Please see the main project contributing guide.

License

Apache License 2.0. See LICENSE for details.

Links

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

wvlet-2026.1.1.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

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

wvlet-2026.1.1-py3-none-macosx_11_0_arm64.whl (10.2 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file wvlet-2026.1.1.tar.gz.

File metadata

  • Download URL: wvlet-2026.1.1.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wvlet-2026.1.1.tar.gz
Algorithm Hash digest
SHA256 5d0d044699177b62b9323236a895c6e0bd008195df2a388c9c813a149ce22a12
MD5 3b5d9b2d03206c511100e181239d3153
BLAKE2b-256 f7ce3fe9e28456f799e04605a861cd119c2301a6f8b2ea411e96d5ba2ee0cb55

See more details on using hashes here.

Provenance

The following attestation bundles were made for wvlet-2026.1.1.tar.gz:

Publisher: python-publish.yml on wvlet/wvlet

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

File details

Details for the file wvlet-2026.1.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for wvlet-2026.1.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ebda511d9030b30856cf9007b3cfa115a287f4c9a1f56ea4d69658ce26d546aa
MD5 163659ce8bd709bdfb51f17ff678c3f7
BLAKE2b-256 7e8dc292d40b9066dec1664917f2a0eb9198def97cb2cfe3d92ce8ffe40dedb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for wvlet-2026.1.1-py3-none-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on wvlet/wvlet

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