prql-python

prql-python offers Rust bindings to the prql-compiler Rust library. It exposes a Python method compile(query: str) -> str.

This is consumed by PyPrql & dbt-prql.

The crate is not published to crates.io; only to PyPI at <https://pypi.org/project/prql-python/>.

Installation

pip install prql-python

Usage

1. import prql_python as prql

3. prql_query = """
4. from employees
5. join salaries (==emp_id)
6. group {employees.dept_id, employees.gender} (
7. aggregate {
8. avg_salary = average salaries.salary
9. }
10. )
11. """

13. options = prql.CompileOptions(
14. format=True, signature_comment=True, target="sql.postgres"
15. )

17. sql = prql.compile(prql_query)
18. sql_postgres = prql.compile(prql_query, options)

Relies on pyo3 for all the magic.