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.

Metadata

Release files for medguardx-core 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for medguardx-core 1.0.1
File Size Uploaded
medguardx_core-1.0.1.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for medguardx-core 1.0.1
File Interpreter ABI Platform
medguardx_core-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.1 kB

Release files / medguardx_core-1.0.1.tar.gz

Download URL medguardx_core-1.0.1.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c572a1405c74c4fa9da30bc18397c32f87daa764dc1783ba3d7a945da90b730a
BLAKE2b-256 checksum
How to use checksums
60fc77560254ffb7e7f8745c1ffd99a1b8d112bb2aaee9f6610c9fdf577593bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release files / medguardx_core-1.0.1-py3-none-any.whl

Download URL medguardx_core-1.0.1-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8add438bcd1ea3c30fa66243387d2f948c162012ef6588aea5efee2c441d12e
BLAKE2b-256 checksum
How to use checksums
4277201e0cb103a2d83b940ec769e6ea0189edf3b7ff1b4b0e9205a8f07dc0af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release 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