Skip to main content

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

medguardx_core-1.0.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

medguardx_core-1.0.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

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

Hashes for medguardx_core-1.0.0.tar.gz
Algorithm Hash digest
SHA256 65f8a23f1c5b03255226095f9f23dcf2d019856e5c445988ea44135d0a4fe7da
MD5 db04064f2f2006b47d0ec4dc294c9438
BLAKE2b-256 a8318b5a16f3312d2970d8285795a1a514ccd20b699f7bf9c995c878e06d0bff

See more details on using hashes here.

Provenance

The following attestation bundles were made for medguardx_core-1.0.0.tar.gz:

Publisher: publish-pypi.yml on adarshcod30/MedGuardX

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

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

Hashes for medguardx_core-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 896f740f2616c83b3e51dcf4c4d436c1dd7a5e3610fc43b833055db9e716f3f5
MD5 6b0f764c262fbde73fb68fd5b3de9048
BLAKE2b-256 687a817806b56ab5420cd14d7b4a7dddfca2710d2cfe6655d52917b4a3bf2060

See more details on using hashes here.

Provenance

The following attestation bundles were made for medguardx_core-1.0.0-py3-none-any.whl:

Publisher: publish-pypi.yml on adarshcod30/MedGuardX

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

Release history Release notifications | RSS feed

1.0.1

2 files

This release

1.0.0 This release

2 files

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