PyMed is a Python library that provides access to PubMed.

Overview

IMPORTANT NOTE: I don't have time to maintain this library (as some of you might have noticed). The PubMed API is a little chaotic, without a clear documentation and no single way of doing things, making it almost impossible to create a proper library. Feel free to create a fork or use the code for your own projects, however, I will archive this repository. Thanks to all contributers and users!

PyMed - PubMed Access through Python

PyMed is a Python library that provides access to PubMed through the PubMed API.

Why this library?

The PubMed API is not very well documented and querying it in a performant way is too complicated and time consuming for researchers. This wrapper provides access to the API in a consistent, readable and performant way.

Features

This library takes care of the following for you:

  • Querying the PubMed database (with the standard PubMed query language)
  • Batching of requests for better performance
  • Parsing and cleaning of the retrieved articles

Examples

For full (working) examples have a look at the examples/ folder in this repository. In essence you only need to import the PubMed class, instantiate it, and use it to query:

from pymed import PubMed
pubmed = PubMed(tool="MyTool", email="[email protected]")
results = pubmed.query("Some query", max_results=500)

Notes on the API

The original documentation of the PubMed API can be found here: PubMed Central. PubMed Central kindly requests you to:

  • Do not make concurrent requests, even at off-peak times; and
  • Include two parameters that help to identify your service or application to our servers
    • tool should be the name of the application, as a string value with no internal spaces, and
    • email should be the e-mail address of the maintainer of the tool, and should be a valid e-mail address.

Notice of Non-Affiliation and Disclaimer

The author of this library is not affiliated, associated, authorized, endorsed by, or in any way officially connected with PubMed, or any of its subsidiaries or its affiliates. The official PubMed website can be found at https://www.ncbi.nlm.nih.gov/pubmed/.

