Here’s a Python library / generic DHIS2 API wrapper to use in custom scripts - from the page:
It attempts to be useful for any data/metadata import tasks including various utilities like file loading, UID generation and logging. A strong focus is on JSON.
It is based on the popular requests HTTP library with a few enhancements (paging, partitioned posts etc.). Hope it’s useful to someone else.