Skip to main content

Production-grade Python package for cardiovascular disease risk calculation

Project description

PyCVDRisk 🫀

Cardiovascular Disease Risk Calculator

A comprehensive Python library for CVD risk assessment

PyPI version Python versions License: MIT CI

📖 Documentation🚀 Quick Start💬 Discussions


✨ What is PyCVDRisk?

PyCVDRisk is a production-ready Python package that implements major cardiovascular disease risk prediction models. Whether you're a researcher analyzing biobank data or a clinician integrating risk assessment into your workflow, PyCVDRisk provides accurate, validated, and easy-to-use CVD risk calculations.

🎯 Key Features

  • 7 Production-Ready Models: SCORE2, ASCVD, Framingham, QRISK3, SMART2, WHO CVD, Globorisk
  • Batch Processing: Handle thousands of patients efficiently with vectorized operations
  • Type-Safe: Full type hints and validation with Pydantic
  • Well-Tested: Comprehensive test suite with high code coverage
  • Research-Grade: Based on peer-reviewed algorithms and clinical guidelines

🚀 Installation

pip install cvd-risk

That's it! PyCVDRisk is now ready to use.


📖 Quick Start

Calculate Risk for One Patient

from cvd_risk import SCORE2

# Create a patient profile
patient = {
    'age': 55,
    'sex': 'male',
    'systolic_bp': 140,
    'total_cholesterol': 6.0,
    'hdl_cholesterol': 1.2,
    'smoking': True,
    'region': 'moderate'
}

# Calculate 10-year CVD risk
result = SCORE2(**patient)

print(f"Risk Score: {result.risk_score:.1f}%")
print(f"Risk Category: {result.risk_category}")

Output:

Risk Score: 10.6%
Risk Category: Moderate risk

Batch Processing for Multiple Patients

import pandas as pd
from cvd_risk import SCORE2

# Load your patient data
df = pd.DataFrame({
    'age': [45, 60, 55, 70],
    'sex': ['female', 'male', 'male', 'female'],
    'systolic_bp': [120, 150, 135, 145],
    'total_cholesterol': [5.5, 7.2, 6.1, 4.8],
    'hdl_cholesterol': [1.8, 1.0, 1.3, 1.5],
    'smoking': [False, True, False, True],
    'region': ['low', 'high', 'moderate', 'moderate']
})

# Calculate risks for all patients
results = SCORE2.batch_calculate(**df)

# Add results to your dataframe
df['cvd_risk_10y'] = results['risk_score']
df['risk_category'] = results['risk_category']

print(df)

🏥 Available Models

Model Population Primary Use Status
SCORE2 European adults (40-69) Primary prevention ✅ Production Ready
ASCVD US/International adults Primary prevention ✅ Production Ready
Framingham US adults Primary prevention ✅ Production Ready
QRISK3 UK primary care Primary prevention ✅ Production Ready
SMART2 Secondary prevention Recurrent CVD risk ✅ Production Ready
WHO CVD Global populations Primary prevention ✅ Production Ready
Globorisk 182 countries Primary prevention ✅ Production Ready

More models coming soon: SCORE2-OP, PREVENT, LifeCVD2, and others


🔬 Usage Examples

Clinical Integration

from cvd_risk import SCORE2, ASCVD

# Compare multiple models for the same patient
patient = {
    'age': 65, 'sex': 'male', 'systolic_bp': 150,
    'total_cholesterol': 6.5, 'hdl_cholesterol': 1.1,
    'smoking': False, 'region': 'high'
}

score2_risk = SCORE2(**patient).risk_score
ascvd_risk = ASCVD(**patient).risk_score

print(f"SCORE2: {score2_risk:.1f}%")
print(f"ASCVD: {ascvd_risk:.1f}%")

Epidemiological Research

import pandas as pd
from cvd_risk import SCORE2

# Process large cohorts efficiently
biobank_data = pd.read_csv('large_cohort.csv')  # 100K+ patients

# Calculate risks (takes ~1 second for large datasets)
risks = SCORE2.batch_calculate(**biobank_data)

# Statistical analysis
high_risk = (risks['risk_score'] > 10).sum()
total_patients = len(biobank_data)
high_risk_percentage = (high_risk / total_patients) * 100

print(f"High-risk patients: {high_risk:,} ({high_risk_percentage:.1f}%)")

Model Comparison

from cvd_risk import SCORE2, Framingham, QRISK3
import numpy as np

# Compare model predictions across a population
ages = np.random.normal(55, 10, 1000)
# ... generate synthetic population data ...

results = {
    'SCORE2': SCORE2.batch_calculate(age=ages, ...),
    'Framingham': Framingham.batch_calculate(age=ages, ...),
    'QRISK3': QRISK3.batch_calculate(age=ages, ...)
}

# Analyze agreement between models
# Statistical analysis code here...

📚 Documentation


🤝 Contributing

We welcome contributions! Here's how to get involved:

Ways to Contribute

  • 🐛 Report bugs via GitHub Issues
  • 💡 Suggest features in Discussions
  • 📝 Improve documentation by editing files
  • 🧪 Add test cases or validation data
  • 🔧 Implement new risk models

Development Setup

# Clone the repository
git clone https://github.com/m-aljasem/PyCVDRisk.git
cd PyCVDRisk

# Install in development mode with all dependencies
pip install -e .[dev]

# Run tests
python build_script.py test

# Run all checks (linting + tests)
python build_script.py check

📄 License

MIT License - Free for academic, clinical, and commercial use.

Just cite us in your research! 📚


🙏 Acknowledgments

  • European Society of Cardiology - SCORE2 algorithm
  • Scientific Python Community - NumPy, Pandas, SciPy
  • Open Source Contributors - Making research software accessible

Built with ❤️ for cardiovascular research and clinical practice

⭐ Star us on GitHub📧 Contact

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

cvd_risk-0.1.1.tar.gz (134.1 kB view details)

Uploaded Source

Built Distribution

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

cvd_risk-0.1.1-py3-none-any.whl (63.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cvd_risk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8a3a70fec7d3ba0b6d040fdec4d36a2f77e6bcb65362dfb5ea9ea19151f09bc1
MD5 08563c8ec48780446db2cddbd23c3a6a
BLAKE2b-256 3fd3bd87ded01b3e0f3b767a47db42fcb0f0eec9e4ae4c1817847f180c59211d

See more details on using hashes here.

Provenance

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

Publisher: release.yml on m-aljasem/PyCVDRisk

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

File details

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

File metadata

  • Download URL: cvd_risk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 63.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cvd_risk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 34420033747b50c62f820888d7e1dbf5948a432e46fd8e895ccfa9bd2c554577
MD5 e05b075ca4e331e90b3b1a9aaa8b8153
BLAKE2b-256 8a17b14eb807a9790611865b4e39999cb457f913cdc35c7cf4686dfe9a83e0f7

See more details on using hashes here.

Provenance

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

Publisher: release.yml on m-aljasem/PyCVDRisk

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