A tool to query EHR databases
Project description
cycquery
cycquery
is a tool for querying relational databases using a simple Python API. It is specifically developed to query
Electronic Health Record (EHR) databases. The tool is a wrapper around SQLAlchemy and can be used
to write SQL-like queries in Python, including joins, conditions, groupby aggregation and many more.
🐣 Getting Started
Installing cycquery using pip
python3 -m pip install cycquery
Query postgresql database
from cycquery import DatasetQuerier
import cycquery.ops as qo
querier = DatasetQuerier(
dbms="postgresql",
port=5432,
host="localhost",
database="dbname",
user="usename",
password="password",
)
# List all tables.
querier.list_tables()
# Get some table.
table = querier.schema.sometable()
# Filter based on some condition (e.g. substring match).
table = table.ops(qo.ConditionSubstring("col1", "substr"))
# Run query to get data as a pandas dataframe.
df = table.run()
# Create a sequential list of operations to perform on the query.
ops = qo.Sequential(
qo.ConditionIn("col2", [1, 2]),
qo.DropNulls("col3"),
qo.Distinct("col1")
)
table = table.ops(ops)
# Run query to get data as a pandas dataframe.
df = table.run()
🧑🏿💻 Developing
Using poetry
The development environment can be set up using poetry. Hence, make sure it is installed and then run:
python3 -m poetry install
source $(poetry env info --path)/bin/activate
In order to install dependencies for testing (codestyle, unit tests, integration tests), run:
python3 -m poetry install --with test
API documentation is built using Sphinx and can be locally built by:
python3 -m poetry install --with docs
cd docs
make html SPHINXOPTS="-D nbsphinx_allow_errors=True"
Contributing
Contributing to cycquery
is welcomed.
See Contributing for
guidelines.
📚 Documentation
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
Built Distribution
File details
Details for the file cycquery-0.1.7.tar.gz
.
File metadata
- Download URL: cycquery-0.1.7.tar.gz
- Upload date:
- Size: 45.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b5371b67a1483becf3bc9520090ff39b884febac7d6b1243555be50e6bf4508 |
|
MD5 | 6b3f69898624c40f889d43efd3f22a77 |
|
BLAKE2b-256 | f0c7b244ec3135b7d1e4fc1cd8485c2f97b86a6db1ef11d7576b8b7675ea1c2b |
File details
Details for the file cycquery-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: cycquery-0.1.7-py3-none-any.whl
- Upload date:
- Size: 50.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34598b88ff8679b236cb0542af2c88e85f9d2244c619948755c64adc84e3ab33 |
|
MD5 | e4165c95ffcc6c6a146cb5bb26fad4d5 |
|
BLAKE2b-256 | 2f31c76850176adf455295de1d32b3be40d6c82d2f05311d2387226f1ba11612 |