Client for SHAARPEC Analytics API.
Project description
Python client for SHAARPEC Analytics API.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
About The Project
This project is a Python client for convenient access to the SHAARPEC Analytics API, including automated authentication handling via device or code flow.
The SHAARPEC Analytics API provides calculations on the healthcare organization's resources, capacities, clinical outcomes, and much more. These results can be accessed via a standard REST API protected by the SHAARPEC Identity Server.
Built With
Getting Started
Prerequisites
The shaarpec client is used as a regular Python library. As always, it is a good idea to install a Python library in an isolated virtual environment.
Installation
- Install the library into your virtual environment.
pip install shaarpec
- Store your credentials to the SHAARPEC IdentityServer in an .env file.
$ cat .env OIDCISH_CLIENT_ID="my client id" OIDCISH_CLIENT_SECRET="my client secret" OIDCISH_AUDIENCE="shaarpec_api.full_access_scope" OIDCISH_SCOPE="openid shaarpec_api.full_access_scope offline_access"
Usage
This library provides a Client class to easily interact with the SHAARPEC Analytics API. The class methods Client.with_device(...)
and Client.with_code(...)
class create clients that authenticate with the SHAARPEC IdentityServer with either device (not tied to an individual user, recommended) or code flow (tied to an individual user, for debugging and development).
All API data is returned as httpx.Response
objects.
Let's look at some code examples on how to get data from the Analytics API. First, import the client class.
from shaarpec import Client
Next, use device flow or code flow to connect the client to the API with the Client.with_device
and/or Client.with_code
class methods.
The credentials can either be stored in a .env file in the working directory (as explained in the Prerequisites section) or given directly as arguments to the auth
dict:e
# Using a client with device flow.
client = Client.with_device(
host="https://api.shaarpec.com/",
auth={"host": "https://idp.shaarpec.com"}
)
Here host
is the base URL to the Analytics API and auth
is a dictionary with the login credentials. With device flow, the user needs to finish the sign-in by visiting a url provided by the IdentityServer. A message will be shown:
Visit https://idp.shaarpec.com/device?userCode=XXXXXXXXX to complete sign-in.
The user visits the website, verifies that the user code is correct and confirms the sign-in. After a few seconds, the client will confirm the sign-in:
SUCCESS: Authentication was successful. Took XX.Y seconds.
The client is now connected to the API and can get data and post computations. Visit the Analytics API Base URL to interactively test the endpoints and read their documentation and about their path and query parameters. These parameters are used in the regular (requests
and httpx
) way with client.verb
calls, where verb
is either get
or post
. For example (remember, API responses are returned as httpx.Response
objects):
client.get("terminology/allergy_type").json()
might return
{'419263009': 'Allergy to tree pollen',
'420174000': 'Allergy to wheat',
'425525006': 'Allergy to dairy product',
'714035009': 'Allergy to soya',
'419474003': 'Allergy to mould',
'232347008': 'Dander (animal) allergy',
'91934008': 'Allergy to nut',
'417532002': 'Allergy to fish',
'300913006': 'Shellfish allergy',
'232350006': 'House dust mite allergy',
'418689008': 'Allergy to grass pollen',
'91935009': 'Allergy to peanuts',
'91930004': 'Allergy to eggs',
'300916003': 'Latex allergy',
'424213003': 'Allergy to bee venom'}
or
client.get("population", conditions=["T78.2", "K81.0"])
might return
[{'patient_origin_id': '4c92f494-3c98-f8dd-1473-da9eb0196f6f',
'age': '10-16',
'is_alive': True,
'gender': 'F',
'deceased_year': 0},
...
]
Roadmap
See the open issues for a full list of proposed features (and known issues).
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
SHAARPEC Support - support@shaarpec.com
Project Link: https://github.com/SHAARPEC/shaarpec-python-client
Project details
Release history Release notifications | RSS feed
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 shaarpec-1.0.1.tar.gz
.
File metadata
- Download URL: shaarpec-1.0.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0b2 CPython/3.8.5 Linux/5.10.16.3-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5d28a85b30fef1a385a71e3c24ff78ac06554403f3d8e1f4dccca4c78a87035 |
|
MD5 | 36136a5cf335c379b19d9fd17b57bd0a |
|
BLAKE2b-256 | 72cde395eb91cc51561a6281ed5faea83dfe3ec7bab6945780ba38cbfa39b911 |
File details
Details for the file shaarpec-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: shaarpec-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0b2 CPython/3.8.5 Linux/5.10.16.3-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c0a4cc9aeceb878996b65cf3dc67ead3b56084e29259e170687e17575d964f5 |
|
MD5 | 237090b9931e7b2ccaa3c61deb7c651b |
|
BLAKE2b-256 | 1de65cdedea39969e57c6c33a67d54ca294bb77c40094a2f5e918e3e381cc963 |