Just in case you were wondering how to get DHIS2 data from python, see below.
Created on 17/12/2018
@author Charles Waka
"""
#Python code for getting data from DHIS2
import getpass
import numpy as np
import pandas as pd
import requests as rq
from io import StringIO
#DHIS2 username and password variables
dhis_uname="admin"
dhis_pwd="district"
dhis_url="https://play.dhis2.org/dev/api/reportTables/KJFbpIymTAo/data.csv"
#If you need to protect your password, you can use getpass
#response=rq.get(dhis_url, auth=(dhis_uname,getpass.getpass()))
response=rq.get(dhis_url, auth=(dhis_uname,dhis_pwd))
#Read the data to a pandas dataset
dset=pd.DataFrame(pd.read_csv(StringIO(response.text)))
#Get column names of data set
print(dset.columns.values)
#Print a few rows of the dataset
dset.head(10)
#You can view the data types of your set
dset.dtypes
Hi @charles.waka, thank you for sharing this. It’s nice however, not a good practice to follow. I would discourage storing usernames and passwords openly for security reasons.
options = [
{'code': 'apple', 'name': 'Apple'},
{'code': 'ball', 'name': 'Ball'},
]
# this will replace existing options in optionset with the one provided
response = set_optionset('PdiTQOAOAqN', options)
both json= and data= should be supported as arguments.
If you’re not using the latest version you should upgrade the package - you can check with: pip show dhis2.py
and upgrade with pip install dhis2.py --upgrade
Please note that it is not an official DHIS 2 Python package but hopefully still useful.