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)
#                en_core_web_trf (transformer — pulls torch automatically)

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.1.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.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file medguardx_core-1.0.1.tar.gz.

File metadata

  • Download URL: medguardx_core-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 c572a1405c74c4fa9da30bc18397c32f87daa764dc1783ba3d7a945da90b730a
MD5 9153bf1ac5b88321287f564f30b9f875
BLAKE2b-256 60fc77560254ffb7e7f8745c1ffd99a1b8d112bb2aaee9f6610c9fdf577593bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for medguardx_core-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: medguardx_core-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f8add438bcd1ea3c30fa66243387d2f948c162012ef6588aea5efee2c441d12e
MD5 00ea850e9de813d6d70154d998a55219
BLAKE2b-256 4277201e0cb103a2d83b940ec769e6ea0189edf3b7ff1b4b0e9205a8f07dc0af

See more details on using hashes here.

Provenance

The following attestation bundles were made for medguardx_core-1.0.1-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

This release

1.0.1 This release

2 files

1.0.0

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