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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyprql-0.2.2.tar.gz.
File metadata
- Download URL: pyprql-0.2.2.tar.gz
- Upload date:
- Size: 18.3 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.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
749ee8e4c5aac013476708397bc7b3caccb6b68a653e087edd130c48144a5692
|
|
| MD5 |
e6a39b526b617a012cfe364f04adaa66
|
|
| BLAKE2b-256 |
75117aa3299b3f3624da4cdd6cb192ef4e73f4174884edf3cc2e4ce44e6691fe
|
File details
Details for the file pyprql-0.2.2-py3-none-any.whl.
File metadata
- Download URL: pyprql-0.2.2-py3-none-any.whl
- Upload date:
- Size: 19.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.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
397f41055400e2166737097dabe6a851d06a79b1efe3abfd5f759c4b58622876
|
|
| MD5 |
9b0f0aff0899f6d12eb85f8961d7d1eb
|
|
| BLAKE2b-256 |
928bf3930e6e79ba58c4879b12441af9b3cffa02bc4d63c2d44d462975abb957
|