Metadata-Version: 2.3
Name: pyprql
Version: 0.13.0
Summary: Python extensions for PRQL
License: Apache-2.0
Author: Charlie Sanders
Author-email: charlie.fats@gmail.com
Requires-Python: >=3.10,<4.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Typing :: Typed
Provides-Extra: polars
Requires-Dist: duckdb-engine (>=0.7,<0.16)
Requires-Dist: ipython (>=8.28.0,<9.0.0)
Requires-Dist: jupysql (>=0.10)
Requires-Dist: pandas (>=1.5)
Requires-Dist: polars (>=0.20.23) ; extra == "polars"
Requires-Dist: prqlc (>=0.13,<0.14)
Requires-Dist: traitlets (>=5)
Project-URL: Homepage, https://prql-lang.org
Project-URL: Repository, https://github.com/prql/pyprql
Description-Content-Type: text/markdown

# pyprql

[![CI/CD](https://github.com/prql/pyprql/actions/workflows/pull-request.yaml/badge.svg?branch=main)](https://github.com/prql/pyprql/actions/workflows/pull-request.yaml)
[![Documentation Status](https://readthedocs.org/projects/pyprql/badge/?version=latest)](https://pyprql.readthedocs.io/en/latest/?badge=latest)

![PyPI](https://img.shields.io/pypi/v/pyprql)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyprql)
[![Codestyle: Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

<!-- [![codecov](https://codecov.io/gh/prql/PyPrql/branch/main/graph/badge.svg?token=C6J2UI7FR5)](https://codecov.io/gh/prql/PyPrql) -->

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](https://pyprql.readthedocs.io/), and the
[PRQL Book][prql_docs].

## Installation

```sh
pip install pyprql
```

Or, install with optional dependencies:

```sh
pip install pyprql[polars]
```

## Usage

### Pandas integration

```python
import pandas as pd
import pyprql.pandas_accessor

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

### Polars integration

```python
import polars as pl
import pyprql.polars_namespace

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

### Jupyter Magic

```python
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:

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

...returns...

```sql
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](https://github.com/charlie-sanders/) &
[@rbpatt2019](https://github.com/rbpatt2019) and is now maintained by the
broader PRQL team.

[prql_docs]: https://prql-lang.org/book

