fda-database by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --skill fda-database通过 openFDA(FDA 为公共数据集提供开放 API 的倡议)访问全面的 FDA 监管数据。使用 Python 和标准化接口查询有关药品、医疗器械、食品、动物/兽药产品以及物质的信息。
核心功能:
此技能适用于处理以下情况:
from scripts.fda_query import FDAQuery
# 初始化(API 密钥可选但推荐)
fda = FDAQuery(api_key="YOUR_API_KEY")
# 查询药品不良事件
events = fda.query_drug_events("aspirin", limit=100)
# 获取药品标签
label = fda.query_drug_label("Lipitor", brand=True)
# 搜索器械召回
recalls = fda.query("device", "enforcement",
search="classification:Class+I",
limit=50)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
虽然 API 无需密钥也可使用,但注册后可获得更高的速率限制:
设置为环境变量:
export FDA_API_KEY="your_key_here"
# 运行综合示例
python scripts/fda_examples.py
# 此示例演示:
# - 药品安全性概况
# - 器械监测
# - 食品召回监控
# - 物质查找
# - 药品比较分析
# - 兽药分析
访问 6 个与药品相关的端点,涵盖从批准到上市后监测的完整药品生命周期。
端点:
常见用例:
# 安全信号检测
fda.count_by_field("drug", "event",
search="patient.drug.medicinalproduct:metformin",
field="patient.reaction.reactionmeddrapt")
# 获取处方信息
label = fda.query_drug_label("Keytruda", brand=True)
# 检查召回情况
recalls = fda.query_drug_recalls(drug_name="metformin")
# 监控短缺情况
shortages = fda.query("drug", "drugshortages",
search="status:Currently+in+Shortage")
参考: 详细文档请参阅 references/drugs.md
访问 9 个与器械相关的端点,涵盖医疗器械安全性、批准和注册信息。
端点:
常见用例:
# 监控器械安全性
events = fda.query_device_events("pacemaker", limit=100)
# 查找器械分类
classification = fda.query_device_classification("DQY")
# 查找 510(k) 许可
clearances = fda.query_device_510k(applicant="Medtronic")
# 按 UDI 搜索
device_info = fda.query("device", "udi",
search="identifiers.id:00884838003019")
参考: 详细文档请参阅 references/devices.md
访问 2 个与食品相关的端点,用于安全监测和召回。
端点:
常见用例:
# 监控过敏原召回
recalls = fda.query_food_recalls(reason="undeclared peanut")
# 跟踪膳食补充剂事件
events = fda.query_food_events(
industry="Dietary Supplements")
# 查找污染召回
listeria = fda.query_food_recalls(
reason="listeria",
classification="I")
参考: 详细文档请参阅 references/foods.md
访问兽药不良事件数据,包含物种特异性信息。
端点:
常见用例:
# 物种特异性事件
dog_events = fda.query_animal_events(
species="Dog",
drug_name="flea collar")
# 品种易感性分析
breed_query = fda.query("animalandveterinary", "event",
search="reaction.veddra_term_name:*seizure*+AND+"
"animal.breed.breed_component:*Labrador*")
参考: 详细文档请参阅 references/animal_veterinary.md
访问分子级别的物质数据,包括 UNII 代码、化学结构和关系。
端点:
常见用例:
# UNII 到 CAS 映射
substance = fda.query_substance_by_unii("R16CO5Y76E")
# 按名称搜索
results = fda.query_substance_by_name("acetaminophen")
# 获取化学结构
structure = fda.query("other", "substance",
search="names.name:ibuprofen+AND+substanceClass:chemical")
参考: 详细文档请参阅 references/other.md
结合多个数据源创建全面的安全性概况:
def drug_safety_profile(fda, drug_name):
"""生成完整的安全性概况。"""
# 1. 总不良事件数
events = fda.query_drug_events(drug_name, limit=1)
total = events["meta"]["results"]["total"]
# 2. 最常见反应
reactions = fda.count_by_field(
"drug", "event",
search=f"patient.drug.medicinalproduct:*{drug_name}*",
field="patient.reaction.reactionmeddrapt",
exact=True
)
# 3. 严重事件
serious = fda.query("drug", "event",
search=f"patient.drug.medicinalproduct:*{drug_name}*+AND+serious:1",
limit=1)
# 4. 近期召回
recalls = fda.query_drug_recalls(drug_name=drug_name)
return {
"total_events": total,
"top_reactions": reactions["results"][:10],
"serious_events": serious["meta"]["results"]["total"],
"recalls": recalls["results"]
}
使用日期范围分析时间趋势:
from datetime import datetime, timedelta
def get_monthly_trends(fda, drug_name, months=12):
"""获取月度不良事件趋势。"""
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}*+AND+receivedate:{date_range}"
result = fda.query("drug", "event", search=search, limit=1)
count = result["meta"]["results"]["total"] if "meta" in result else 0
trends.append({
"month": start.strftime("%Y-%m"),
"events": count
})
return trends
并排比较多个产品:
def compare_drugs(fda, drug_list):
"""比较多种药物的安全性概况。"""
comparison = {}
for drug in drug_list:
# 总事件数
events = fda.query_drug_events(drug, limit=1)
total = events["meta"]["results"]["total"] if "meta" in events else 0
# 严重事件数
serious = fda.query("drug", "event",
search=f"patient.drug.medicinalproduct:*{drug}*+AND+serious:1",
limit=1)
serious_count = serious["meta"]["results"]["total"] if "meta" in serious else 0
comparison[drug] = {
"total_events": total,
"serious_events": serious_count,
"serious_rate": (serious_count/total*100) if total > 0 else 0
}
return comparison
跨多个端点链接数据:
def comprehensive_device_lookup(fda, device_name):
"""在所有相关数据库中查找器械。"""
return {
"adverse_events": fda.query_device_events(device_name, limit=10),
"510k_clearances": fda.query_device_510k(device_name=device_name),
"recalls": fda.query("device", "enforcement",
search=f"product_description:*{device_name}*"),
"udi_info": fda.query("device", "udi",
search=f"brand_name:*{device_name}*")
}
所有 API 响应都遵循此结构:
{
"meta": {
"disclaimer": "...",
"results": {
"skip": 0,
"limit": 100,
"total": 15234
}
},
"results": [
# 结果对象数组
]
}
始终处理潜在错误:
result = fda.query_drug_events("aspirin", limit=10)
if "error" in result:
print(f"错误:{result['error']}")
elif "results" not in result or len(result["results"]) == 0:
print("未找到结果")
else:
# 处理结果
for event in result["results"]:
# 处理事件数据
pass
对于大型结果集,使用分页:
# 自动分页
all_results = fda.query_all(
"drug", "event",
search="patient.drug.medicinalproduct:aspirin",
max_results=5000
)
# 手动分页
for skip in range(0, 1000, 100):
batch = fda.query("drug", "event",
search="...",
limit=100,
skip=skip)
# 处理批次
应:
# 具体字段搜索
search="patient.drug.medicinalproduct:aspirin"
不应:
# 过于宽泛的通配符
search="*aspirin*"
FDAQuery 类会自动处理速率限制,但请注意限制:
FDAQuery 类包含内置缓存(默认启用):
# 缓存是自动的
fda = FDAQuery(api_key=api_key, use_cache=True, cache_ttl=3600)
计数/聚合时,使用 .exact 后缀:
# 计算精确短语
fda.count_by_field("drug", "event",
search="...",
field="patient.reaction.reactionmeddrapt",
exact=True) # 自动添加 .exact
清理和验证搜索词:
def clean_drug_name(name):
"""清理查询的药品名称。"""
return name.strip().replace('"', '\\"')
drug_name = clean_drug_name(user_input)
有关以下内容的详细信息:
references/api_basics.mdreferences/drugs.mdreferences/devices.mdreferences/foods.mdreferences/animal_veterinary.mdreferences/other.mdscripts/fda_query.py主要查询模块,提供 FDAQuery 类:
scripts/fda_examples.py综合示例,演示:
运行示例:
python scripts/fda_examples.py
问题:超出速率限制
问题:未找到结果
问题:查询语法无效
references/api_basics.md 中的查询语法问题:结果中缺少字段
每周安装次数
132
代码仓库
GitHub 星标数
22.6K
首次出现
Jan 21, 2026
安全审计
安装于
claude-code110
opencode104
gemini-cli100
cursor97
codex90
antigravity89
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:
This skill should be used when working with:
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)
While the API works without a key, registering provides higher rate limits:
Register at: https://open.fda.gov/apis/authentication/
Set as environment variable:
export FDA_API_KEY="your_key_here"
# 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
Access 6 drug-related endpoints covering the full drug lifecycle from approval to post-market surveillance.
Endpoints:
Common use cases:
# 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
Access 9 device-related endpoints covering medical device safety, approvals, and registrations.
Endpoints:
Common use cases:
# 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
Access 2 food-related endpoints for safety monitoring and recalls.
Endpoints:
Common use cases:
# 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
Access veterinary drug adverse event data with species-specific information.
Endpoint:
Common use cases:
# Species-specific events
dog_events = fda.query_animal_events(
species="Dog",
drug_name="flea collar")
# Breed predisposition analysis
breed_query = fda.query("animalandveterinary", "event",
search="reaction.veddra_term_name:*seizure*+AND+"
"animal.breed.breed_component:*Labrador*")
Reference: See references/animal_veterinary.md for detailed documentation
Access molecular-level substance data with UNII codes, chemical structures, and relationships.
Endpoints:
Common use cases:
# UNII to CAS mapping
substance = fda.query_substance_by_unii("R16CO5Y76E")
# Search by name
results = fda.query_substance_by_name("acetaminophen")
# Get chemical structure
structure = fda.query("other", "substance",
search="names.name:ibuprofen+AND+substanceClass:chemical")
Reference: See references/other.md for detailed documentation
Create comprehensive safety profiles combining multiple data sources:
def drug_safety_profile(fda, drug_name):
"""Generate complete safety profile."""
# 1. Total adverse events
events = fda.query_drug_events(drug_name, limit=1)
total = events["meta"]["results"]["total"]
# 2. Most common reactions
reactions = fda.count_by_field(
"drug", "event",
search=f"patient.drug.medicinalproduct:*{drug_name}*",
field="patient.reaction.reactionmeddrapt",
exact=True
)
# 3. Serious events
serious = fda.query("drug", "event",
search=f"patient.drug.medicinalproduct:*{drug_name}*+AND+serious:1",
limit=1)
# 4. Recent recalls
recalls = fda.query_drug_recalls(drug_name=drug_name)
return {
"total_events": total,
"top_reactions": reactions["results"][:10],
"serious_events": serious["meta"]["results"]["total"],
"recalls": recalls["results"]
}
Analyze trends over time using date ranges:
from datetime import datetime, timedelta
def get_monthly_trends(fda, drug_name, months=12):
"""Get monthly adverse event trends."""
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}*+AND+receivedate:{date_range}"
result = fda.query("drug", "event", search=search, limit=1)
count = result["meta"]["results"]["total"] if "meta" in result else 0
trends.append({
"month": start.strftime("%Y-%m"),
"events": count
})
return trends
Compare multiple products side-by-side:
def compare_drugs(fda, drug_list):
"""Compare safety profiles of multiple drugs."""
comparison = {}
for drug in drug_list:
# Total events
events = fda.query_drug_events(drug, limit=1)
total = events["meta"]["results"]["total"] if "meta" in events else 0
# Serious events
serious = fda.query("drug", "event",
search=f"patient.drug.medicinalproduct:*{drug}*+AND+serious:1",
limit=1)
serious_count = serious["meta"]["results"]["total"] if "meta" in serious else 0
comparison[drug] = {
"total_events": total,
"serious_events": serious_count,
"serious_rate": (serious_count/total*100) if total > 0 else 0
}
return comparison
Link data across multiple endpoints:
def comprehensive_device_lookup(fda, device_name):
"""Look up device across all relevant databases."""
return {
"adverse_events": fda.query_device_events(device_name, limit=10),
"510k_clearances": fda.query_device_510k(device_name=device_name),
"recalls": fda.query("device", "enforcement",
search=f"product_description:*{device_name}*"),
"udi_info": fda.query("device", "udi",
search=f"brand_name:*{device_name}*")
}
All API responses follow this structure:
{
"meta": {
"disclaimer": "...",
"results": {
"skip": 0,
"limit": 100,
"total": 15234
}
},
"results": [
# Array of result objects
]
}
Always handle potential errors:
result = fda.query_drug_events("aspirin", limit=10)
if "error" in result:
print(f"Error: {result['error']}")
elif "results" not in result or len(result["results"]) == 0:
print("No results found")
else:
# Process results
for event in result["results"]:
# Handle event data
pass
For large result sets, use pagination:
# Automatic pagination
all_results = fda.query_all(
"drug", "event",
search="patient.drug.medicinalproduct:aspirin",
max_results=5000
)
# Manual pagination
for skip in range(0, 1000, 100):
batch = fda.query("drug", "event",
search="...",
limit=100,
skip=skip)
# Process batch
DO:
# Specific field search
search="patient.drug.medicinalproduct:aspirin"
DON'T:
# Overly broad wildcard
search="*aspirin*"
The FDAQuery class handles rate limiting automatically, but be aware of limits:
The FDAQuery class includes built-in caching (enabled by default):
# Caching is automatic
fda = FDAQuery(api_key=api_key, use_cache=True, cache_ttl=3600)
When counting/aggregating, use .exact suffix:
# Count exact phrases
fda.count_by_field("drug", "event",
search="...",
field="patient.reaction.reactionmeddrapt",
exact=True) # Adds .exact automatically
Clean and validate search terms:
def clean_drug_name(name):
"""Clean drug name for query."""
return name.strip().replace('"', '\\"')
drug_name = clean_drug_name(user_input)
For detailed information about:
references/api_basics.mdreferences/drugs.mdreferences/devices.mdreferences/foods.mdreferences/animal_veterinary.mdreferences/other.mdscripts/fda_query.pyMain query module with FDAQuery class providing:
scripts/fda_examples.pyComprehensive examples demonstrating:
Run examples:
python scripts/fda_examples.py
Issue : Rate limit exceeded
Issue : No results found
Issue : Invalid query syntax
references/api_basics.mdIssue : Missing fields in results
Weekly Installs
132
Repository
GitHub Stars
22.6K
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
claude-code110
opencode104
gemini-cli100
cursor97
codex90
antigravity89
lark-cli 共享规则:飞书资源操作指南与权限配置详解
27,500 周安装