Skip to main content

OpenSafety 🩺

PyPI version License

OpenSafety is an open-source Pharmacovigilance (PV) AI toolkit that combines fine-tuned Small Language Models (SLMs) with deterministic MedDRA v28.0 ontology verification for:

  1. Adverse Drug Reaction (ADR) Extraction from clinical narratives.
  2. MedDRA Coding (LLT, Preferred Term, and Primary System Organ Class).
  3. Regulatory Listedness Assessment against Reference Safety Information (RSI / Product Labels).

Installation

pip install opensafety

Quick Start

1. Instant MedDRA v28.0 Search & Coding

from opensafety import MedDRADatabase, HybridMedDRAMatcher

# 1. Connect to the indexed MedDRA database
db = MedDRADatabase("meddra.db")

# 2. Look up exact regulatory terms
res = db.search_term("Dry cough")
print(res[0]["pt_name"])  # "Cough"
print(res[0]["soc_name"]) # "Respiratory, thoracic and mediastinal disorders"

# 3. Fuzzy & colloquial matching from patient verbatims
matcher = HybridMedDRAMatcher("meddra.db")
matches = matcher.search("stomach ache", top_k=1)
print(matches[0]["pt_name"])  # "Abdominal pain upper"

2. End-to-End AI Pharmacovigilance Pipeline

from opensafety import OpenSafetyEngine

# Initialize the engine with your trained LoRA adapter and MedDRA database
engine = OpenSafetyEngine(
    adapter_path="opensafety_qwen_adapter",
    meddra_db_path="meddra.db"
)

# Analyze a raw clinical narrative
report = engine.analyze(
    drug="Atorvastatin",
    narrative="A 62-year-old female taking Atorvastatin 40mg daily developed acute muscle weakness and soreness in her calves.",
    rsi="Section 4.8 Undesirable Effects: Common: myalgia, arthralgia, pain in extremity, muscle spasms."
)

# Inspect verified regulatory output
for event in report.adverse_events:
    print(f"Verbatim: {event.verbatim}")
    print(f"MedDRA PT: {event.meddra_pt} (Code: {event.meddra_pt_code})")
    print(f"Primary SOC: {event.meddra_soc}")
    print(f"Listedness: {event.listedness.status}")
    print(f"Rationale: {event.listedness.rationale}")

Architecture: Hybrid Safety Engine

[ Clinical Narrative / Case Report ] + [ Reference Safety Info (RSI) ]
                                  │
                                  ▼
      Fine-Tuned Qwen 2.5 (1.5B) Pharmacovigilance SLM
                                  │
                                  ▼
                     Extracted Structured JSON
                                  │
                                  ▼
         Deterministic MedDRA v28.0 SQLite Verification
            (Zero hallucination, verified 8-digit codes)
                                  │
                                  ▼
              Validated ICH E2B(R3) Structured Report

License

Apache License 2.0. MedDRA is copyrighted by the International Council for Harmonisation (ICH) and maintained by MSSO.

Metadata

Release files for opensafety 0.1.0

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

Source distribution (sdist)

Source distribution for opensafety 0.1.0
File Size Uploaded
opensafety-0.1.0.tar.gz 17.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opensafety 0.1.0
File Interpreter ABI Platform
opensafety-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.5 kB

Release files / opensafety-0.1.0.tar.gz

Download URL opensafety-0.1.0.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a9525a15f62e2134dd98297e2d7f321c5c5ed0420efb3bd8ce2307f0d7350f35
BLAKE2b-256 checksum
How to use checksums
7796f7e840ee35b1b9d5d0e158bbfaaa03c7b5c82ff7cd09addf16945a5847a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / opensafety-0.1.0-py3-none-any.whl

Download URL opensafety-0.1.0-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51055544c40ea4147ef2ddc365545606ffeaf072dfe297278a4bb4626a9492f3
BLAKE2b-256 checksum
How to use checksums
a9a120daa567b4d27e63c7c95f5d2990a5f0b0b88ac63005e29b174617857b03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

2 release files

0.0.1

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