Python interface for Canadian drug shortages

This post is a part of a series on drug shortages.

I’ve built a python package for using the Drug Shortages Canada database web API. It’s called pydrugshortagesca and you can read more about it on the project github page, and install it like so:

pip install pydrugshortagesca

It is an extremely small wrapper around the web API but provides a few useful additions. Firstly, there is a convenience function for iterating over all search results without having to handle making separate requests yourself, e.g:

from pydrugshortagesca import api
...
for record in session.isearch(term="venlafaxine"):
    ... do stuffCode language: JavaScript (javascript)

Secondly, I’ve made it easy to export search results as flat files such as CSV, e.g:

from pydrugshortages import export
...
export.as_csv(session, open('shortages.csv', 'w'), term='venlafaxine')Code language: JavaScript (javascript)

Lastly, there is a command line tool for interacting with the database, and exporting results. For instance, to export the same search as above, you would run:

$ pydrugshortages -p term venlafaxine --fmt csv > shortages.csv

Enjoy!

1 Comment

Comments are closed.