Skip to main content

A Python package to fetch research papers from PubMed based on user-defined queries

Project description

Pharma 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.

PyPI version Python Version License: MIT

Features

  • Search PubMed using custom queries with full PubMed query syntax support
  • 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
  • Python API for programmatic access

Installation

From PyPI

pip install pharma-pubmed-fetcher

From Source

git clone https://github.com/yourusername/pharma-pubmed-fetcher.git
cd pharma-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 (supports full PubMed query syntax)
  • --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 initialization
    • pubmed_fetcher.py: Core functionality (module)
    • main.py: Command-line interface
  • tests/: Test directory
    • test_main.py: Tests for the module
  • examples/: Example scripts
    • basic_usage.py: Basic usage example
    • advanced_filtering.py: Advanced filtering example
    • run_examples.py: Script to run all examples
  • pyproject.toml: Poetry configuration
  • setup.py: Setuptools configuration (for compatibility)
  • requirements.txt: Development dependencies

Development

  1. Clone the repository:
git clone https://github.com/yourusername/pharma-pubmed-fetcher.git
cd pharma-pubmed-fetcher
  1. Install development dependencies:
poetry install
  1. Run tests:
poetry run pytest
  1. Format code:
poetry run black pubmed_fetcher tests
poetry run isort pubmed_fetcher tests
  1. Run linters:
poetry run flake8 pubmed_fetcher tests
poetry run mypy pubmed_fetcher
  1. Check publication readiness:
python check_publication_readiness.py

Publishing

To PyPI

  1. Create a PyPI account at https://pypi.org/
  2. Configure Poetry with your PyPI credentials:
poetry config pypi-token.pypi your-token-here
  1. 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

  1. Create a Test-PyPI account at https://test.pypi.org/
  2. Configure Poetry to use Test-PyPI:
poetry config repositories.testpypi https://test.pypi.org/legacy/
  1. 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.10+
  • 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pharma_pubmed_fetcher-0.1.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pharma_pubmed_fetcher-0.1.1-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file pharma_pubmed_fetcher-0.1.1.tar.gz.

File metadata

  • Download URL: pharma_pubmed_fetcher-0.1.1.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.9 Windows/10

File hashes

Hashes for pharma_pubmed_fetcher-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3ff63a5225128bda96228e6fa54741ee17da3850dc599c45d32acc5b13f1595f
MD5 aaa1818755087ef71dfdb2e377afad44
BLAKE2b-256 557d674bb2bc1cf12ec1bd400084f63770784e043954907730147b5d668152c5

See more details on using hashes here.

File details

Details for the file pharma_pubmed_fetcher-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pharma_pubmed_fetcher-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a29e4eb40cdbfc2eddffcfab6e8001584980e7e1ff49d8e238e2f3e9b4b2cf6
MD5 0a2fdac04ac7d854001682e7405757ea
BLAKE2b-256 7062dc4336dcc658249e1ebef52d79758c7e3cdea2a7d30287ad1dc32c5ef337

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page