Skip to main content

Health Data Downloader Package

The Health Data Downloader is a Python package that makes it easy to download and read real world health data.

Current data sources supported:

  • NHANES National Health and Nutrition Examination Survey (CDC)

The NHANES Submodule

If you want to download health data from NHANES this module can help you not only download the data but also add documentation from the official NHANES website, and read this data into a pandas dataframe.

NHANES is the National Health and Nutrition Examination Survey which collects data about the health of adults and children in the United States.

Note: This is not an official repository from the NHANES project nor the CDC

This project provides workflows that enable you to:

  • discover and download datasets from NHANES by component (meaning what type of data like Laboratory data, examination etc.) and by cycle (which years)
  • read the XPT files into a pandas DataFrames
  • extract NHANES variable documentation into CSV files and rename variable codes into human-readable names (such as heart_rate instead of LF321)
  • search and summarize local files if they are already downloaded

Quick start

In thie quick start we will:

  1. Install required packages.
  2. Run a download.
  3. Read and inspect data.
pip install healthdata

You can choose which components you want to download (such as Demographics, Laboratory etc.) and which years (can be either "2017-2020" or "2016"). This will also download documentation about these fields from the NHANES website to add them when the data is read. If the data is already downloaded in the output directory the module will log this and skip the download.

from healthdata.nhanes.downloader import download_nhanes_data

download_nhanes_data(
    components=["Demographics", "Examination"],
    output_dir="nhanes_data",
    years=["2017-2018"],
)

You can read the data you already downloaded (you will be prompted to download it if it doesn't exist)

from healthdata.nhanes.reader import read_nhanes_data, search_nhanes_local_data

df = read_nhanes_data("nhanes_data/2017-2018/2017/Demographics/DEMO_J.XPT")
print(df.head())

inventory = search_nhanes_local_data(search_dir="nhanes_data")
print(inventory.head())

That's all folks! Now you will see that your dataframe already includes documentation.

Current caveats

  • HTML codebook parsing depends on current NHANES page text patterns. CDC page structure changes may require parser updates.
  • Network errors and partial downloads are not retried automatically.

Upcoming Additions

Planned additions include NCBI GEO and other open health and biomedical datasets. The current release supports NHANES only.

License

This project is licensed under the MIT License. Commercial use is permitted under its terms. Downloaded datasets may be subject to separate terms set by their respective providers.

For paid support or consulting, contact the author at contact@ismail.bio.

Author

Ismail Elouafiq

Contact: contact@ismail.bio

Metadata

Release files for healthdata 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for healthdata 0.1.0
File Size Uploaded
healthdata-0.1.0.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for healthdata 0.1.0
File Interpreter ABI Platform
healthdata-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.4 kB

Release files / healthdata-0.1.0.tar.gz

Download URL healthdata-0.1.0.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
76be08e85285520e144227ee7f340b38fca1b11f099bd3868e59db08a096b4ac
BLAKE2b-256 checksum
How to use checksums
6a1cb75d8b30304bcb58579285e9f4b7b530b8cf81d2d3d2955ec5ee92eaeb7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / healthdata-0.1.0-py3-none-any.whl

Download URL healthdata-0.1.0-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eea52ee76d90354460c2b96dc3d22773aa22ff200c1b92ea5573e56aaa815948
BLAKE2b-256 checksum
How to use checksums
00d63d950bb741952c6c2d99171a20278214a847ecc2b6222d8c840583e5d90f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page