Python Implementation of Pipelined Relational Query Language (PRQL)
Project description
PyPrql
Python implementation of PRQL.
Documentation of PRQL is at https://github.com/max-sixty/prql
Installation
pip install pyprql
CLI
Usage:
pyprql 'connection_string'
pyprql 'postgresql://user:password@localhost:5432/database'
Examples:
pyprql 'sqlite:///chinook.db'
Try it out:
curl https://github.com/qorrect/PyPrql/blob/main/resources/chinook.db?raw=true -o chinook.db
pyprql "sqlite:///chinook.db"
PRQL> show tables
pyprql.to_sql
query='''
from employees
filter country = "USA"
derive [
gross_salary: salary + payroll_tax,
gross_cost: gross_salary + benefits_cost
]
filter gross_cost > 0
aggregate by:[title, country] [
average salary,
sum salary,
average gross_salary,
sum gross_salary,
average gross_cost,
sum_gross_cost: sum gross_cost,
row_count: count salary
]
sort sum_gross_cost
filter row_count > 200
take 20
'''
from pyprql import to_sql
sql = to_sql(query)
print(sql)
SELECT AVG(salary),
SUM(salary),
AVG(salary + payroll_tax),
SUM(salary + payroll_tax),
AVG(salary + payroll_tax + benefits_cost),
SUM(salary + payroll_tax + benefits_cost) as sum_gross_cost,
COUNT(salary) as row_count,
salary + payroll_tax as gross_salary,
(salary + payroll_tax) + benefits_cost as gross_cost
FROM `employees` employees_e
WHERE country="USA" AND (gross_salary+benefits_cost)>0
GROUP BY title, country
HAVING row_count >200
ORDER BY sum_gross_cost
LIMIT 20
Differences from the spec
The parser is only able to parse casts in select statements insde of [ ]
, so
select foo | as float
will fail, it must be wrapped in brackets as a single item list.
select [ foo | as float ]
Project details
Release history Release notifications | RSS feed
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.4.0.tar.gz
(21.5 kB
view details)
Built Distribution
pyprql-0.4.0-py3-none-any.whl
(23.4 kB
view details)
File details
Details for the file pyprql-0.4.0.tar.gz
.
File metadata
- Download URL: pyprql-0.4.0.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a4feeebc6f67daf6258bbc67a20e35a726e0bd232818f3429323df5dbc3bc53 |
|
MD5 | e544ce60f808d01f47a596cbb6c6dac8 |
|
BLAKE2b-256 | fa85c2a0b023e134d780d05a78b8c2459e837869980e5faf1ae4f01580eb769f |
Provenance
File details
Details for the file pyprql-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: pyprql-0.4.0-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a69a7de1f17ebabf845537dcec15a932ce923a29dab096206ad6614aa8b26b |
|
MD5 | e97b3e99838d911c13afb0af9cbb1fcd |
|
BLAKE2b-256 | 718f82830698a3d59f9b0990cd9b54887911c67c12a7356fc5a1a7c19b654275 |