A Python package to fetch research papers from PubMed based on user-defined queries
Project description
PubMed Fetcher
A Python package to fetch research papers from PubMed based on user-defined queries, specifically targeting papers affiliated with pharmaceutical or biotech companies.
Features
- Search PubMed using custom queries
- Filter papers by non-academic affiliations
- Extract company names from author affiliations
- Save results in CSV format with detailed information
- Command-line interface for easy usage
Installation
From PyPI
pip install pubmed-fetcher
From Test-PyPI (for testing)
pip install --index-url https://test.pypi.org/simple/ pubmed-fetcher
From Source
git clone https://github.com/yourusername/pubmed-fetcher.git
cd pubmed-fetcher
poetry install
Usage
Command Line
get-papers-list "your search query" --email your.email@example.com --file output.csv
Command Line Arguments
query: Search query for PubMed--email: Your email address (required by NCBI)--file: Output CSV file path (default: pubmed_results.csv)--max-results: Maximum number of results to return (default: 100)--debug: Enable debug mode for verbose output
Python API
from pubmed_fetcher import PubMedFetcher
# Initialize the fetcher
fetcher = PubMedFetcher(email="your.email@example.com")
# Search for papers
papers = fetcher.search(query="cancer AND immunotherapy", max_results=10)
# Filter papers by company affiliation
filtered_papers = fetcher.filter_by_company_affiliation(papers)
# Convert to DataFrame
df = fetcher.to_dataframe(filtered_papers)
# Save to CSV
df.to_csv("results.csv", index=False)
Examples
The package includes example scripts demonstrating various use cases:
# Run all examples
python examples/run_examples.py --email your.email@example.com
# Run a specific example
python examples/basic_usage.py
python examples/advanced_filtering.py
See the examples directory for more information.
Output Format
The program generates a CSV file with the following columns:
- PubmedID: Unique identifier for the paper
- Title: Title of the paper
- Publication Date: Date the paper was published
- Non-academic Author(s): Names of authors affiliated with non-academic institutions
- Company Affiliation(s): Names of pharmaceutical/biotech companies
- Corresponding Author Email: Email address of the corresponding author
Code Organization
The package is organized as follows:
pubmed_fetcher/: Main package directory__init__.py: Package initializationpubmed_fetcher.py: Core functionality (module)main.py: Command-line interface
tests/: Test directorytest_main.py: Tests for the module
examples/: Example scriptsbasic_usage.py: Basic usage exampleadvanced_filtering.py: Advanced filtering examplerun_examples.py: Script to run all examples
pyproject.toml: Poetry configurationsetup.py: Setuptools configuration (for compatibility)requirements.txt: Development dependencies
Development
- Clone the repository:
git clone https://github.com/yourusername/pubmed-fetcher.git
cd pubmed-fetcher
- Install development dependencies:
poetry install
- Run tests:
poetry run pytest
- Format code:
poetry run black pubmed_fetcher tests
poetry run isort pubmed_fetcher tests
- Run linters:
poetry run flake8 pubmed_fetcher tests
poetry run mypy pubmed_fetcher
- Check publication readiness:
python check_publication_readiness.py
Publishing
To PyPI
- Create a PyPI account at https://pypi.org/
- Configure Poetry with your PyPI credentials:
poetry config pypi-token.pypi your-token-here
- Run the publish script:
On Linux/macOS:
chmod +x publish_to_pypi.sh
./publish_to_pypi.sh
On Windows:
publish_to_pypi.bat
To Test-PyPI
- Create a Test-PyPI account at https://test.pypi.org/
- Configure Poetry to use Test-PyPI:
poetry config repositories.testpypi https://test.pypi.org/legacy/
- Run the publish script:
On Linux/macOS:
chmod +x publish_to_testpypi.sh
./publish_to_testpypi.sh
On Windows:
publish_to_testpypi.bat
Tools and Libraries Used
Development Tools
- Python 3.11
- Git for version control
- GitHub for repository hosting
- Poetry for dependency management
- Claude 3.5 Sonnet for code assistance and development
Python Libraries
- Biopython - For PubMed data retrieval
- Click - For command-line interface
- Pandas - For data manipulation and CSV handling
- Requests - For HTTP requests
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pharma_pubmed_fetcher-0.1.0.tar.gz.
File metadata
- Download URL: pharma_pubmed_fetcher-0.1.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.11.9 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fda848adae447c3ffd381e1cd89057075f1c81c545eb849f9ed5f835ccbdca0
|
|
| MD5 |
69d116f2294761b270f5e01d47504a66
|
|
| BLAKE2b-256 |
9f899a244433fa95b31857c522f1c2fb949b5e4dfcb88f813d626f5791db9621
|
File details
Details for the file pharma_pubmed_fetcher-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pharma_pubmed_fetcher-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.11.9 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98af38484daae6d1a666704f5c512e13adddd39f6f85c14ea0f7ef385ef684cc
|
|
| MD5 |
7c6b06160676da7fa0067569633ba1ce
|
|
| BLAKE2b-256 |
0d382fa457dcc858f8a82da8075e65709a314905559c10ac1d08dbf8c4dabffa
|