Skip to main content

Python interface for the PHC.

Project description

The phc-sdk-py is a developer kit for interfacing with the PHC API on Python 3.6 and above.

Project Status

GitHub Travis (.org) branch PyPI status GitHub release

Getting Started

Dependencies

Getting the Source

This project is hosted on GitHub. You can clone this project directly using this command:

git clone git@github.com:lifeomic/phc-sdk-py.git

Development

Python environments are managed using virtualenv. Be sure to have this installed first pip install virtualenv. The makefile will setup the environment for the targets listed below.

Setup

This installs some pre-commit hooks that will format and lint new changes.

make setup

Running tests

make test

Linting

make lint

Installation

pip3 install phc

Usage

A Session needs to be created first that stores the token and account information needed to access the PHC API. One can currently using API Key tokens generated from the PHC Account, or OAuth tokens generated using the CLI.

from phc import Session

session = Session(token=<TOKEN VALUE>, account="myaccount")

Once a Session is created, you can then access the different parts of the platform.

from phc import Accounts

accounts = Accounts(session)
myaccounts = accounts.get_list()

Here's and example of fetching FHIR resource using SQL:

import pandas as pd
from phc import Fhir

fhir = Fhir(session)

res = fhir.execute_sql(project='19e34782-91c4-4143-aaee-2ba81ed0b206',
                       statement='SELECT * from patient LIMIT 0,5000')

resources = list(map(lambda r: r.get("_source"), res.get("hits").get("hits")))
df = pd.DataFrame(resources)

While here's an example of fetching patients observation data from using Analytics DSL. Notice that in this case, there is a helper query builder class (PatientFilterQueryBuilder):

from phc import Analytics, PatientFilterQueryBuilder

client = Analytics(session)
search = PatientFilterQueryBuilder()
search.patient() \
    .observations() \
    .code(eq='11142-7') \
    .system(eq='http://loinc.org') \
    .value_quantity(lt=40)

res = client.get_patients(project='5a07dedb-fa2a-4cb0-b662-95b23a050221', query_builder=search)

print(f"Found {len(res)} patients")

While here's an example of fetching data using data lake engine:

from phc import Session, DataLakeQuery, Analytics

session = Session()
client = Analytics(session)

dataset_id = '19e34782-91c4-4143-aaee-2ba81ed0b206'
query_string = "SELECT sample_id, gene, impact, amino_acid_change, histology FROM variant WHERE tumor_site='breast'"
output_file_name = 'query-test-notebook'
query = DataLakeQuery(dataset_id=dataset_id, query=query_string, output_file_name=output_file_name)

query_id = client.execute_data_lake_query(query)
specific_query = client.get_data_lake_query(query_id)
paginated_dataset_queries = client.list_data_lake_queries(dataset_id=dataset_id)
print(query_id)

Release Process

Releases are generally created with each merged PR. Packages for each release are published to PyPi. See CHANGELOG.md for release notes.

Versioning

This project uses Semantic Versioning.

Contributing

We encourage public contributions! Please review CONTRIBUTING.md and CODE_OF_CONDUCT.md for details on our code of conduct and development process.

License

This project is licensed under the MIT License - see LICENSE file for details.

Authors

See the list of contributors who participate in this project.

Acknowledgements

This project is built with the following:

  • aiohttp - Asynchronous HTTP Client/Server for asyncio and Python.

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

phc-0.4.3.tar.gz (11.2 kB view hashes)

Uploaded Source

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