Skip to main content

OpenSafety 🩺

PyPI version Hugging Face License

OpenSafety is an open-source Pharmacovigilance (PV) AI toolkit powered by the OpenSafety-1.5B foundation model and deterministic MedDRA v28.0 ontology verification for:

  1. Adverse Drug Reaction (ADR) Extraction from raw clinical text.
  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: End-to-End AI Pharmacovigilance

from opensafety import OpenSafetyEngine

# 1. Initialize the engine (automatically loads the OpenSafety-1.5B model)
engine = OpenSafetyEngine()

# 2. Analyze a raw patient 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."
)

# 3. 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}")
    print(f"Validation: {event.validation_status}")

from opensafety import MedDRADatabase, HybridMedDRAMatcher

# Exact dictionary lookup (89,774 LLTs & 26,920 PTs)
db = MedDRADatabase("meddra.db")
res = db.search_term("Dry cough")
print(res[0]["pt_name"])  # "Cough"
print(res[0]["soc_name"]) # "Respiratory, thoracic and mediastinal disorders"

# Colloquial fuzzy matching for patient expressions
matcher = HybridMedDRAMatcher("meddra.db")
matches = matcher.search("stomach ache", top_k=1)
print(matches[0]["pt_name"])  # "Abdominal pain upper"

Architecture: Hybrid Safety Engine

[ Clinical Narrative / Case Report ] + [ Reference Safety Info (RSI) ]
                                  │
                                  ▼
               OpenSafety-1.5B Clinical Foundation Model
                                  │
                                  ▼
                     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.2.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.2.0
File Size Uploaded
opensafety-0.2.0.tar.gz 17.5 kB Details

Built distribution (wheel)

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

Total release size: 36.3 kB

Release files / opensafety-0.2.0.tar.gz

Download URL opensafety-0.2.0.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dd3c219f0cbff66050be617eeea4c716ff3b0357e66174e27b200ee0b5a1cd52
BLAKE2b-256 checksum
How to use checksums
da5554d85388c6929d4e9a5e5498ce73fddb3ae123b22461defd5b9e24e1bb39
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.2.0-py3-none-any.whl

Download URL opensafety-0.2.0-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
765444492381a1799306202e9dd4b271d006792a5aa6c6ceb94b6b069b553a1e
BLAKE2b-256 checksum
How to use checksums
57beda9eb9cc904988c801de799bc3caeea2907822cb0c7f23d6f8cc9302fc3c
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

This release

0.2.0 This release

2 release files

0.1.0

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