@@ -790,6 +790,63 @@ When running in Positron IDE, the extension provides enhanced functionality:
790790
791791---
792792
793+ ### 8. Python Bindings (` ggsql-python/ ` )
794+
795+ ** Responsibility** : Python bindings for ggsql, enabling Python users to render Altair charts using ggsql's VISUALISE syntax.
796+
797+ ** Features** :
798+
799+ - PyO3-based Rust bindings compiled to a native Python extension
800+ - Works with any narwhals-compatible DataFrame (polars, pandas, etc.)
801+ - LazyFrames are collected automatically
802+ - Returns native ` altair.Chart ` objects for easy display and customization
803+ - Query splitting to separate SQL from VISUALISE portions
804+
805+ ** Installation** :
806+
807+ ``` bash
808+ # From source (requires Rust toolchain and maturin)
809+ cd ggsql-python
810+ pip install maturin
811+ maturin develop
812+ ```
813+
814+ ** API** :
815+
816+ ``` python
817+ import ggsql
818+ import polars as pl
819+
820+ # Split a ggSQL query into SQL and VISUALISE portions
821+ sql, viz = ggsql.split_query("""
822+ SELECT date, revenue FROM sales
823+ VISUALISE date AS x, revenue AS y
824+ DRAW line
825+ """ )
826+
827+ # Execute SQL and render to Altair chart
828+ df = pl.DataFrame({" x" : [1 , 2 , 3 ], " y" : [10 , 20 , 30 ]})
829+ chart = ggsql.render_altair(df, " VISUALISE x, y DRAW point" )
830+
831+ # Display or save
832+ chart.display() # In Jupyter
833+ chart.save(" chart.html" )
834+ ```
835+
836+ ** Functions** :
837+
838+ - ` split_query(query: str) -> tuple[str, str] ` - Split ggSQL query into SQL and VISUALISE portions
839+ - ` render_altair(df, viz, **kwargs) -> altair.Chart ` - Render DataFrame with VISUALISE spec to Altair chart
840+
841+ ** Dependencies** :
842+
843+ - Python >= 3.10
844+ - altair >= 5.0
845+ - narwhals >= 2.15
846+ - polars >= 1.0
847+
848+ ---
849+
793850## Feature Flags and Build Configuration
794851
795852ggsql uses Cargo feature flags to enable optional functionality and reduce binary size.
@@ -822,9 +879,9 @@ ggsql uses Cargo feature flags to enable optional functionality and reduce binar
822879 - Includes: ` axum ` , ` tokio ` , ` tower-http ` , ` tracing ` , ` duckdb ` , ` vegalite `
823880 - Required for building ` ggsql-rest ` server
824881
825- ** Future features ** :
882+ ** Python bindings ** :
826883
827- - ` python ` - Python bindings via PyO3 (planned )
884+ - ` ggsql- python` - Python bindings via PyO3 (separate crate, not a feature flag )
828885
829886### Building with Custom Features
830887
@@ -850,7 +907,7 @@ cargo build --all-features
850907- ` postgres ` → ` postgres ` crate (future)
851908- ` sqlite ` → ` rusqlite ` crate (future)
852909- ` rest-api ` → ` axum ` , ` tokio ` , ` tower-http ` , ` tracing ` , ` tracing-subscriber `
853- - ` python ` → ` pyo3 ` crate (future )
910+ - ` ggsql- python` → ` pyo3 ` , ` narwhals ` , ` altair ` (separate workspace crate )
854911
855912---
856913
0 commit comments