Skip to main content

A tool to query EHR databases

Project description

cycquery

PyPI PyPI - Python Version code checks integration tests docs codecov

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

cycquery-0.1.8.tar.gz (44.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cycquery-0.1.8-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

Details for the file cycquery-0.1.8.tar.gz.

File metadata

  • Download URL: cycquery-0.1.8.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cycquery-0.1.8.tar.gz
Algorithm Hash digest
SHA256 bfb178774f41c10ec207167dedc95c7588fdfc44d9a227d8ccde4b900623130d
MD5 afb85e0abf22bf6a4268baf37c235336
BLAKE2b-256 d78025c67ecd8830d54882db1baff8fb495453bd754444bb4e5cc089a7596370

See more details on using hashes here.

File details

Details for the file cycquery-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: cycquery-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 51.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for cycquery-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d53fcd4273025ef7f6a5f40825bf359511e578790eee630835b8557ff2d16831
MD5 636a2b7d68f3966c151dfbfb43aa23aa
BLAKE2b-256 7c48d8dd22f6be9b1f09a71b190a0d65c35536ea79c735ac397b45081d5b76bc

See more details on using hashes here.

Supported by

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