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
  2. prql_query = """
  3. from employees
  4. join salaries (==emp_id)
  5. group {employees.dept_id, employees.gender} (
  6. aggregate {
  7. avg_salary = average salaries.salary
  8. }
  9. )
  10. """
  11. options = prql.CompileOptions(
  12. format=True, signature_comment=True, target="sql.postgres"
  13. )
  14. sql = prql.compile(prql_query)
  15. sql_postgres = prql.compile(prql_query, options)

Relies on pyo3 for all the magic.