A Python library for manipulating National Drug Codes (NDCs)
Project description
NDClib
NDClib is a Python library for representing National Drug Codes (NDCs). Using the library, NDCs can be represented as objects and trivially converted between common output formats (e.g., 10– and 11–digit). This eliminates the need to manually convert NDCs from disparate sources into the same format before manipulating or comparing them.
Requirements
- Python 3.10 or newer
Installation
pip install ndclib
Usage
Define an NDC
Any NDC, irrespective of format (10– or 11–digit; hyphenated or unhyphenated), can be used to define an NDC object.
from ndclib import NDC
package = NDC("0378-4517-93")
Convert between formats
Once an NDC is defined, the to_10() or to_11() methods can be called to output the respective formatted strings. By default, the 10-digit format is hyphenated and the 11-digit format is not. Both methods take an optional boolean hyphenated parameter that can be used to control the output.
NDC("0378-4517-93").to_11()
# "00378451793"
NDC("00378451793").to_10()
# "0378-4517-93"
NDC("00378451793").to_10(hyphenated=False)
# "0378451793"
For convenience, ndc10 and ndc11 properties are also available to output the same information as the respective methods using the default hyphenation setting.
NDC("0378-4517-93").ndc11
# "00378451793"
NDC("00378451793").ndc10
# "0378-4517-93"
Check for equality
NDCs objects can be compared for equality using the regular equality operator.
NDC("0378-4517-93") == NDC("00378451793")
# True
Use alternative data sources
If no data provider is explicitly set, NDClib uses the RxNorm web API to perform any necessary conversions between NDC formats. This may not always be the best option depending on the type of data being processed. For example, it may be important to identify Universal Product Codes (UPCs) in addition to NDCs when performing tasks involving non-drug products treated as if they were medications. Some alternative data providers can also identify UPC codes.
Attempting to process UPC (or any) data not available from the selected provider will result in an exception:
NDC('11822079577').ndc10
# ndclib.exceptions.MissingNDCFormatException: An NDC format could not be determined for NDC '11822079577' using the current data provider (Rx Norm Web API).
Medi-Span
To use the Medi-Span electronic drug file from Wolters Kluwer, extract the MEDNDC file and instantiate the MediSpanProvider class with a path to the file.
from pathlib import Path
from ndc import MediSpanProvider
medispan = MediSpanProvider(
Path("/path/to/MEDFPLS/USAENG/DB/MEDNDC")
)
Set the NDC provider to the Medi-Span provider.
NDC.set_provider(medispan)
From this point on, all NDC objects will use the Medi-Span provider.
NDC('11822079577').ndc10
# '11822-79577'
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
This software is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ndclib-1.0rc1.tar.gz.
File metadata
- Download URL: ndclib-1.0rc1.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bff6a1c73b29630b0bee2e26e78bcabf7281f10507b0cfc67a019a9a93536539
|
|
| MD5 |
109e280ff09c20ca70479d5c1d6ed11c
|
|
| BLAKE2b-256 |
839213000e2c870c85d7df6c1c4cfe8457f2da56faffb011a054ae32df672e80
|
Provenance
The following attestation bundles were made for ndclib-1.0rc1.tar.gz:
Publisher:
python-publish.yml on eddie-cosma/ndclib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ndclib-1.0rc1.tar.gz -
Subject digest:
bff6a1c73b29630b0bee2e26e78bcabf7281f10507b0cfc67a019a9a93536539 - Sigstore transparency entry: 163653836
- Sigstore integration time:
-
Permalink:
eddie-cosma/ndclib@a97bab9ff0b38d866958637954184a5e3407087c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/eddie-cosma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a97bab9ff0b38d866958637954184a5e3407087c -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ndclib-1.0rc1-py3-none-any.whl.
File metadata
- Download URL: ndclib-1.0rc1-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f15a163c9d586a672ab9cc58c9b1f25b9474f021fc1342d142c358ae80905e3b
|
|
| MD5 |
f3c01aa7c330f6964fb4d6c3b00a3e57
|
|
| BLAKE2b-256 |
99bca10c7e97c85a46ce0a62180d67e0eb0214086527775f8097cfc2135c4039
|
Provenance
The following attestation bundles were made for ndclib-1.0rc1-py3-none-any.whl:
Publisher:
python-publish.yml on eddie-cosma/ndclib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ndclib-1.0rc1-py3-none-any.whl -
Subject digest:
f15a163c9d586a672ab9cc58c9b1f25b9474f021fc1342d142c358ae80905e3b - Sigstore transparency entry: 163653837
- Sigstore integration time:
-
Permalink:
eddie-cosma/ndclib@a97bab9ff0b38d866958637954184a5e3407087c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/eddie-cosma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a97bab9ff0b38d866958637954184a5e3407087c -
Trigger Event:
workflow_dispatch
-
Statement type: