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

import pandas as pd
import pyprql.pandas_accessor

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

Polars integration

import polars as pl
import pyprql.polars_namespace

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 prqlc.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, 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.

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.12.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

pyprql-0.12.1-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file pyprql-0.12.1.tar.gz.

File metadata

  • Download URL: pyprql-0.12.1.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pyprql-0.12.1.tar.gz
Algorithm Hash digest
SHA256 942e460f56a600f0da98acd30c5bdd41f378cee268f44a5f72118ed5c381272f
MD5 4886208c2d177da33c45d75f8991e481
BLAKE2b-256 9b6dd47299cdf1ce772defc0c9dd32b054790f74d51a7fa8fe61c2b212fe2513

See more details on using hashes here.

File details

Details for the file pyprql-0.12.1-py3-none-any.whl.

File metadata

  • Download URL: pyprql-0.12.1-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pyprql-0.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bba4b1e64f10951fa614453a0ed706843dd7e7a22a894c4915bfc5f73e428bad
MD5 caed2ec1bd3e20fe87d50922efebf6e5
BLAKE2b-256 6f4694e203c110ba29d36d9306b6753f3ff325d54eec788e2644dad018ddaad5

See more details on using hashes here.

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