OpenSafety 🩺
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:
- Adverse Drug Reaction (ADR) Extraction from clinical narratives.
- MedDRA Coding (LLT, Preferred Term, and Primary System Organ Class).
- 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)
| File | Size | Uploaded | |
|---|---|---|---|
| opensafety-0.1.0.tar.gz | 17.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|