Skip to main content

Python extensions for PRQL

Project description

pyprql

CI/CD Documentation Status

PyPI PyPI - Python Version Codestyle: Black

pyprql contains:

  • pyprql.pandas_accessor — Pandas integration for PRQL
  • pyprql.magic — IPython magic for connecting to databases using %%prql
  • pyprql.compile — An export of prql-python's compile function

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

Installation

pip install pyprql

Usage

Pandas integration

import pandas as pd
import pyprql.pandas_accessor

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

Jupyter Magic

In [1]: %load_ext pyprql.magic
In [2]: %prql postgresql://user:password@localhost:5432/database
In [3]: %%prql
   ...: from p
   ...: group categoryID (
   ...:   aggregate {average unitPrice}
   ...: )
In [4]: %%prql results <<
   ...: from p
   ...: aggregate {min unitsInStock, max unitsInStock}

Compilation

This library exposes prql-python.compile, so we can simply generate SQL:

import pyprql
pyprql.compile("from artists | select track")
print(pyprql.compile("from artists | select track"))

...returns...

SELECT
  track
FROM
  artists

For context, prql-python is the Python binding for prql-compiler, 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyprql-0.11.0.tar.gz (17.5 kB view hashes)

Uploaded Source

Built Distribution

pyprql-0.11.0-py3-none-any.whl (19.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page