Introduction
In academic research, managing references is an important but time-consuming task. Especially when writing a paper, we often need to retrieve citation formats from different databases. To solve this problem, I developed get-bibtex, a Python library that helps researchers quickly retrieve BibTeX citations from multiple academic databases.
Why Choose get-bibtex?
1. Support for Multiple Sources
- CrossRef (the most comprehensive DOI database)
- DBLP (a computer science literature database)
- Google Scholar (requires an API key)
2. Smart Workflow
3. Simple and Easy to Use
4. Batch File Processing
# 从文件读取并保存
workflow.process_file(
input_path="papers.txt",
output_path="references.bib"
)
Key Features
Smart Fallback Mechanism
- Automatically tries other data sources when one fails
- Maximizes the amount of citation information retrieved
Progress Tracking
- Uses tqdm to display processing progress
- Gives you a clear view of batch processing status
Error Handling
- Detailed logging
- Gracefully handles API limits and network errors
Formatted Output
- Automatically cleans up and formats BibTeX
- Ensures consistent output formatting
Use Cases
Paper Writing
When you're writing a paper, you can retrieve citations directly by DOI or title:
Literature Reviews
Process large batches of references:
Retrieving Citations for Papers on Attention Mechanisms
Suppose we need citations for the following papers:
- FedMSA: A Model Selection and Adaptation System for Federated Learning
- Attention Is All You Need: The pioneering work on Transformers
- Non-Local Neural Networks: Non-local neural networks
- ECA-Net: An efficient channel attention mechanism
- CBAM: Convolutional Block Attention Module
Using CrossRef (by DOI)
Output example:
Using DBLP (by title)
from apiModels import DBLPBibTeX
fetcher = DBLPBibTeX()
# CBAM
bibtex = fetcher.get_bibtex("CBAM: Convolutional Block Attention Module")
print(bibtex)
Output example:
Using a Workflow to Retrieve Multiple Citations
Batch File Processing
You can create a workflow to process a file containing multiple citations. First, create the workflow and add data sources:
Input example: papers.txt
Output example: references.bib
Installation
Using pip:
pip install get-bibtex
Using Poetry:
poetry add get-bibtex
Best Practices
Register with an email address
Pythonfetcher = CrossRefBibTeX(email="your.email@example.com")This gives you higher priority when accessing the API.
Use Workflows Sensibly
Pythonworkflow = WorkflowBuilder() workflow.add_fetcher(CrossRefBibTeX()) # 主要源 workflow.add_fetcher(DBLPBibTeX()) # 备用源Add data sources in order of reliability.
Add Delays for Batch Processing When processing large numbers of citations, use the built-in delay mechanism to avoid triggering API limits.
Get a SerpAPI Key
To use the Google Scholar feature, you need a SerpAPI key. Here are the steps:
Sign up for a SerpAPI account
- Visit the SerpAPI website
- Click the "Sign Up" button in the top-right corner
- Fill in your registration details (email, password, etc.)
Choose the Right Plan
- Free plan: 100 searches per month
- Paid plans: Choose different tiers based on your needs
- For testing and personal use, the free plan is usually sufficient
Get Your API Key
- After signing in, go to the Dashboard
- Find your key in the "API Key" section
- Copy the key for use in your code
Usage Example
CodeBlock Loading...Things to Note
- Protect your API key and don't share it publicly
- Monitor usage to avoid exceeding the limits
- Set reasonable intervals between requests (at least one second is recommended)
- Use environment variables to store your API key in production environments ```python import os
apikey = os.getenv("SERPAPIKEY") fetcher = GoogleScholarBibTeX(apikey=apikey)
Recommendations
- Try CrossRef and DBLP first
- Use Google Scholar only when no results are found
- Keep API usage limits in mind during batch processing
python # 推荐的工作流顺序 workflow = WorkflowBuilder() workflow.add_fetcher(CrossRefBibTeX(email="your.email@example.com")) workflow.add_fetcher(DBLPBibTeX()) workflow.add_fetcher(GoogleScholarBibTeX(api_key="your-serpapi-key"))
Future Outlook
- Support more data sources
- Add citation format conversion
- Provide a graphical user interface
- Offer more customization options
Conclusion
get-bibtex is designed to simplify reference management in academic writing. Whether you're working on a single paper or conducting a literature review, it can help you retrieve and manage citations efficiently. Feel free to contribute to the project on GitHub, share suggestions, or report issues.
Related Links
- GitHub repository: get-bibtex
- Report issues: Issues
- PyPI page: get-bibtex