Hello all,
Sharing a bit of beginner level knowledge i gathered. If my post encourages few others to pick up some other topics to share, many beginners like me will be benefited.
So here I go with basic python usage series for DHIS2 APIs. I’m currently using DHIS2.py. You may find a better module or you can write your own code
Use case : I want to extract data element details as ID,Name from a DHIS2 instance using python code.
Pre-requisite: DHIS2.py module installed.
Workable code:
from dhis2 import Api
api = Api('play.dhis2.org/2.34.0/', 'admin', 'district')
r = api.get('dataElements?paging=false', params={'fields': 'id,name'})
de_data = r.json()
print ("ID,Name")
for de in de_data['dataElements']:
print (de['id'],",",de['name'])
#sample output
#ID,Name
#fbfJHSPpUQD , ANC 1st visit