Comments
  • Abstract is not downloading the information on method and Results

    Abstract is not downloading the information on method and Results

    Hi,

    Thank you for creating the library, it is very helpful. Have checked with downloaded data, it gives only the Back Ground or objective or whichever come first in Abstract. Is any possibility to get the entire Abstract(Back Ground, Objective, Methods, Results, Conclusion, Conclusion) as displayed when we search in the website.

    happy to help you, if I can do something.

    opened by muralidhar972 10
  • Paginate \ count result

    Paginate \ count result

    Hi, Is there a way to get count of the relevant results with respect to the query and \ or to paginate the results. E.g. read the first 500, then 500-1000, etc.?

    opened by tomron 5
  • api.py is broken

    api.py is broken

    Describe the bug

    When importing pymed I get the following error:

    $ python3 
    Python 3.5.3 (default, Sep 27 2018, 17:25:39)  
    [GCC 6.3.0 20170516] on linux 
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from pymed import PubMed 
    Traceback (most recent call last): 
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.5/dist-packages/pymed/__init__.py", line 1, in <module> 
        from .api import PubMed
      File "/usr/local/lib/python3.5/dist-packages/pymed/api.py", line 118
        response = requests.get(f"{BASE_URL}{url}", params=parameters)
                                                 ^ 
    SyntaxError: invalid syntax
    >>> import pymed 
    Traceback (most recent call last): 
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.5/dist-packages/pymed/__init__.py", line 1, in <module>
        from .api import PubMed
      File "/usr/local/lib/python3.5/dist-packages/pymed/api.py", line 118
        response = requests.get(f"{BASE_URL}{url}", params=parameters)
                                                 ^
    SyntaxError: invalid syntax `
    
    

    To Reproduce Just try to import it in the interpreter.

    Environment (please complete the following information):

    • OS: Same error in WSL Ubuntu and Debian 9
    • Version: Python 3.5.3
    opened by fluoridepsychosis 2
  • Access to Affiliation in XML data

    Access to Affiliation in XML data

    Is your feature request related to a problem? Please describe. It's important to me to see the affiliation information associated with an author if applicable. I can't see where this is being extracted from the returned XML.

    Describe the solution you'd like Ideally, this would be an additional return in the form of .affiliation.

    Describe alternatives you've considered

    I created a "hack" by editing article.py def _extractAuthors(self: object, xml_element: TypeVar("Element")) -> list: return [ { "lastname": getContent(author, ".//LastName", None), "firstname": getContent(author, ".//ForeName", None), "initials": getContent(author, ".//Initials", None), "affiliation": getContent(author, ".//AffiliationInfo/Affiliation", None), } for author in xml_element.findall(".//Author") ]

    opened by yuanchueh 1
  • changed method to methods and added args

    changed method to methods and added args

    All Submissions:

    • [ ] Have you followed the guidelines in our Contributing document?
    • [ ] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

    New Feature Submissions:

    1. [ ] Does your submission pass tests (if applicable)?
    2. [ ] Have you lint your code locally prior to submission (use flake8)?

    Changes to Core Features:

    • [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
    • [ ] Have you written new tests for your core changes, as applicable?
    • [ ] Have you successfully ran tests with your changes locally?
    opened by esteininger 1
  • added additional support

    added additional support

    added support for conclusion, method and results fields within the AbstractText field via _attemptGrab function.

    All Submissions:

    • [x] Have you followed the guidelines in our Contributing document?
    • [x] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

    New Feature Submissions:

    1. [x] Does your submission pass tests (if applicable)?
    2. [ ] Have you lint your code locally prior to submission (use flake8)?

    Changes to Core Features:

    • [x] Have you added an explanation of what your changes do and why you'd like us to include them?
    • [x] Have you written new tests for your core changes, as applicable?
    • [x] Have you successfully ran tests with your changes locally?
    opened by esteininger 1
  • Feature/enforce rate limit

    Feature/enforce rate limit

    All Submissions:

    • [ ] Have you followed the guidelines in our Contributing document?
    • [ ] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

    New Feature Submissions:

    1. [ ] Does your submission pass tests (if applicable)?
    2. [ ] Have you lint your code locally prior to submission (use flake8)?

    Changes to Core Features:

    • [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
    • [ ] Have you written new tests for your core changes, as applicable?
    • [ ] Have you successfully ran tests with your changes locally?
    opened by gijswobben 0
  • Feature/enforce rate limit

    Feature/enforce rate limit

    All Submissions:

    • [ ] Have you followed the guidelines in our Contributing document?
    • [ ] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

    New Feature Submissions:

    1. [ ] Does your submission pass tests (if applicable)?
    2. [ ] Have you lint your code locally prior to submission (use flake8)?

    Changes to Core Features:

    • [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
    • [ ] Have you written new tests for your core changes, as applicable?
    • [ ] Have you successfully ran tests with your changes locally?
    opened by gijswobben 0
  • Update the examples bugs

    Update the examples bugs

    fix article_id to be pulled from the new pubmed_id method

    All Submissions:

    • [x] Have you followed the guidelines in our Contributing document?
    • [x] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

    New Feature Submissions:

    1. [x] Does your submission pass tests (if applicable)?
    2. [x] Have you lint your code locally prior to submission (use flake8)?

    Changes to Core Features:

    • [x] Have you added an explanation of what your changes do and why you'd like us to include them?
    • [ ] Have you written new tests for your core changes, as applicable?
    • [x] Have you successfully ran tests with your changes locally?
    opened by Darkbladecr 0
  • Save article xml as attribute to allow for processing after the fact

    Save article xml as attribute to allow for processing after the fact

    I've found that I often need to get additional data from an article. For this it would be helpful to have access to the original xml.

    All Submissions:

    • [x] Have you followed the guidelines in our Contributing document?
    • [x] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

    New Feature Submissions:

    1. [ ] Does your submission pass tests (if applicable)? not applicable
    2. [x] Have you lint your code locally prior to submission (use flake8)?

    Changes to Core Features:

    • [x] Have you added an explanation of what your changes do and why you'd like us to include them?
    • [ ] Have you written new tests for your core changes, as applicable? not applicable
    • [ ] Have you successfully ran tests with your changes locally? not applicable
    opened by radusuciu 0
  • Added affiliations to the authors of articles

    Added affiliations to the authors of articles

    All Submissions:

    • [x] Have you followed the guidelines in our Contributing document?
    • [x] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

    New Feature Submissions:

    1. [x] Does your submission pass tests (if applicable)?
    2. [x] Have you lint your code locally prior to submission (use flake8)?

    Changes to Core Features:

    • [x] Have you added an explanation of what your changes do and why you'd like us to include them?
    • [x] Have you written new tests for your core changes, as applicable?
    • [x] Have you successfully ran tests with your changes locally?
    opened by gijswobben 0
  • Pubmed API filter endpoints

    Pubmed API filter endpoints

    Is your feature request related to a problem? Please describe. Could you please add some filter features with Pubmed API

    Additional context I'm facing problems passing filter queries to the API.

    opened by sjtly16 0
  • Pagination on response

    Pagination on response

    Hi Gjis,

    I am using pymed package in one of my project. Everything is going well but some queries gives lots of articles. I want to give response in pagination, I have tried #1 but it takes lots of time. Can you help me out for solution.

    Thank you

    opened by hemantbadhe 0
  • BugFix/pmid-parsing

    BugFix/pmid-parsing

    This will fix the PMID parsing issue in articles for which currently multiple PMID's are getting parsed. Resolves issue #22

    All Submissions:

    • [x] Have you followed the guidelines in our Contributing document?
    • [ ] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

    New Feature Submissions:

    1. [x] Does your submission pass tests (if applicable)?
    2. [x] Have you lint your code locally prior to submission (use flake8)?

    Changes to Core Features:

    • [x] Have you added an explanation of what your changes do and why you'd like us to include them?
    • [ ] Have you written new tests for your core changes, as applicable?
    • [x] Have you successfully ran tests with your changes locally?
    opened by ritvikvipra 1
  • Bugfix/article ID parsing issue

    Bugfix/article ID parsing issue

    Thanks for the useful and well written library!

    This minimal fix make the parser returning only the paper pubmed id. Before, also the ids of the citations papers were returned.(they are within the ReferenceList element of the xml).

    Fixes #22

    An alternative XPath to be used: path = ".//PubmedData/ArticleIdList/ArticleId[@IdType='pubmed']"

    All Submissions:

    • [x] Have you followed the guidelines in our Contributing document?
    • [x] Have you checked to ensure there aren't other open Pull Requests for the same update/change?

    New Feature Submissions:

    1. [ ] Does your submission pass tests (if applicable)?
    2. [x] Have you lint your code locally prior to submission (use flake8)?

    Changes to Core Features:

    • [x] Have you added an explanation of what your changes do and why you'd like us to include them?
    • [ ] Have you written new tests for your core changes, as applicable?
    • [ ] Have you successfully ran tests with your changes locally?
    opened by iacopy 0
  • Could you please add support for API key?

    Could you please add support for API key?

    Is your feature request related to a problem? Please describe. Currently one cannot enter the PubMed API key, so one cannot increase the rate limit to 10calls/sec

    Describe the solution you'd like It would be great to add another param to the PubMed object.

    Describe alternatives you've considered Writing my own code to handle the API :)

    Additional context See here for info about the API key

    THANKS!

    opened by rgranit 1
  • Is there a way to fetch Mesh terms?

    Is there a way to fetch Mesh terms?

    Is there a way to fetch MESH terms of a publication from the API using the packadge?

    This information is found under 'MeshHeadingList' of the xml returned using efetch.

    opened by rgranit 1
Owner
Gijs Wobben
Gijs Wobben
A minimalistic library designed to provide native access to YNAB data from Python

pYNAB A minimalistic library designed to provide native access to YNAB data from Python. Install The simplest way is to install the latest version fro

Ivan Smirnov 92 Apr 6, 2022
A Python library to access Instagram's private API.

Instagram Private API A Python wrapper for the Instagram private API with no 3rd party dependencies. Supports both the app and web APIs. Overview I wr

null 2.6k Jan 5, 2023
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
Unofficial instagram API, give you access to ALL instagram features (like, follow, upload photo and video and etc)! Write on python.

Instagram-API-python Unofficial Instagram API to give you access to ALL Instagram features (like, follow, upload photo and video, etc)! Written in Pyt

Vladimir Bezrukov 1 Nov 19, 2021
Python version of PlaceNL's headless bot with automatic access token refresh

Reddit /r/place 2022 headless bot This headless Python bot will automatically login to reddit, obtain access tokens (and refreshes them when they expi

null 19 May 21, 2022
An API Client package to access the APIs for NBA.com

nba_api An API Client package to access the APIs for NBA.com Development Version: v1.1.9 nba_api is an API Client for www.nba.com. This package is mea

Swar Patel 1.4k Jan 1, 2023
Validate all your Customer IAM Policies against AWS Access Analyzer - Policy Validation

✅ Access Analyzer - Batch Policy Validator This script will analyze using AWS Access Analyzer - Policy Validation all your account customer managed IA

Victor GRENU 41 Dec 12, 2022
SSH-Restricted deploys an SSH compliance rule (AWS Config) with auto-remediation via AWS Lambda if SSH access is public.

SSH-Restricted SSH-Restricted deploys an SSH compliance rule with auto-remediation via AWS Lambda if SSH access is public. SSH-Auto-Restricted checks

Adrian Hornsby 30 Nov 8, 2022
Telegram Bot to store Posts and Documents and it can Access by Special Links.

File-sharing-Bot Telegram Bot to store Posts and Documents and it can Access by Special Links. I Guess This Will Be Usefull For Many People..... ?? .

Code X Botz 1.2k Jan 8, 2023
Automation for grabbing keys from a Linux host. Useful during red team exercises to quickly help assess what access to a Linux host can lead to.

keygrabber Automation for grabbing keys from a Linux host. This can be helpful during red team exercises when you gain access to a Linux host and want

Cedric Owens 14 Sep 27, 2022
Role Based Access Control for Slack-Bolt Applications

Role Based Access Control for Slack-Bolt Apps Role Based Access Control (RBAC) is a term applied to limiting the authorization for a specific operatio

Jeremy Schulman 7 Jan 6, 2022
The Research PACS on AWS solution facilitates researchers' access medical images stored in the clinical PACS in a secure and seamless manner

Research PACS on AWS Challenge to solve Solution presentation Deploy the solution Further reading Releases License Challenge to solve The rise of new

AWS Samples 23 Sep 9, 2022
Repository to access information of stocks in Bombay Stock Exchange.

BSE Repository to access information of stocks in Bombay Stock Exchange. The code in this repository uses BSE API and conclusions made using the code

null 1 Nov 13, 2021
Access LeetCode problems via id

LCid - access LeetCode problems via id Introduction As a world's leading online programming learning platform, LeetCode is quite popular among program

bunnyxt 14 Oct 8, 2022
Basic query to access Traindex API

traindex-api-query Basic query to access Traindex API Please make sure to provide your Traindex API key to the line 8 in the script file. There are tw

Foretheta 1 Nov 11, 2021
This bot automaticaly access to giveaway ! You can won free NFT !

This bot automaticaly access to giveaway ! You can won free NFT !

2s.py 28 Oct 20, 2022
File-sharing-Bot: Telegram Bot to store Posts and Documents and it can Access by Special Links.

File-sharing-Bot Telegram Bot to store Posts and Documents and it can Access by Special Links. I Guess This Will Be Usefull For Many People..... ?? .

null 1 Dec 17, 2021
A wrapper for The Movie Database API v3 and v4 that only uses the read access token (not api key).

fulltmdb A wrapper for The Movie Database API v3 and v4 that only uses the read access token (not api key). Installation Use the package manager pip t

Jacob Hale 2 Sep 26, 2021