This release is a pre-release and may not be stable for production use.
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.
Metadata
Release files for ndclib 1.0rc1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ndclib-1.0rc1.tar.gz | 10.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ndclib-1.0rc1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.0 kB
Release files / ndclib-1.0rc1.tar.gz
| Download URL | ndclib-1.0rc1.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bff6a1c73b29630b0bee2e26e78bcabf7281f10507b0cfc67a019a9a93536539
|
|
BLAKE2b-256 checksum How to use checksums |
839213000e2c870c85d7df6c1c4cfe8457f2da56faffb011a054ae32df672e80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 19, 2025.
Transparency logRelease files / ndclib-1.0rc1-py3-none-any.whl
| Download URL | ndclib-1.0rc1-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f15a163c9d586a672ab9cc58c9b1f25b9474f021fc1342d142c358ae80905e3b
|
|
BLAKE2b-256 checksum How to use checksums |
99bca10c7e97c85a46ce0a62180d67e0eb0214086527775f8097cfc2135c4039
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 19, 2025.
Transparency log