关于 openalex-database
OpenAlex Database 提供查询 OpenAlex 学术目录的工具和工作流,适用于研究人员及文献分析者。它涵盖论文、作者和机构等实体,并支持批量查询、引文分析与研究趋势分析。
主要功能
- 01搜索论文及学术实体
- 02按作者或机构查找论文
- 03筛选开放获取与高被引论文
- 04分析出版趋势和研究产出
- 05批量查询 DOI、ORCID 等标识符
- 06分页提取大型数据集
适用场景
- 01整理特定主题的相关文献
- 02分析研究人员或机构的产出
- 03追踪论文引用与出版趋势
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ davila7/ claude-code-templates --skill openalex-database安装后在 Claude Code 中输入/openalex-database确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/api_guide.mdcommon_queries.mdscripts/openalex_client.pyquery_helpers.py详细介绍
OpenAlex 数据库
概述
OpenAlex 是一个全面的开放目录,收录了 2.4 亿多篇学术作品、作者、机构、主题、来源、出版商和资助机构。本技能提供了用于查询 OpenAlex API 的工具和工作流,以便检索文献、分析研究成果、追踪引用以及开展文献计量研究。
快速开始
基本设置
始终使用电子邮件地址初始化客户端,以访问礼貌池(速率限制提升 10 倍):
from scripts.openalex_client import OpenAlexClient
client = OpenAlexClient(email="[email protected]")
安装要求
使用 uv 安装所需包:
uv pip install requests
无需 API 密钥 - OpenAlex 完全开放。
核心能力
1. 检索论文
用于:按标题、摘要或主题查找论文
# Simple search
results = client.search_works(
search="machine learning",
per_page=100
)
# Search with filters
results = client.search_works(
search="CRISPR gene editing",
filter_params={
"publication_year": ">2020",
"is_oa": "true"
},
sort="cited_by_count:desc"
)
2. 按作者查找作品
用于:获取特定研究者的所有出版物
使用两步模式(实体名称 → ID → 作品):
from scripts.query_helpers import find_author_works
works = find_author_works(
author_name="Jennifer Doudna",
client=client,
limit=100
)
手动两步方法:
# Step 1: Get author ID
author_response = client._make_request(
'/authors',
params={'search': 'Jennifer Doudna', 'per-page': 1}
)
author_id = author_response['results'][0]['id'].split('/')[-1]
# Step 2: Get works
works = client.search_works(
filter_params={"authorships.author.id": author_id}
)
3. 查找来自机构的作品
用于:分析大学或组织的研究成果
from scripts.query_helpers import find_institution_works
works = find_institution_works(
institution_name="Stanford University",
client=client,
limit=200
)
4. 高被引论文
用于:查找某一领域内有影响力的论文
from scripts.query_helpers import find_highly_cited_recent_papers
papers = find_highly_cited_recent_papers(
topic="quantum computing",
years=">2020",
client=client,
limit=100
)
5. 开放获取论文
用于:查找可免费获取的研究
from scripts.query_helpers import get_open_access_papers
papers = get_open_access_papers(
search_term="climate change",
client=client,
oa_status="any", # or "gold", "green", "hybrid", "bronze"
limit=200
)
6. 出版趋势分析
用于:追踪一段时间内的研究成果
from scripts.query_helpers import get_publication_trends
trends = get_publication_trends(
search_term="artificial intelligence",
filter_params={"is_oa": "true"},
client=client
)
# Sort and display
for trend in sorted(trends, key=lambda x: x['key'])[-10:]:
print(f"{trend['key']}: {trend['count']} publications")
7. 研究成果分析
用于:对作者或机构的研究进行全面分析
from scripts.query_helpers import analyze_research_output
analysis = analyze_research_output(
entity_type='institution', # or 'author'
entity_name='MIT',
client=client,
years='>2020'
)
print(f"Total works: {analysis['total_works']}")
print(f"Open access: {analysis['open_access_percentage']}%")
print(f"Top topics: {analysis['top_topics'][:5]}")
8. 批量查询
用于:高效获取多个 DOI、ORCID 或 ID 的信息
dois = [
"https://doi.org/10.1038/s41586-021-03819-2",
"https://doi.org/10.1126/science.abc1234",
# ... up to 50 DOIs
]
works = client.batch_lookup(
entity_type='works',
ids=dois,
id_field='doi'
)
9. 随机抽样
用于:获取具有代表性的样本以进行分析
# Small sample
works = client.sample_works(
sample_size=100,
seed=42, # For reproducibility
filter_params={"publication_year": "2023"}
)
# Large sample (>10k) - automatically handles multiple requests
works = client.sample_works(
sample_size=25000,
seed=42,
filter_params={"is_oa": "true"}
)
10. 引用分析
用于:查找引用了特定作品的论文
# Get the work
work = client.get_entity('works', 'https://doi.org/10.1038/s41586-021-03819-2')
# Get citing papers using cited_by_api_url
import requests
citing_response = requests.get(
work['cited_by_api_url'],
params={'mailto': client.email, 'per-page': 200}
)
citing_works = citing_response.json()['results']
11. 主题与学科分析
用于:了解研究重点领域
# Get top topics for an institution
topics = client.group_by(
entity_type='works',
group_field='topics.id',
filter_params={
"authorships.institutions.id": "I136199984", # MIT
"publication_year": ">2020"
}
)
for topic in topics[:10]:
print(f"{topic['key_display_name']}: {topic['count']} works")
12. 大规模数据提取
用于:下载大型数据集以进行分析
# Paginate through all results
all_papers = client.paginate_all(
endpoint='/works',
params={
'search': 'synthetic biology',
'filter': 'publication_year:2020-2024'
},
max_results=10000
)
# Export to CSV
import csv
with open('papers.csv', 'w', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
writer.writerow(['Title', 'Year', 'Citations', 'DOI', 'OA Status'])
for paper in all_papers:
writer.writerow([
paper.get('title', 'N/A'),
paper.get('publication_year', 'N/A'),
paper.get('cited_by_count', 0),
paper.get('doi', 'N/A'),
paper.get('open_access', {}).get('oa_status', 'closed')
])
关键最佳实践
始终使用电子邮件以使用礼貌池
添加电子邮件以获得 10 倍的速率限制(1 req/sec → 10 req/sec):
client = OpenAlexClient(email="[email protected]")
实体查询使用两步模式
切勿直接按实体名称过滤 - 始终先获取 ID:
# ✅ Correct
# 1. Search for entity → get ID
# 2. Filter by ID
# ❌ Wrong
# filter=author_name:Einstein # This doesn't work!
使用最大分页大小
始终使用 per-page=200 以高效检索数据:
results = client.search_works(search="topic", per_page=200)
批量处理多个 ID
对多个 ID 使用 batch_lookup(),而不是逐个请求:
# ✅ Correct - 1 request for 50 DOIs
works = client.batch_lookup('works', doi_list, 'doi')
# ❌ Wrong - 50 separate requests
for doi in doi_list:
work = client.get_entity('works', doi)
使用 Sample 参数获取随机数据
使用带 seed 的 sample_works() 进行可复现的随机抽样:
# ✅ Correct
works = client.sample_works(sample_size=100, seed=42)
# ❌ Wrong - random page numbers bias results
# Using random page numbers doesn't give true random sample
仅选择所需字段
通过选择特定字段来减小响应大小:
results = client.search_works(
search="topic",
select=['id', 'title', 'publication_year', 'cited_by_count']
)
常见过滤模式
日期范围
# Single year
filter_params={"publication_year": "2023"}
# After year
filter_params={"publication_year": ">2020"}
# Range
filter_params={"publication_year": "2020-2024"}
多个过滤器(AND)
# All conditions must match
filter_params={
"publication_year": ">2020",
"is_oa": "true",
"cited_by_count": ">100"
}
多个值(OR)
# Any institution matches
filter_params={
"authorships.institutions.id": "I136199984|I27837315" # MIT or Harvard
}
合作(属性内 AND)
# Papers with authors from BOTH institutions
filter_params={
"authorships.institutions.id": "I136199984+I27837315" # MIT AND Harvard
}
取反
# Exclude type
filter_params={
"type": "!paratext"
}
实体类型
OpenAlex 提供以下实体类型:
- works - 学术文档(文章、书籍、数据集)
- authors - 已消歧身份的研究者
- institutions - 大学和研究组织
- sources - 期刊、存储库、会议
- topics - 学科分类
- publishers - 出版组织
- funders - 资助机构
使用一致的模式访问任意实体类型:
client.search_works(...)
client.get_entity('authors', author_id)
client.group_by('works', 'topics.id', filter_params={...})
外部 ID
直接使用外部标识符:
# DOI for works
work = client.get_entity('works', 'https://doi.org/10.7717/peerj.4375')
# ORCID for authors
author = client.get_entity('authors', 'https://orcid.org/0000-0003-1613-5981')
# ROR for institutions
institution = client.get_entity('institutions', 'https://ror.org/02y3ad647')
# ISSN for sources
source = client.get_entity('sources', 'issn:0028-0836')
参考文档
详细 API 参考
参见 references/api_guide.md 了解:
- 完整的过滤语法
- 所有可用端点
- 响应结构
- 错误处理
- 性能优化
- 速率限制详情
常见查询示例
参见 references/common_queries.md 了解:
- 完整可运行示例
- 真实用例
- 复杂查询模式
- 数据导出工作流
- 多步分析流程
脚本
openalex_client.py
主 API 客户端,具有:
- 自动速率限制
- 指数退避重试逻辑
- 分页支持
- 批量操作
- 错误处理
用于直接 API 访问并可完全控制。
query_helpers.py
用于常见操作的高级辅助函数:
find_author_works()- 按作者获取论文find_institution_works()- 获取机构的论文find_highly_cited_recent_papers()- 获取有影响力的论文get_open_access_papers()- 查找 OA 出版物get_publication_trends()- 分析随时间变化的趋势analyze_research_output()- 综合分析
用于常见的研究查询,提供简化的接口。
故障排查
限流
如果遇到 403 错误:
- 确保在请求中添加了邮箱
- 确认未超过 10 请求/秒
- 客户端会自动实现指数退避
结果为空
如果搜索没有返回结果:
- 检查过滤语法(参见
references/api_guide.md) - 对实体查询使用两步模式(不要按名称过滤)
- 确认实体 ID 格式正确
超时错误
对于大型查询:
- 使用分页,设置
per-page=200 - 使用
select=限制返回字段 - 如有需要,拆分为更小的查询
速率限制
- 默认:1 请求/秒,100k 请求/天
- 礼貌池(带邮箱):10 请求/秒,100k 请求/天
在生产工作流中,请始终通过向客户端提供邮箱来使用礼貌池。
注意事项
- 无需身份验证
- 所有数据开放且免费
- 速率限制全局适用,而非按 IP
- 如果需要基于大模型的分析,请结合 OpenRouter 使用 LitLLM(不要直接使用 Perplexity API)
- 客户端会自动处理分页、重试和限流