medguardx-core
Context-aware PII/PHI detection and masking for healthcare data — a stateless, model-configurable, framework-agnostic Python engine. This is the reusable core of MedGuardX; embed it in any project.
Why
- Stateless & safe to embed — text and context in, masked text out. No auth, no database, no global state. Your app owns storage, identity, and audit.
- Bring your own model — any installed spaCy English pipeline works
(
en_core_web_sm/md/lg/trf). Pick your accuracy/RAM trade-off. - Model-independent structured IDs — Aadhaar (Verhoeff-validated), PAN, MRN, credit cards, IBAN, IP are matched by format, so they work identically on every model.
- Deterministic, leak-proof masking — overlapping detections are resolved by a fixed priority, and no strategy ever leaves part of a detected identifier visible.
Install
pip install medguardx-core
python -m spacy download en_core_web_md # recommended default
# other options: en_core_web_sm (smallest) · en_core_web_lg (best statistical)
# for the transformer model: pip install "medguardx-core[trf]" && python -m spacy download en_core_web_trf
The engine is model-agnostic — install any spaCy English pipeline and pass its name
to EngineConfig(model=...). (Model wheels aren't declared as dependencies because
spaCy models aren't on PyPI; spacy download is the standard way to fetch them.)
Quickstart
from medguardx import MedGuardEngine, EngineConfig, Role, Purpose
engine = MedGuardEngine(EngineConfig(model="en_core_web_md"))
result = engine.process(
"Patient John Smith, Aadhaar 2341 2341 2346, card 4111 1111 1111 1111.",
role=Role.NURSE, purpose=Purpose.TREATMENT, consent=False,
)
print(result.masking_strategy if False else result.strategy.value) # partial_mask
print(result.masked_text)
# Patient [NAME_REDACTED], Aadhaar [AADHAAR_REDACTED], card [CARD ****1111].
Compose the steps yourself when you need to:
entities = engine.detect(text) # list[PIIEntity]
strategy, rule = engine.evaluate_policy(Role.DOCTOR, Purpose.RESEARCH, consent=False)
masked = engine.mask(text, entities, strategy)
Configuration
EngineConfig(model=..., score_threshold=..., entities=[...], enable_custom_recognizers=True).
DATE_TIME is intentionally not in the default entity set — as a high-confidence
span it used to shadow phone numbers and Aadhaar. Add it back explicitly if you need
date masking.
Custom policy
from medguardx import PolicyEngine, MedGuardEngine, Role, Purpose, MaskingStrategy
rules = {(Role.COMPANY, Purpose.TREATMENT, True): (MaskingStrategy.PARTIAL_MASK, "vendor SLA")}
engine = MedGuardEngine(policy=PolicyEngine(rules=rules)) # deny-by-default for the rest
Masking strategies
| Strategy | Behaviour |
|---|---|
full_access |
text returned unchanged |
partial_mask |
identifiers redacted; card/phone/email keep a minimal safe hint |
full_anonymize |
every identifier replaced with a typed [TYPE_REDACTED] token |
deny |
access refused; no data returned |
Ingestion (optional)
medguardx.ingestion.extract_text(filename, bytes) pulls text from plain text, PDF
(pdfplumber), images (pytesseract), and HL7 (hl7apy). Those extractors import
their heavy deps lazily.
License
Apache-2.0.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file medguardx_core-1.0.0.tar.gz.
File metadata
- Download URL: medguardx_core-1.0.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65f8a23f1c5b03255226095f9f23dcf2d019856e5c445988ea44135d0a4fe7da
|
|
| MD5 |
db04064f2f2006b47d0ec4dc294c9438
|
|
| BLAKE2b-256 |
a8318b5a16f3312d2970d8285795a1a514ccd20b699f7bf9c995c878e06d0bff
|
Provenance
The following attestation bundles were made for medguardx_core-1.0.0.tar.gz:
Publisher:
publish-pypi.yml on adarshcod30/MedGuardX
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
medguardx_core-1.0.0.tar.gz -
Subject digest:
65f8a23f1c5b03255226095f9f23dcf2d019856e5c445988ea44135d0a4fe7da - Sigstore transparency entry: 2647259165
- Sigstore integration time:
-
Permalink:
adarshcod30/MedGuardX@ba83e0ebe0ba40330776da6a4c0d0cf7fba54a01 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/adarshcod30
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@ba83e0ebe0ba40330776da6a4c0d0cf7fba54a01 -
Trigger Event:
release
-
Statement type:
File details
Details for the file medguardx_core-1.0.0-py3-none-any.whl.
File metadata
- Download URL: medguardx_core-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
896f740f2616c83b3e51dcf4c4d436c1dd7a5e3610fc43b833055db9e716f3f5
|
|
| MD5 |
6b0f764c262fbde73fb68fd5b3de9048
|
|
| BLAKE2b-256 |
687a817806b56ab5420cd14d7b4a7dddfca2710d2cfe6655d52917b4a3bf2060
|
Provenance
The following attestation bundles were made for medguardx_core-1.0.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on adarshcod30/MedGuardX
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
medguardx_core-1.0.0-py3-none-any.whl -
Subject digest:
896f740f2616c83b3e51dcf4c4d436c1dd7a5e3610fc43b833055db9e716f3f5 - Sigstore transparency entry: 2647259182
- Sigstore integration time:
-
Permalink:
adarshcod30/MedGuardX@ba83e0ebe0ba40330776da6a4c0d0cf7fba54a01 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/adarshcod30
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@ba83e0ebe0ba40330776da6a4c0d0cf7fba54a01 -
Trigger Event:
release
-
Statement type: