OpenSafety 🩺
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:
- Adverse Drug Reaction (ADR) Extraction from raw clinical text.
- MedDRA Coding (LLT, Preferred Term, and Primary System Organ Class).
- Regulatory Listedness Assessment against Reference Safety Information (RSI / Product Labels).
Installation
pip install opensafety
💻 Effortless Terminal CLI Usage
OpenSafety provides an interactive, terminal-first interface designed for effortless case reviews:
1. Interactive Guided Wizard (Paste Narrative & Attach RSI):
Simply run opensafety in your terminal:
opensafety
- Step 1: Paste Narrative or Drag-and-Drop File:
- Paste your multi-line clinical narrative (press Enter twice or type
DONEto finish). - Or simply drag & drop a case file (
.pdf,.docx,.txt,.md) directly into the terminal window! - Or press
Dto immediately run the built-in clinical demo case.
- Paste your multi-line clinical narrative (press Enter twice or type
- Step 2: Attach Reference Safety Information (RSI):
- Drag & drop an SmPC / USPI / IB document (
.pdf,.docx,.txt), OR - Paste Section 4.8 / Undesirable Effects text directly, OR
- Press Enter to skip (performs ADR coding without listedness).
- Drag & drop an SmPC / USPI / IB document (
- Step 3: Suspect Drug Name (Optional):
- Type the drug name, or press Enter to auto-extract suspect drugs directly from the narrative!
- Step 4: Real-time Analysis & Validation:
- Outputs color-coded cards (
🟢 LISTEDvs🔴 UNLISTED,✅ VERIFIED MedDRA v28.0). - Option to save as JSON or an ICH E2B(R3) ICSR (
.xml).
- Outputs color-coded cards (
2. Instant Built-in Demo Case:
opensafety demo
Runs an end-to-end clinical case (Atorvastatin with Rhabdomyolysis and Acute Renal Failure against SmPC Section 4.8) in seconds.
3. Command-Line File / Pipe Mode:
# Attach PDF / Word documents directly:
opensafety analyze --narrative case.pdf --rsi smpc_section_4_8.docx -o report.json
# Or pipe text from another command or file:
cat case_narrative.txt | opensafety analyze --rsi label.pdf
4. Fast MedDRA v28.0 Ontology Lookup:
opensafety lookup "muscle pain"
opensafety lookup "rhabdomyolysis"
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}")
Instant MedDRA v28.0 Dictionary & Fuzzy Search
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.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opensafety-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for opensafety-0.3.3-py3-none-any.whl |
Release files / opensafety-0.3.3-py3-none-any.whl
| Download URL | opensafety-0.3.3-py3-none-any.whl |
|---|---|
| Size | 41.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c076d3648ecaee8e4006afcd4d64d37fa32cc86dca75b1b30a79a7e5e787b08f
|
|
BLAKE2b-256 checksum How to use checksums |
bb09c4f7e243831a422be9f868631a6083854de8926af5ddc8d41b433ae5b256
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for opensafety 0.3.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.