Skip to main content

CGMPy — Continuous Glucose Monitoring Analysis

CI PyPI version Python versions License: MIT Code style: Ruff Documentation Status: Beta

A modular Python library for analyzing Continuous Glucose Monitoring (CGM) data, with a strong focus on clinical metrics, pregnancy-specific workflows, and reproducible research.


What is CGMPy?

CGMPy provides a clean, type-hinted Python API for:

  • Loading CGM data from CSV, Parquet, or in-memory pandas.DataFrame with automatic device detection (Dexcom Clarity, FreeStyle Libre / Libreview, Tandem, Medtronic CareLink).
  • Processing & validating glucose time series (glucometric ranges, gap detection, interval normalization).
  • Computing clinical metrics following international consensus:
    • Basic statistics: mean, median, GMI, glucose CV.
    • Time in range (TIR): TIR, TAR, TBR with customizable targets (diabetes vs. pregnancy).
    • Glycemic variability: SD, CV, MAGE, MODD, CONGA, J-Index, LBGI, HBGI, GRI.
    • Pregnancy-specific metrics for gestational diabetes.
  • Visualizing ambulatory glucose profiles (AGP), daily trends, and statistical summaries.
  • Comparing results against the AGATA reference implementation for validation.

The library is modular: every component (loader, processor, analyzer, exporter, plotter, metrics) can be used independently or composed through the high-level GlucoseAnalysis facade.


Installation

# Stable release
pip install cgmpy

# With AGATA integration (optional, requires agata)
pip install cgmpy[agata]

# With documentation / development tools
pip install cgmpy[dev,docs]

CGMPy requires Python ≥ 3.10.

From source

git clone https://github.com/javierpa95/cgmpy.git
cd cgmpy
pip install -e .[dev]

Quickstart

from cgmpy import GlucoseAnalysis

# One-line analysis
analysis = GlucoseAnalysis("path/to/glucose.csv")
report = analysis.get_comprehensive_report()
print(f"Time in Range: {report['time_in_range']['tir']}%")

# Generate the standard Ambulatory Glucose Profile
analysis.plot_comprehensive_dashboard()

Lower-level modular API

from cgmpy.data import ModularGlucoseData
from cgmpy.metrics import ModularGlucoseMetrics
from cgmpy.metrics.targets import get_targets

data = ModularGlucoseData("cgm_data.csv")
data.filter_by_date_range("2024-01-01", "2024-01-31")

# Compute metrics with pregnancy-specific cutoffs
targets = get_targets("pregnancy")
metrics = ModularGlucoseMetrics(data, targets=targets)
print(metrics.time_in_range())
print(metrics.variability().mage())

Features

Domain Capabilities
Data ingestion CSV, Parquet, DataFrame. Auto delimiter, header detection, device-specific loaders.
Validation Glucose range check, time interval regularity, gap analysis, data quality scoring.
Basic metrics Mean, median, GMI, SD, IQR, % time in any custom range.
Time in range TIR, TAR (level 1/2), TBR (level 1/2) with international consensus cutoffs.
Variability CV, MAGE, MODD, CONGA, J-Index, LBGI, HBGI, GRI, MAG, ADRR.
Pregnancy Dedicated GestationalDiabetes metrics, pregnancy glucose targets (63–140 mg/dL).
Visualization AGP (Ambulatory Glucose Profile), daily traces, statistical dashboards.
AGATA parity AgataAnalysis wrapper for side-by-side comparison with the AGATA reference.
Export To Parquet (optimized) / CSV / Excel, with deduplication and type coercion.

Documentation


Clinical & Research Use

CGMPy is built to support clinical research workflows in diabetes and gestational diabetes. If you use CGMPy in a publication, please cite the version you used (see CITATION.cff).

Important — Not a medical device. CGMPy is a research and analysis tool. It is not a medical device and must not be used as a substitute for professional medical advice. Always validate clinical interpretations with a qualified healthcare provider.


Contributing

We welcome contributions! Please read CONTRIBUTING.md for guidelines on reporting bugs, proposing features, and submitting pull requests. By participating, you agree to abide by the Code of Conduct.

Quick links:


Security & Privacy

CGMPy can process sensitive health data. Please review SECURITY.md for:

  • How to report vulnerabilities.
  • The strict policy on committing Protected Health Information (PHI).
  • How to anonymize datasets before sharing examples or bug reports.

Never commit real patient data, real CGM exports with personal identifiers, or any HIPAA/GDPR-protected data. Examples and tests must use synthetic or fully anonymized data only.


License

CGMPy is released under the MIT License. See LICENSE for details.

Copyright © 2024–2026 Javier Peñate Arrieta.


Acknowledgments

  • The clinical metric definitions follow international consensus guidelines (Battelino et al., Diabetes Care 2019; Bergenstal et al., J. Diabetes Sci. Technol. 2013).
  • The AGATA library is the reference implementation used for cross-validation.
  • Inspired by R packages like iglu and Python packages in the diabetes research ecosystem.

Metadata

Release files for cgmpy 0.6.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 cgmpy 0.6.0
File Size Uploaded Provenance Actions
cgmpy-0.6.0.tar.gz 947.7 kB Without provenance Details for cgmpy-0.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.0 MB

Release files / cgmpy-0.6.0.tar.gz

Download URL cgmpy-0.6.0.tar.gz
Size 947.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c149831288c3e669c474c8d61393ed46c7c05b0f30b1beb6e9529d26bdd7445b
BLAKE2b-256 checksum
How to use checksums
1be28420052e87d300e3c2b64b03467e4bf72849e418c085b6df6d14b9d6c4d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / cgmpy-0.6.0-py3-none-any.whl

Download URL cgmpy-0.6.0-py3-none-any.whl
Size 86.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
959429ce5f990eaea7c44e69381dbd5e40b1f9391856f1ecf7d3429c5b12b53b
BLAKE2b-256 checksum
How to use checksums
8012a9c3084ce2093cf67a3fb8f99a4fcd5e5347002222c68fb8e705990c9e8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for cgmpy 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files No provenance

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