Skip to content

Repository files navigation

pyprql

CI/CDDocumentation Status

PyPIPyPI - Python VersionCodestyle: Black

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's compile function

For docs, check out the pyprql docs, and the PRQL Book.

Installation

pip install pyprql

Or, install with optional dependencies:

pip install pyprql[polars]

Usage

Pandas integration

importpandasaspdimportpyprql.pandas_accessordf= (...)
results_df=df.prql.query("select {age, name, occupation} | filter age > 21")

Polars integration

importpolarsasplimportpyprql.polars_namespacedf= (...)
results_df=df.prql.query("select {age, name, occupation} | filter age > 21")

Jupyter Magic

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}

Compilation

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
artists

For 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.

Support

This project was created by @charlie-sanders & @rbpatt2019 and is now maintained by the broader PRQL team.

About

Python extensions for PRQL

Resources

Code of conduct

Contributing

Stars

106 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages