Welcome to the new home of the HDX FAQ
For the complete documentation index, see llms.txt. This page is also available as Markdown.

HDX Python library

Learn about the HDX library to contribute data to the platform.

The HDX Python API is a library for reading data from HDX and creating or updating datasets in code, instead of through the website. It is maintained by the HDX team and is the recommended way to automate work on HDX.

Full usage documentation lives on ReadTheDocs.

Reading vs. writing: To read metadata or data from HDX, use read-only mode with no API token. To create or update datasets, you need an API token and editor or admin rights on your organization (see Before you write code).

When to use it

Your situation
Best option

One-off or occasional upload

HDX web interface

Recurring or scheduled dataset updates

Python library

Managing many datasets at once

Python library

Reading HDX metadata or data for analysis (no API token needed)

Python library, read-only mode

Not using Python

rhdx for R

Before you write code

  • Your organization must exist on HDX, and you need to be an editor or admin of it.

  • Find your user ID and organization ID (the values passed to set_maintainer and set_organization). Look up your user ID at https://data.humdata.org/api/3/action/user_show?id=USERNAME and your organization ID at https://data.humdata.org/api/3/action/organization_show?id=ORG-NAME, replacing the placeholders with your HDX username and organization name.

  • Get an API token from your HDX profile page (instructions).

  • Test against the stage server before writing to production. Contact hdx@un.org for access.

  • Dataset tags must come from HDX's approved list.

Code examples

Create a dataset with a file resource

Install first with pip install hdx-python-api. Note running the same code again updates the dataset rather than creating a duplicate.

Update an existing dataset

This pattern fits recurring updates: read the dataset, swap in the new file, and push the change back to HDX. To run this on a schedule, use the scraper template under Going further.

Going further

Questions or problems?

Email us at hdx@un.org or raise a GitHub issue.

Last updated

Was this helpful?