paperscraper

repository·main·Indexed 19 days ago

https://github.com/jannisborn/paperscraper

A Python package for scraping publication metadata and full-text files (PDF/XML) from PubMed, arXiv, and preprint servers including bioRxiv, medRxiv, and chemRxiv. It features tools for bibliometric analysis, citation counts, journal impact factor queries, and author metrics via Semantic Scholar. The library supports complex Boolean search queries using nested lists and provides utilities for downloading local metadata dumps, performing keyword analysis, and plotting temporal research trends.

Tokens
13.5K
Snippets
45
Records
57
Agent score
67%

What's inside paperscraper

  1. Overview of paperscraper capabilities

    main

    paperscraper

    paperscraper is a Python package designed for reproducible literature search, publication metadata retrieval, and citation analysis. It provides a unified interface to search across multiple sources including PubMed, arXiv, bioRxiv, medRxiv, and ChemRxiv.

    Key Features:

    • Multi-source Search: Express a single Boolean keyword query to run across PubMed and various preprint servers.
    • Local-first Paradigm: Minimizes API dependency by allowing users to create and query local JSONL snapshots of metadata.
    • Metadata Normalization: Results are returned as normalized tabular records (title, authors, date, abstract, journal, DOI) in JSONL format.
    • Full-text Retrieval: Best-effort retrieval of accessible PDF or XML full texts via DOI.
    • Bibliometrics: Tools for analyzing scholar metrics (citation counts, h-index) and self-citation/self-reference patterns.
    • Trend Analysis: Utilities for keyword-based research trend analysis and plotting.
  2. Explore the paperscraper API modules

    main

    The paperscraper library provides a modular API for scraping scientific literature and analyzing citations. The main entry points are organized by source and functionality:

    • paperscraper: The main package entry point.
    • paperscraper.arxiv: Tools for ArXiv scraping and keyword-based searches.
    • paperscraper.citations: Functions to retrieve (self-)citations and (self-)references for both specific papers and authors.
    • paperscraper.get_dumps: Utilities for downloading metadata dumps from bioRxiv, medRxiv, and chemRxiv.
    • paperscraper.pdf: Functionality to download publications as PDF files.
    • paperscraper.pubmed: Tools for keyword searches on PubMed.
    • paperscraper.scholar: Endpoints for interacting with Google Scholar.
    • paperscraper.xrxiv: Shared utilities specifically for the {bio, med, chem}Rxiv ecosystem.
  3. Explore paperscraper top-level utility modules

    main

    The paperscraper package provides several top-level utility modules for different stages of the research paper analysis pipeline. These modules are accessible directly under the paperscraper namespace.

    Available modules include:

    • async_utils: Asynchronous utility functions.
    • impact: Tools for calculating or analyzing research impact.
    • load_dumps: Functions for loading data dumps.
    • plotting: Visualization and plotting utilities.
    • postprocessing: Tools for cleaning or transforming scraped data.
    • server_dumps: Utilities related to server-side data dumps.
    • utils: General purpose helper functions.
  4. Analyze scholar metrics and self-citations

    main

    paperscraper provides utilities to move beyond simple citation counts to more nuanced bibliometric analysis.

    Scholar Metrics:

    • Paper level: Uses Semantic Scholar to retrieve citation counts.
    • Author level: Uses Semantic Scholar to retrieve publication counts, citation counts, and h-index values.
    • Journal level: Uses a fuzzy-search wrapper around the impact-factor package to find journal metrics.

    Self-Citation Analysis: The package distinguishes between two types of self-links to help identify metric gaming:

    • Self-citation: A citation from a later paper that shares at least one author with the cited paper.
    • Self-reference: A reference made by a paper to earlier work that shares at least one author.

    These metrics are estimated at both the paper and author levels using Semantic Scholar metadata.

  5. Construct Boolean search queries using nested lists

    main

    In paperscraper, search terms are represented as nested lists to implement Boolean logic.

    • The outer list represents the AND operator.
    • The inner lists represent synonyms using the OR operator.

    Example: [["AI", "Machine Learning"], ["Quantum"], ["Chemistry"]] translates to (AI OR "Machine Learning") AND (Quantum) AND (Chemistry).

    ai = ["Artificial intelligence", "Machine learning"]
    qc = ["Quantum computing", "Quantum algorithm"]
    chemistry = ["Chemistry", "Chemical"]
    query = [ai, qc, chemistry]
  6. How keyword search and local dumps work

    main

    The core workflow for analyzing literature trends involves searching normalized metadata using a nested Boolean keyword convention.

    Query Syntax: Queries are structured as nested keyword lists:

    • Outer level: Terms are combined using AND.
    • Inner level: Lists define synonyms combined using OR.

    Workflow for Preprint Servers (bioRxiv, medRxiv, ChemRxiv): Because these services are not redistributed by the package due to copyright, you must first create local JSONL dumps using paperscraper.get_dumps. This creates a stable snapshot for your analysis.

    Workflow for arXiv: You can either query the arXiv API directly or build a local dump from the arXiv Kaggle metadata snapshot.

    Key Components:

    • paperscraper.get_dumps: Used to download metadata for preprint servers.
    • XRXivQuery: A class that reads JSONL files and applies the keyword logic over selected metadata fields.
    • dump_queries: A helper function that runs one or more queries across all configured sources.
  7. Understand the maintenance scope of paperscraper

    main

    The project maintainers provide support for the following areas:

    • Package behavior and documented APIs.
    • Metadata parsing.
    • Retrieval fallbacks.
    • Reproducible examples.

    The following are NOT supported or guaranteed:

    • Access to paywalled content.
    • Bypassing publisher restrictions.
    • Solving Google Scholar captchas.
    • Controlling the availability of upstream APIs.
  8. Understand PDF retrieval fallbacks

    main

    If direct PDF retrieval via DOI fails, paperscraper attempts several fallback mechanisms to find full text:

    • BioC-PMC XML: For open-access papers in PubMed Central.
    • eLife XML: From the eLife article XML repository.
    • Publisher APIs: When matching credentials (e.g., Wiley, Elsevier) are provided.
    • bioRxiv S3 access: When AWS requester-pays credentials (IAM key with AmazonS3ReadOnlyAccess) are provided.

    Note: Fallbacks cannot bypass publisher paywalls or restrictions.

  9. Install paperscraper

    main

    You can install paperscraper using pip or uv to perform reproducible searches over scholarly metadata, retrieve full-text PDFs/XML, and perform bibliometric analysis across PubMed, arXiv, bioRxiv, medRxiv, and ChemRxiv.

    pip install paperscraper

    or

    uv add paperscraper
  10. Handle security and credentials safely

    main

    Never post API keys, publisher credentials, AWS credentials, or private data in public GitHub issues.

    If a report requires private credentials or describes a sensitive security issue, contact the maintainers privately via their public GitHub or package metadata profiles. Provide only the minimum information necessary for triage.

  11. Download xRxiv metadata dumps

    main

    To scrape data from bioRxiv, medRxiv, or chemRxiv, you must first download their local metadata dumps. These are stored in JSONL format (one paper per line) in the server_dumps folder. After downloading, restart your Python interpreter so paperscraper.load_dumps can discover the new files.

    Use paperscraper.utils.get_server_dumps_dir() to inspect the directory where dumps are stored.

    from paperscraper.get_dumps import biorxiv, medrxiv, chemrxiv
    
    chemrxiv()  # ~50K papers
    medrxiv()   # ~100K papers
    biorxiv()   # ~450K papers
  12. Ask usage questions and troubleshoot behavior

    main

    Questions regarding documented workflows are welcome on the public issue tracker. When asking questions, include enough context to reproduce the problem locally.

    Note on external factors: Be aware that failures may be caused by factors outside of paperscraper's control, such as:

    • External API availability or rate limits.
    • Captchas.
    • Publisher access rules and paywalls.
    • Platform terms of service.