Skip to main content

Downloads the FDA drugs database along with the NDC codes active ingredients and drug classes

Project description

pyDrugsDatabase

PyDrugsDatabase downloads the FDA drugs database so that it can be used locally. The database is also indexed allowing for obtaining drugs by generic name, active ingredients and drug classes

Tutorials

Installation

To Install PyDrugDatabase from PyPI,

pip install pydrusgdatabase

Loading the Database

To create and load the database, from the latest data, from the fda,

import pathlib
from pydrugsdatabase.drugs_load import DrugsLoad

DrugsLoad(pathlib.Path("/path/to/save/db")).load_from_fda()

This will download, extract format and save the records, plus create a series of indexes to access the records faster.

Reading the Database

import pathlib
from pydrugsdatabase.drugs_database import DrugsDatabase

drugs_db = DrugsDatabase(pathlib.Path("/path/to/db/"))

Obtaining records by Product or Package NDC

rec = drugs_db.get_by_package_ndc("4444-333")

A single TinyDB Document object is returned. This is a modified Dictionary

!!! Note Records are stored by product NDC numbers. not package. The first two sets of number represent the product NDC id, and the last is used for the exact packaging. Drug details are the same for all packages (including dose), except for the size of the package (number of doses)

Obtaining Records by Medication Class

Each Drug has multiple medication classes, representing different aspects of the given drug, such as chemical class, main usage, chemical route used etc. Some medications that have multiple active ingredients will have classes assigned for each of the active ingredients used.

recs = drugs_db.get_by_class("ssri")

A list of TinyDB Documents are returned

Obtaining Records By generic Name

recs = drugs_db.get_by_generic_name("paracetamol")

A list of TinyDB Document objects is returned

Obtaining Records By Ingredient

The database holds lists of the active ingredients in a given medication, which can be multiple, for example Adderall.

recs = drugs_db.get_by_ingredient("paracetamol")

Returns a list of TinyDB Documents

Get all Generic Names

names = drugs_db.get_all_generic_names()

returns a list of strings

get All Medication Classes

class_names = drugs_db.get_all_medication_classes()

Get All Ingredients

ingredients = drugs_db.get_all_ingredients()

returns a list of strings

Accessing the Database directly

The Database and the indexes can be accessed directly. They are all TinyDB instances

  • obj.db: The main DB
  • obj.ndc_index: Two layered index for the NDC product Id
  • obj.generic_name_index: Index of Generic names
  • obj.medication_class_index: Index of Medication classes
  • obj.ingredient_index: index of the Active ingredients

Reference

Records in the database are stored in the following format.

  • package_ndc: List of strings
  • product_ndc: string
  • generic_name: string (lowercase)
  • brand_name: string (lowercase)
  • active_ingredients: list of strings (lowercase)
  • pharm_class: list of strings (lowercase)
  • pharm_class_epc: list of strings (lowercase)
  • pharm_class_cs: list of strings (lowercase)
  • pharm_class_moa: list of strings (lowercase)
  • pharm_class_pe: list of strings (lowercase)

There is also a calculated field called all_classes() that returns all class fields in one (no duplicates)

Concepts

The FDA drugs database comes in a large json file format, with a lot of additional data. I have stripped away the majority of it, leaving the main classification elements, brand name, generic name, ingredients and medication classes. the data is pulled and ran through a pydantic model to ensure standards before being saved.

The data is saved in tinyDB, thus no need to have a database server in place, just run the download and start accessing the data

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

pydrugsdatabase-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file pydrugsdatabase-0.1.0.tar.gz.

File metadata

  • Download URL: pydrugsdatabase-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for pydrugsdatabase-0.1.0.tar.gz
Algorithm Hash digest
SHA256 77ef9b43dd08a8c57ca283e3c75cf10c45808fcbc1971eab0ba83644e893d3fb
MD5 db8255ff1c76c12dbf585e86fa7a40bb
BLAKE2b-256 99b79205a08afa4d060ab199e3f726dd599756a8b85e3267ab90c2a4e20c3fb4

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