domains / research / fda-openapi-query / fda-database
The three copies describe the same openFDA Python client, but they are not interchangeable. The Vibe-Skills and OpenClaw copies are near-identical reference documents that enumerate endpoints and point to reference files, while the aipoch copy adds concrete, runnable analysis patterns (safety profile, monthly trend, serious-event rate, pagination/aggregation notes, dependency pinning) and names additional reference files. Crowning one copy would hide either the detailed endpoint catalog or the operational analysis steps, so the catalog should combine them.
| Repository | Path |
|---|---|
| foryourhealth111-pixel/Vibe-Skills | bundled/skills/fda-database/SKILL.md |
| aipoch/medical-research-skills | scientific-skills/Evidence Insight/fda-database/SKILL.md |
| FreedomIntelligence/OpenClaw-Medical-Skills | skills/fda-database/SKILL.md |
| Role | Repository | Path |
|---|---|---|
| peer | foryourhealth111-pixel/Vibe-Skills | bundled/skills/fda-database/SKILL.md |
| peer | aipoch/medical-research-skills | scientific-skills/Evidence Insight/fda-database/SKILL.md |
| peer | FreedomIntelligence/OpenClaw-Medical-Skills | skills/fda-database/SKILL.md |
---
name: fda-database
description: Query the openFDA API for drugs, devices, adverse events, recalls, regulatory submissions (510k, PMA), and substance identification (UNII) for FDA regulatory data analysis and safety research.
license: Unknown
metadata:
skill-author: K-Dense Inc. / AIPOCH
---
# FDA Database Access
## Overview
Access comprehensive FDA regulatory data through openFDA, the FDA's initiative to provide open APIs for public datasets. Query information about drugs, medical devices, foods, animal/veterinary products, and substances using Python with standardized interfaces.
**Key capabilities:**
- Query adverse events for drugs, devices, foods, and veterinary products
- Access product labeling, approvals, and regulatory submissions
- Monitor recalls and enforcement actions
- Look up National Drug Codes (NDC) and substance identifiers (UNII)
- Analyze device classifications and clearances (510k, PMA)
- Track drug shortages and supply issues
- Research chemical structures and substance relationships
## When to Use This Skill
Use this skill when working with:
- **Drug research**: Safety profiles, adverse events, labeling, approvals, shortages
- **Medical device surveillance**: Adverse events, recalls, 510(k) clearances, PMA approvals
- **Food safety**: Recalls, allergen tracking, adverse events, dietary supplements
- **Veterinary medicine**: Animal drug adverse events by species and breed
- **Chemical/substance data**: UNII lookup, CAS number mapping, molecular structures
- **Regulatory analysis**: Approval pathways, enforcement actions, compliance tracking
- **Pharmacovigilance**: Post-market surveillance, safety signal detection
- **Scientific research**: Drug interactions, comparative safety, epidemiological studies
## Dependencies
- Python **3.9+**
- openFDA API access (public)
- Optional: openFDA API key (recommended for higher daily quota)
- Package-level dependencies (e.g., `requests`) are defined by the repository implementation in `scripts/fda_query.py`. If you maintain this skill, pin them in `requirements.txt` (for example, `requests==2.31.0`) to ensure reproducibility.
## Quick Start
### 1. Basic Setup
```python
from scripts.fda_query import FDAQuery
# Initialize (API key optional but recommended)
fda = FDAQuery(api_key="YOUR_API_KEY")
# Query drug adverse events
events = fda.query_drug_events("aspirin", limit=100)
# Get drug labeling
label = fda.query_drug_label("Lipitor", brand=True)
# Search device recalls
recalls = fda.query("device", "enforcement",
search="classification:Class+I",
limit=50)
```
### 2. API Key Setup
While the API works without a key, registering provides higher rate limits:
- **Without key**: 240 requests/min, 1,000/day
- **With key**: 240 requests/min, 120,000/day
Register at: https://open.fda.gov/apis/authentication/
Set as environment variable:
```bash
export FDA_API_KEY="your_key_here"
```
### 3. Running Examples
```bash
# Run comprehensive examples
python scripts/fda_examples.py
# This demonstrates:
# - Drug safety profiles
# - Device surveillance
# - Food recall monitoring
# - Substance lookup
# - Comparative drug analysis
# - Veterinary drug analysis
```
## FDA Database Categories
### Drugs
Access 6 drug-related endpoints covering the full drug lifecycle from approval to post-market surveillance.
**Endpoints:**
1. **Adverse Events** - Reports of side effects, errors, and therapeutic failures
2. **Product Labeling** - Prescribing information, warnings, indications
3. **NDC Directory** - National Drug Code product information
4. **Enforcement Reports** - Drug recalls and safety actions
5. **Drugs@FDA** - Historical approval data since 1939
6. **Drug Shortages** - Current and resolved supply issues
**Common use cases:**
```python
# Safety signal detection
fda.count_by_field("drug", "event",
search="patient.drug.medicinalproduct:metformin",
field="patient.reaction.reactionmeddrapt")
# Get prescribing information
label = fda.query_drug_label("Keytruda", brand=True)
# Check for recalls
recalls = fda.query_drug_recalls(drug_name="metformin")
# Monitor shortages
shortages = fda.query("drug", "drugshortages",
search="status:Currently+in+Shortage")
```
**Reference:** See `references/drugs.md` for detailed documentation
### Devices
Access 9 device-related endpoints covering medical device safety, approvals, and registrations.
**Endpoints:**
1. **Adverse Events** - Device malfunctions, injuries, deaths
2. **510(k) Clearances** - Premarket notifications
3. **Classification** - Device categories and risk classes
4. **Enforcement Reports** - Device recalls
5. **Recalls** - Detailed recall information
6. **PMA** - Premarket approval data for Class III devices
7. **Registrations & Listings** - Manufacturing facility data
8. **UDI** - Unique Device Identification database
9. **COVID-19 Serology** - Antibody test performance data
**Common use cases:**
```python
# Monitor device safety
events = fda.query_device_events("pacemaker", limit=100)
# Look up device classification
classification = fda.query_device_classification("DQY")
# Find 510(k) clearances
clearances = fda.query_device_510k(applicant="Medtronic")
# Search by UDI
device_info = fda.query("device", "udi",
search="identifiers.id:00884838003019")
```
**Reference:** See `references/devices.md` for detailed documentation
### Foods
Access 2 food-related endpoints for safety monitoring and recalls.
**Endpoints:**
1. **Adverse Events** - Food, dietary supplement, and cosmetic events
2. **Enforcement Reports** - Food product recalls
**Common use cases:**
```python
# Monitor allergen recalls
recalls = fda.query_food_recalls(reason="undeclared peanut")
# Track dietary supplement events
events = fda.query_food_events(
industry="Dietary Supplements")
# Find contamination recalls
listeria = fda.query_food_recalls(
reason="listeria",
classification="I")
```
**Reference:** See `references/foods.md` for detailed documentation
### Animal & Veterinary
Access veterinary drug adverse event data with species-specific information.
**Endpoint:**
1. **Adverse Events** - Animal drug side effects by species, breed, and product
**Common use cases:**
```python
# Species-specific events
dog_events = fda.query_animal_events(
species="Dog",
drug_name="flea collar")
```
**Reference:** See `references/animal_veterinary.md` for detailed documentation
### Substances
Access substance identification data including UNII, CAS numbers, and molecular structures.
**Common use cases:**
```python
# UNII lookup
substance = fda.query_substance_by_unii("R16CO5Y76E")
```
**Reference:** See `references/other.md` for detailed documentation
## Operational Safeguards
- Optional API key support for higher daily limits
- Built-in caching (TTL) and rate limiting (as implemented in `scripts/fda_query.py`)
- Basic error handling patterns
- Supports openFDA query patterns: fielded search strings, date ranges, wildcards
- Aggregations via `count_by_field(...)` (with `.exact` support)
- Pagination via `skip/limit` and bulk retrieval via `query_all(...)`
## Example Usage
The following example is designed to be runnable in a repository that contains `scripts/fda_query.py` and the `FDAQuery` class.
### 1) Set an API key (optional, recommended)
```bash
export FDA_API_KEY="your_key_here"
```
### 2) Run a complete script
```python
import os
from datetime import datetime, timedelta
from scripts.fda_query import FDAQuery
def drug_safety_profile(fda: FDAQuery, drug_name: str):
# Total adverse events (meta.total)
events = fda.query_drug_events(drug_name, limit=1)
total = events.get("meta", {}).get("results", {}).get("total", 0)
# Top reactions (aggregation)
reactions = fda.count_by_field(
"drug",
"event",
search=f"patient.drug.medicinalproduct:*{drug_name}*",
field="patient.reaction.reactionmeddrapt",
exact=True,
)
top_reactions = reactions.get("results", [])[:10]
# Serious events
serious = fda.query(
"drug",
"event",
search=f"patient.drug.medicinalproduct:*{drug_name}*+AND+serious:1",
limit=1,
)
serious_total = serious.get("meta", {}).get("results", {}).get("total", 0)
# Recent recalls
recalls = fda.query_drug_recalls(drug_name=drug_name)
recall_results = recalls.get("results", [])
return {
"drug": drug_name,
"total_events": total,
"serious_events": serious_total,
"serious_rate_pct": (serious_total / total * 100.0) if total else 0.0,
"top_reactions": top_reactions,
"recalls_sample": recall_results[:5],
}
def monthly_event_trend(fda: FDAQuery, drug_name: str, months: int = 6):
trends = []
for i in range(months):
end = datetime.now() - timedelta(days=30 * i)
start = end - timedelta(days=30)
date_range = f"[{start.strftime('%Y%m%d')}+TO+{end.strftime('%Y%m%d')}]"
search = (
f"patient.drug.medicinalproduct:*{drug_name}*"
f"+AND+receivedate:{date_range}"
)
result = fda.query("drug", "event", search=search, limit=1)
count = result.get("meta", {}).get("results", {}).get("total", 0)
trends.append({"month": start.strftime("%Y-%m"), "events": count})
return list(reversed(trends))
def main():
fda = FDAQuery(api_key=os.getenv("FDA_API_KEY"))
# Drug: safety profile + trend
profile = drug_safety_profile(fda, "aspirin")
trend = monthly_event_trend(fda, "aspirin", months=6)
# Device: quick cross-database lookup
device_lookup = {
"adverse_events": fda.query_device_events("pacemaker", limit=10),
"classification": fda.query_device_classification("DQY"),
"510k": fda.query_device_510k(applicant="Medtronic"),
"udi": fda.query("device", "udi", search="brand_name:*pacemaker*", limit=5),
}
# Food: recall monitoring
food_recalls = fda.query_food_recalls(reason="undeclared peanut", limit=10)
# Substance: UNII lookup
substance = fda.query_substance_by_unii("R16CO5Y76E")
print({"drug_profile": profile, "drug_trend": trend})
print({"device_lookup_keys": list(device_lookup.keys())})
print({"food_recalls_count": len(food_recalls.get("results", []))})
print({"substance_keys": list(substance.keys())})
if __name__ == "__main__":
main()
```
### 3) Run the repository examples (if provided)
```bash
python scripts/fda_examples.py
```
## Implementation Details
### API domains and endpoints
This skill is a thin client over openFDA endpoints, typically accessed as:
- **Drugs**: drug/event, drug/label, drug/ndc, drug/enforcement, drug/drugsfda, drug/drugshortages
- **Devices**: device/event, device/510k, device/classification, device/enforcement, device/recall, device/pma, device/registration, device/udi, device/covid19serology
- **Foods**: food/event, food/enforcement
- **Animal & Veterinary**: animalandveterinary/event
- **Other**: substance/identifier, substance/structure
> Additional endpoint notes and query syntax are typically documented in:
> `references/api_basics.md`, `references/drugs.md`, `references/devices.md`, `references/foods.md`, `references/animal_veterinary.md`, `references/other.md`.