Read Human Mortality Database and Human Fertility Database data from the web
Project description
pyhmfd
A Python package for reading data from the Human Mortality Database (HMD), Human Fertility Database (HFD), Human Fertility Collection (HFC), Japanese Mortality Database (JMD), and Canadian Historical Mortality Database (CHMD).
Returns tidy pandas.DataFrame objects ready for analysis.
Credits
This package is a Python port of the R package HMDHFDplus by Tim Riffe, Jose Manuel Aburto, and contributors:
Riffe T, Aburto JM, et al. (2023). HMDHFDplus: Read Human Mortality Database and Human Fertility Database Data from the Web. R package. https://github.com/timriffe/HMDHFDplus
The authentication flow, URL patterns, parsing logic, and data-cleaning conventions are derived directly from that work. Licensed under GPL-2.0.
Supported databases
| Database | Short name | Authentication |
|---|---|---|
| Human Mortality Database | HMD | account required |
| Human Fertility Database | HFD | account required |
| Human Fertility Collection | HFC | none |
| Japanese Mortality Database | JMD | none |
| Canadian Historical Mortality Database | CHMD | none |
Installation
pip install pyhmfd
Or from source:
git clone https://github.com/filipeclduarte/pyhmfd.git
cd pyhmfd
pip install -e ".[dev]"
Credentials
For HMD and HFD you need a free account at their respective websites. Supply credentials via environment variables (recommended for scripts/CI):
export HMD_USER="your@email.com"
export HMD_PASSWORD="yourpassword"
export HFD_USER="your@email.com"
export HFD_PASSWORD="yourpassword"
Or pass them directly to the function, or let the package prompt interactively. Credentials entered interactively are offered to the system keyring for storage.
Quick start
import pyhmfd
# Human Mortality Database — needs credentials
df = pyhmfd.read_hmd_web("USA", "Mx_1x1")
df = pyhmfd.read_hmd_web("FRATNP", "Deaths_1x1", username="u@example.com", password="pw")
# Human Fertility Database — needs credentials
df = pyhmfd.read_hfd_web("USA", "asfrRR")
# Japanese Mortality Database — no auth
df = pyhmfd.read_jmd_web("01", "Deaths_1x1") # 01 = Hokkaido
# Canadian Historical Mortality Database — no auth
df = pyhmfd.read_chmd_web("que", "Mx_1x1") # que = Quebec
# Human Fertility Collection — no auth
df = pyhmfd.read_hfc_web("RUS", "ASFRstand")
# Read a locally downloaded file
df = pyhmfd.read_hmd("/path/to/Mx_1x1.txt")
df = pyhmfd.read_hfd("/path/to/asfrRR.txt", item="asfrRR")
Utility functions
# List available countries
pyhmfd.get_hmd_countries() # ['AUS', 'AUT', ..., 'USA']
pyhmfd.get_hfd_countries() # DataFrame with country names and codes
pyhmfd.get_hfc_countries() # list of codes
pyhmfd.get_jmd_prefectures() # dict: name → 2-digit code
pyhmfd.get_chmd_provinces() # ['alb', 'bco', 'can', ...]
# List available data items per country
pyhmfd.get_hmd_items("USA") # DataFrame: item, description, url
pyhmfd.get_hfd_items("USA") # DataFrame: item, description, url
# Last-update date for an HFD country
pyhmfd.get_hfd_date("USA") # '20260323' (date of last update)
Output format
All functions return a pandas.DataFrame. When fixup=True (default):
Agecolumn isInt64(nullable integer).OpenIntervalboolean column marks the terminal open age group (e.g. 110+).YearandCohortareInt64.- Rate and count columns are
float64. - Missing values coded as
'.'in source files becomeNaN.
Running tests
pytest
License
GPL-2.0, following the original R package.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyhmfd-0.1.3.tar.gz.
File metadata
- Download URL: pyhmfd-0.1.3.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1d8c81178b667c21e87928a092c55a35162de7a3f4b41dff6b1a94054c0961d
|
|
| MD5 |
b8919648d8b74d7d917b868f8c5b69ac
|
|
| BLAKE2b-256 |
8d5c974336331209788307c62e5ea645a258eb00fcff4a7b098614382c508969
|
File details
Details for the file pyhmfd-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pyhmfd-0.1.3-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af63f159ba8be07884e0946e44e25645062908ac204616966c563d1e6d59c9bc
|
|
| MD5 |
292f19761a3eb17c15109450e4d4ca5b
|
|
| BLAKE2b-256 |
bfdbba546c19fe6c06367f1fea62a5a707343d1d08c77a1f7ac10fa32d186754
|