Skip to main content

A Python library for calculating child growth z-scores and percentiles using WHO and INTERGROWTH-21st standards

Project description

pygrowthstandards

PyPI version Python Version Python 3.11+ License: MIT Python package pre-commit

A Python library for calculating and visualizing child growth standards using data from the World Health Organization (WHO) and the INTERGROWTH-21st Project.

This toolkit provides a simple and flexible API to assess child growth by calculating z-scores and percentiles for common anthropometric measurements, including height, weight, BMI, and head circumference.

Data Sources

This library implements standards from internationally recognized sources:

Features

  • Calculate z-scores and percentiles for stature (length/height), weight, BMI, and head circumference.
  • Support for both WHO and INTERGROWTH-21st growth standards.
  • A simple object-oriented Calculator for tracking a Patient's measurements over time.
  • A straightforward functional API for one-off calculations.
  • Generate and save customizable growth charts.

Installation

To install the latest stable release from PyPI:

pip install pygrowthstandards

Development Installation

To install for development, clone the repository and install in editable mode using uv:

git clone https://github.com/Yannngn/pygrowthstandards.git
cd pygrowthstandards
uv venv --python 3.11
source .venv/bin/activate
uv sync

Quick Start

Object-Oriented Approach

The object-oriented API is ideal for tracking a patient's growth over time. It uses a Patient object to store measurements and a Plotter to visualize them.

# filepath: main.py
import datetime
from pygrowthstandards.oop.patient import Patient
from pygrowthstandards.oop.measurement import MeasurementGroup
from pygrowthstandards.oop.plotter import Plotter

# 1. Create a Patient
patient = Patient(
    sex="M",
    birthday_date=datetime.date(2022, 1, 1),
)

# 2. Add measurements over time
measurements = [
    MeasurementGroup(date=datetime.date(2022, 7, 1), weight=8.6, stature=68.4, head_circumference=44.5),
    MeasurementGroup(date=datetime.date(2023, 1, 1), weight=10.2, stature=75.7, head_circumference=46.5),
    MeasurementGroup(date=datetime.date(2024, 1, 1), weight=12.6, stature=87.8, head_circumference=48.5),
]
for mg in measurements:
    patient.add_measurements(mg)

# 3. Calculate z-scores for all measurements
patient.calculate_all()

# 4. Display a summary table
print(patient.display_measurements())

# 5. Plot the growth charts
plotter = Plotter(patient)
plotter.plot(
    age_group="0-2",
    measurement_type="stature",
    show=False,
    output_path="stature_growth_chart.png"
)

Example Output

After running the above code, you can view the generated growth chart:

Stature Growth Chart

Functional Approach

For quick, single, stateless calculations, the functional API provides direct access to the z-score calculation engine. This is useful when you don't need to track a patient's history.

# filepath: main.py
from pygrowthstandards import functional as F

# Calculate z-scores for various measurements and ages
z1 = F.zscore("stature", 50, "F", age_days=0, gestational_age=280)
z2 = F.zscore("weight", 5, "F", age_days=30)
z3 = F.zscore("head_circumference", 40, "F", age_days=180)
z4 = F.zscore("stature", 80, "F", age_days=365)
z5 = F.zscore("weight", 12, "F", age_days=730)
z6 = F.zscore("head_circumference", 48, "F", age_days=1460)

print(f"{z1:.2f}\n{z2:.2f}\n{z3:.2f}\n{z4:.2f}\n{z5:.2f}\n{z6:.2f}")

The output of this script is:

0.45
1.34
-1.64
2.33
0.36
-0.94

Contributing

Contributions are welcome! Please feel free to open an issue to report a bug or suggest a feature, or submit a pull request with your improvements.

Before contributing, please set up the development environment and run the pre-commit hooks and tests.

# Install hooks
pre-commit install

# Run tests
pytest

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

This package is built upon the publicly available data provided by the World Health Organization (WHO) and The INTERGROWTH-21st Project. We are grateful for their commitment to open data and global health.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygrowthstandards-0.1.3.tar.gz (257.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygrowthstandards-0.1.3-py3-none-any.whl (261.9 kB view details)

Uploaded Python 3

File details

Details for the file pygrowthstandards-0.1.3.tar.gz.

File metadata

  • Download URL: pygrowthstandards-0.1.3.tar.gz
  • Upload date:
  • Size: 257.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pygrowthstandards-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b87a22e9088a21a06dcdf63b0345c5f7c31cef453f6d481a2372ebf427e2e744
MD5 a6e1591f5ea8c53cc9bf1da43076565d
BLAKE2b-256 9c25fa0f6464ffae20fed7292999f03f036428bf10f0c2809a3406b612f3e8cd

See more details on using hashes here.

File details

Details for the file pygrowthstandards-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pygrowthstandards-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2eecc2093339c596017e5fc7c9c01405dcdbfb516878c96183c743c1dc32ad7b
MD5 e1f5499bcc9e2dac81b20536e1747a3b
BLAKE2b-256 f443c480682804b16e793ee6f245793e5c5efcd4451cc95a8f3705c264ffcf68

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page