Skip to main content

Minimal Python wrapper for the database API

Project description


A minimal python wrapper around the database API

Depends on requests module and will pass through exceptions from that library when they occur.


Install the package:

pip install pydrugshortagesca

You can then configure your username and password in one of the following ways:

Create configuration file in ~/.config/pydrugshortagesca/config:


Or, set the following environment variables:

export DSC_EMAIL=""
export DSC_PASSWORD="s3cr3t!"

You can test your installation by running the command pydrugshortagesca. You should not be prompted for a username or password, and it should return some results in JSON format.

Basic Usage

Interacting with the database is done via the api.Session object:

from pydrugshortagesca import api, export
import json

session = api.Session(email="", password="123456")

except Exception as e:
    print("Error with log in", e)
    print("Details:", session.response.content)
    # search() returns a batch of results.
    # Use the `limit` and `offset` parameters to adjust which batch to return.
    json_results ="venlafaxine", offset=20)
    print("Total results {}".format(json_results['total']))

    # isearch() returns an iterator over all records returned by a search.
    # This may make several requests to the database if needed.
    results = session.isearch(term="venlafaxine", orderby='updated_date')
    for rec in results:

    # Custom filter functions can also be supplied
    results = session.isearch(_filter=lambda x: x['drug_strength'] == '150.0MG',
        term="venlafaxine", orderby='updated_date'):
    for rec in results:
    # The export module provides utility functions for exporting results in tabular form
    csvfile = open('shortages.csv','w')
    export.as_csv(session, csvfile, shortages=True, term="venlafaxine")


There is also a commandline interface. See pydrugshortagesca --help for details, but briefly:

$ pydrugshortagesca -p term venlafaxine --type shortages --fmt csv > shortages.csv




Pull requests are very welcome!

Project details

Download files

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

Files for pydrugshortagesca, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size pydrugshortagesca-0.1.3-py3-none-any.whl (8.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pydrugshortagesca-0.1.3.tar.gz (6.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page