Skip to main content

quarrel makes it easy to query legacy rdbmses

Project description

querulous_quarrel

Named for a lovely groups of sparrows that happened to be flying by. A library that makes writing and executing queries a little easier for data scientists.

quarrel uses concentric and waddle and is proudly sponsored by the m&a team at cscgh.

installation

cd /path/to/repo
pip install quarrel

quick start

  1. create a config file

     oracle:
       host: oracle.example.com
       user: scott
       password: tiger
       sid: xe
    
  2. initialize concentric with the config file from (1)

     from concentric.managers import setup_concentric
    
     setup_concentric('/path/to/oracle.yml')
    
  3. (optional) initialize the sql template directories

     from quarrel.settings import setup_quarrel
     setup_quarrel('/path/to/jinja2/sql/templates', '/path/to/jinja2/sql/queries') 
    
  4. query the database

     from quarrel.raw import query
     results = query('oracle', 'select sysdate from dual')
    

raw results -- get raw results from the dbapi connection

quarrel.raw allows you to get the tuples as they were returned by the underlying dbapi connection. the header will be the cursor.description returned from the query, and the results will be the list of tuples returned by the query.

> from quarrel.raw import query
> header, results = query('oracle', 'select sysdate d from dual')
> print(header[0][0])
D
> print(results)
[(datetime.datetime(2022, 6, 26, 15, 10, 59),)]

cooked results -- get results as a list of dicts

quarrel.cooked allows you to get a list of dicts which is slightly easier to understand and work with but can be substantially slower as python will construct a dict per row that is returned. Each key of the dict will be the lower-cased column name specified in the query.

> from quarrel.cooked import query
> results = query('oracle', 'select sysdate d from dual')
> print(results)
[{'d': datetime.datetime(2022, 6, 26, 15, 14, 12)}]

sqlalchemy results

quarrel.sqlalchemy allows you to get a list of dicts as well. However, it uses sqlalchemy under the hood. This can be useful when you need sql alchemy's connection pooling features.

> from quarrel.sqlalchemy import query
> results = query('oracle', 'select sysdate d from dual')
> print(results)
[{'d': datetime.datetime(2022, 6, 26, 15, 14, 12)}]

pandas results

quarrel.pandas allows you to get a dataframe using either the dbapi connection or a sqlalchemy connection.

> from quarrel.pandas import query
> results = query('oracle', 'select sysdate d from dual')
> print(results)
                    d
0 2022-06-26 15:20:34

> from quarrel.pandas import query_alchemy
> results = query_alchemy('oracle', 'select sysdate d from dual')
> print(results)
                    d
0 2022-06-26 15:20:34

In order to use pandas, make sure you install pandas support using the pandas extra

pip install quarrel[pandas]

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

quarrel-0.6.tar.gz (7.2 kB view details)

Uploaded Source

File details

Details for the file quarrel-0.6.tar.gz.

File metadata

  • Download URL: quarrel-0.6.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.5

File hashes

Hashes for quarrel-0.6.tar.gz
Algorithm Hash digest
SHA256 df7a3930c24b118d5a970cb797b9baec29f3c869ae10fc7a1e3a98b6e08d3298
MD5 18c9104d099b5f9d8b718307275806a7
BLAKE2b-256 79cc78629855ad36efecadfa0596d1f3b2c541f4686e3d52f819e94b7b856af8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page