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.1.tar.gz (486.5 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.1-py3-none-any.whl (261.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pygrowthstandards-0.1.1.tar.gz
  • Upload date:
  • Size: 486.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pygrowthstandards-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4d2fff51b700696ef6a9683c3218045f561348551c408daa20f334439e44ef4a
MD5 17ada37ca6a4b2e2c03e12a0d065998b
BLAKE2b-256 190514540aefceb55f0218dc030532eb2114377c53c01ee90372480b3c91e107

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygrowthstandards-0.1.1.tar.gz:

Publisher: publish.yml on Yannngn/pygrowthstandards

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for pygrowthstandards-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 693507f517c913525e4612dbd3c06086a3883f57e5ae523284887f089c91755f
MD5 c0b7ac0776a14265b30a961cd8302bc2
BLAKE2b-256 fd365e7a4a556f78267abff2ce8bbe009fb4d1be081c0fc7b51f31deab876b36

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygrowthstandards-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Yannngn/pygrowthstandards

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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