HDX Python Utilities
raw JSON → 4.0.8 verified Fri May 01 auth: no python
Supporting utilities for the HDX Python ecosystem, including streaming tabular data (CSV/JSON/Excel), date/time handling, URL manipulation, file I/O, and general helper functions. Current version 4.0.8, requires Python >=3.10, follows weekly release cadence.
pip install hdx-python-utilities Common errors
error ImportError: cannot import name 'get_filename_from_url' from 'hdx.utilities.loader' ↓
cause Function moved to hdx.utilities.url in 4.0.4.
fix
Use: from hdx.utilities.url import get_filename_from_url
error ModuleNotFoundError: No module named 'hdx.utilities' ↓
cause Package not installed or installed under a different name.
fix
Install with: pip install hdx-python-utilities
error TypeError: save_iterable_to_csv() got an unexpected keyword argument 'headers' ↓
cause Parameter name changed in an older version; 'headers' might be 'fieldnames' or require a different signature.
fix
Check the documentation for your version. In recent versions, use 'headers' parameter. For older versions, use 'fieldnames' or omit.
error AttributeError: module 'hdx.utilities' has no attribute 'loader' ↓
cause The utilities module might not have submodules imported automatically; need explicit import.
fix
Use: from hdx.utilities.loader import load_csv (not import hdx.utilities)
Warnings
breaking Python 3.10+ required starting from version 4.0.0. Older Python versions (3.6, 3.8, 3.9) are no longer supported. ↓
fix Upgrade to Python 3.10 or later, or pin to hdx-python-utilities<4.0.0 if you must use an older Python.
breaking URL-related functions (get_filename_from_url, get_filename_extension_from_url, get_path_for_url, get_url_for_get, get_url_params_for_post) moved from loader module to url module in 4.0.4. Old imports will break. ↓
fix Change imports from 'hdx.utilities.loader' to 'hdx.utilities.url' for these functions.
gotcha save_iterable expects headers to be list of strings ordered as desired. For a list of dicts, if headers are not specified, they are inferred from the first dict's keys, which may not preserve order or include all keys. ↓
fix Always provide explicit headers list when saving tabular data to ensure correct column order and completeness.
deprecated Functions that returned None in edge cases (e.g., row_function returning None) now handle that edge case properly. Old code relying on None may break. ↓
fix Update code to handle the new behavior where None is no longer returned unexpectedly. Test your row functions.
Imports
- save_iterable_to_csv wrong
from hdx.utilities import save_iterable_to_csvcorrectfrom hdx.utilities.file_handler import save_iterable_to_csv - load_csv wrong
from hdx.utilities import load_csvcorrectfrom hdx.utilities.loader import load_csv - get_filename_from_url wrong
from hdx.utilities.loader import get_filename_from_urlcorrectfrom hdx.utilities.url import get_filename_from_url - get_filename_extension_from_url wrong
from hdx.utilities.loader import get_filename_extension_from_urlcorrectfrom hdx.utilities.url import get_filename_extension_from_url - get_path_for_url wrong
from hdx.utilities.loader import get_path_for_urlcorrectfrom hdx.utilities.url import get_path_for_url - get_url_for_get wrong
from hdx.utilities.loader import get_url_for_getcorrectfrom hdx.utilities.url import get_url_for_get - get_url_params_for_post wrong
from hdx.utilities.loader import get_url_params_for_postcorrectfrom hdx.utilities.url import get_url_params_for_post - smart_split wrong
from hdx.utilities.loader import smart_splitcorrectfrom hdx.utilities.text import smart_split
Quickstart
from hdx.utilities.loader import load_csv
from hdx.utilities.file_handler import save_iterable_to_csv
# Load a CSV file
filepath = 'data.csv'
data = load_csv(filepath)
# Save an iterable (list of dicts) to CSV
records = [{'name': 'Alice', 'age': 30}, {'name': 'Bob', 'age': 25}]
save_iterable_to_csv(records, 'output.csv', headers=['name', 'age'])
print('Done')