pyprql contains:
- pyprql.pandas_accessor — Pandas integration for PRQL
- pyprql.polars_namespace — Polars integration for PRQL
- pyprql.magic — IPython magic for connecting to databases using
%%prql - pyprql.compile — An export of
prqlc'scompilefunction
For docs, check out the pyprql docs, and the PRQL Book.
pip install pyprqlOr, install with optional dependencies:
pip install pyprql[polars]importpandasaspdimportpyprql.pandas_accessordf= (...)
results_df=df.prql.query("select {age, name, occupation} | filter age > 21")importpolarsasplimportpyprql.polars_namespacedf= (...)
results_df=df.prql.query("select {age, name, occupation} | filter age > 21")In [1]: %load_extpyprql.magicIn [2]: %prqlpostgresql://user:password@localhost:5432/databaseIn [3]: %%prql
...: fromp
...: groupcategoryID (
...: aggregate {averageunitPrice}
...: )
In [4]: %%prqlresults<<
...: fromp
...: aggregate {minunitsInStock, maxunitsInStock}This library exposes prqlc.compile, so we can simply generate SQL:
importpyprqlpyprql.compile("from artists | select track")
print(pyprql.compile("from artists | select track"))...returns...
SELECT
track
FROM
artistsFor context, prqlc in Python is the Python binding for the prqlc Rust crate, so only
contains functions for compilation; and this library offers broader python
integrations and tooling.
This project was created by @charlie-sanders & @rbpatt2019 and is now maintained by the broader PRQL team.