comorbidipy
A high-performance Python package for calculating comorbidity scores and clinical risk scores from ICD codes.
Built with Polars for blazing-fast processing of large datasets.
Features
- Charlson Comorbidity Index – Multiple mapping variants (Quan, Swedish, Australian, SHMI) and weighting schemes
- Elixhauser Comorbidity Index – Quan mapping with van Walraven or Swiss weights
- Hospital Frailty Risk Score (HFRS) – For patients ≥75 years
- Disability & Sensory Impairments – Learning disabilities, visual and hearing impairments
Installation
pip install comorbidipy
Requires Python 3.13+.
Quick Start
Python API
import polars as pl
from comorbidipy import comorbidity, hfrs, disability
# Sample data
df = pl.DataFrame({
"id": ["P001", "P001", "P002", "P002"],
"code": ["I21", "E112", "I50", "J44"],
"age": [65, 65, 72, 72],
})
# Calculate Charlson Comorbidity Index
result = comorbidity(df, id_col="id", code_col="code", age_col="age")
# Calculate Hospital Frailty Risk Score
frailty = hfrs(df, id_col="id", code_col="code")
# Identify disabilities
disabilities = disability(df, id_col="id", code_col="code")
Command Line Interface
# Charlson score
comorbidipy charlson input.csv output.csv --age-col age
# Elixhauser score
comorbidipy elixhauser input.parquet output.parquet --weights van_walraven
# Hospital Frailty Risk Score
comorbidipy hfrs input.csv output.csv
# Disability identification
comorbidipy disability input.csv output.csv
# Show available options
comorbidipy info
Supported file formats: CSV, Parquet, JSON, NDJSON, Avro.
Charlson Variants
| Mapping | ICD-9 | ICD-10 | Description |
|---|---|---|---|
quan |
✅ | ✅ | Quan et al. (2005) |
swedish |
❌ | ✅ | Swedish National Patient Register |
australian |
❌ | ✅ | Australian IHW adaptation |
shmi |
❌ | ✅ | UK SHMI specification |
| Weighting | Description |
|---|---|
charlson |
Original 1987 weights |
quan |
Quan et al. updated weights |
shmi |
UK SHMI weights |
shmi_modified |
Modified SHMI weights |
Documentation
Full documentation: https://vvcb.github.io/comorbidipy
License
MIT License – see LICENSE for details.
Credits
- Inspired by the R library
comorbidityby Alessandro Gasparini - Built with Polars and Typer
Metadata
Release files for comorbidipy 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| comorbidipy-0.8.0.tar.gz | 103.6 kB | Without provenance | Details for comorbidipy-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| comorbidipy-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for comorbidipy-0.8.0-py3-none-any.whl |
Total release size: 125.3 kB
Release files / comorbidipy-0.8.0.tar.gz
| Download URL | comorbidipy-0.8.0.tar.gz |
|---|---|
| Size | 103.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
759cc321ae4eec7a3c0637661fbf541447e5be176b8adc2c29b2a45436c744dc
|
|
BLAKE2b-256 checksum How to use checksums |
4a1f05b24e28b266bea5acc55c436bc7d669439d31f1f4a9241603f6a4ffd43a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / comorbidipy-0.8.0-py3-none-any.whl
| Download URL | comorbidipy-0.8.0-py3-none-any.whl |
|---|---|
| Size | 21.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac280f660ff934c2cd8538896ce6be2f55c5e45a181e7f60c4906c2d7da5ed89
|
|
BLAKE2b-256 checksum How to use checksums |
8aeebc7bcd4c27b9aba636355b67101a15eeb02e3335bb1ea62e78d429f0e23c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for comorbidipy 0.8.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.