Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
amrit110 committed Nov 2, 2023
1 parent 32eefc1 commit c8372f7
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ cyclops-query
[![codecov](https://codecov.io/gh/VectorInstitute/cyclops-query/branch/main/graph/badge.svg)](https://codecov.io/gh/VectorInstitute/cyclops-query)
[![license](https://img.shields.io/github/license/VectorInstitute/cyclops-query.svg)](https://github.com/VectorInstitute/cyclops-query/blob/main/LICENSE)

``cyclops-query`` is a tool for querying EHR databases.
``cyclops-query`` 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](https://www.sqlalchemy.org/) and can be used
to write SQL-like queries in Python, including joins, conditions, groupby aggregation and many more.

## 🐣 Getting Started

Expand All @@ -18,6 +20,42 @@ cyclops-query
python3 -m pip install cycquery
```

### Query postgresql database

```python
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
Expand Down
46 changes: 44 additions & 2 deletions docs/source/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ cyclops-query

|PyPI| |code checks| |integration tests| |docs| |codecov| |license|

``cyclops-query`` is a tool for querying EHR databases.
``cyclops-query`` 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 <https://www.sqlalchemy.org/>`__ and can be used to write
SQL-like queries in Python, including joins, conditions, groupby
aggregation and many more.

🐣 Getting Started
==================
Expand All @@ -15,8 +20,45 @@ Installing cyclops-query using pip
python3 -m pip install cycquery
Query postgresql database
-------------------------

.. code:: python
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
------------
Expand Down

0 comments on commit c8372f7

Please sign in to comment.