Skip to main content

Database operator

Project description

dw - database operator

Run sql statement in python

support argument passing, text replacement, read sql from file
function for DDL/DML on database table and pandas dataframe
logging via the logging package

Programmatically generate simple sql query

based on string injection

Generate and run summary queries

utlise data manipulation capability of database instead of passing
large raw data to python which may not be feasible
summary query results as pandas dataframe for access to python toolkit

aim to cater for sqlite, postgre and oracle dialects

from dw import lt
lt.qry('test').where("score > 0.5") \
.valc('time,cat',"avg(score) avgscore,round(sum(amt)/1e3,2) total") \
.pivot('time','cat',['n','avgscore','total'])
2022-01-23 01:08:13,407 [INFO] running:
with x as (
    select * from test
    where score > 0.5
)
select 
    time,cat
    ,count(1) n
    ,avg(score) avgscore, round(sum(amt)/1e3,2) total
from x
group by time,cat
order by n desc
2022-01-23 01:08:13,413 [INFO] done
n avgscore total
cat test train test train test train
time
2013-01-02 816.0 847.0 0.746747 0.750452 398.34 417.31
2013-02-02 837.0 858.0 0.748214 0.743094 419.11 447.04
2013-03-02 805.0 860.0 0.756775 0.739017 394.89 422.35

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

dwops-0.0.1.tar.gz (8.8 kB view hashes)

Uploaded Source

Built Distribution

dwops-0.0.1-py3-none-any.whl (9.0 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