Look up administered-drug activity by NPI in Python
Look up a shared drug code for three real providers, preserving billing units, settings and payment definitions.
Find reported Part B drug activity for a provider roster
You have rendering NPIs and want to see their reported use of an administered drug. This example selects three North Carolina ophthalmologists and looks up J2777, the source’s code for faricimab-svoa in 0.1 mg billing units. It returns beneficiaries, billing units and average allowed and Medicare-paid amounts, keeping facility and non-facility records separate.
The optional input.csv contains three genuine NPI selections. The same selections appear in the roster list in the Python code below. No providers, patients or utilization observations are invented.
Download the three sample tables into your working folder. provider_drugs.csv contains all 13 qualifying drug relationships for these NPIs, not just J2777. provider_coverage.csv contains their three coverage records; drug_codes.csv contains the seven corresponding code summaries. Every product field is retained. Code-summary counts describe the complete prepared edition, not just these providers.
The full $29 reference contains 273,750 provider/code/setting records, 120,565 NPIs with qualifying activity and 483 HCPCS Level II drug codes. It describes 2024 Original Medicare Part B activity; CPT-coded records are excluded. Review the complete product and coverage.
Code example
This standard-library example runs in a notebook cell, IPython or a script in the folder containing the CSVs. It reads the files one row at a time and keeps only the selected NPIs and drug code.
Paths are relative to your working folder; use from pathlib import Path; print(Path.cwd()) to check it, or supply full paths.
import csv
from decimal import Decimal
from pathlib import Path
# Genuine NPI selections, also supplied in the optional input.csv.
roster = [{'npi': '1013448216'}, {'npi': '1023078821'}, {'npi': '1023221199'}]
selected = {item['npi'] for item in roster}
hcpcs = 'J2777' # Faricimab-svoa, 0.1 mg per billing unit in this source.
with Path('provider_coverage.csv').open(encoding='utf-8', newline='') as f:
providers = {r['npi']: r for r in csv.DictReader(f) if r['npi'] in selected}
activity = {npi: [] for npi in selected}
# Stream the table, retaining only the chosen providers and code.
with Path('provider_drugs.csv').open(encoding='utf-8', newline='') as f:
for row in csv.DictReader(f):
if row['npi'] in selected and row['hcpcs_code'] == hcpcs:
activity[row['npi']].append(row)
results = []
for item in roster:
npi = item['npi']
provider = providers.get(npi)
if provider is None:
print(f'{npi}: absent from the public source; no zero activity inferred.')
continue
print(f"{provider['first_name']} {provider['last_or_organization_name']} | NPI {npi} | {provider['city']}, {provider['state']}")
if not activity[npi]:
print(f' No published {hcpcs} record for this NPI in this edition.')
for row in activity[npi]:
result = {key: row[key] for key in ['npi', 'hcpcs_code', 'place_of_service',
'beneficiaries', 'service_units', 'beneficiary_day_services',
'average_allowed_amount', 'average_medicare_payment']}
results.append(result)
setting = 'non-facility' if row['place_of_service'] == 'O' else 'facility'
print(f" {hcpcs} | {setting} | {row['beneficiaries']} beneficiaries | {Decimal(row['service_units']):,} billing units")
print(f" Average allowed: ${Decimal(row['average_allowed_amount']):.2f}; Medicare paid: ${Decimal(row['average_medicare_payment']):.2f} per billing unit")
Replace roster with your NPI strings or a CSV’s npi column, and change hcpcs to another included code. The sample and purchased files retain other drug relationships even though this example prints one drug.
Analysis of the output
Farid Khan | NPI 1013448216 | Hendersonville, NC
J2777 | non-facility | 37 beneficiaries | 5,580 billing units
Average allowed: $33.82; Medicare paid: $26.95 per billing unit
Henry Burnett | NPI 1023078821 | Winston Salem, NC
J2777 | non-facility | 26 beneficiaries | 9,780 billing units
Average allowed: $34.55; Medicare paid: $27.52 per billing unit
Sachin Mudvari | NPI 1023221199 | Raleigh, NC
J2777 | non-facility | 51 beneficiaries | 15,120 billing units
Average allowed: $34.30; Medicare paid: $27.27 per billing unit
The three providers have 37, 26 and 51 reported J2777 beneficiaries respectively. All three records are non-facility. The 5,580, 9,780 and 15,120 service units are billing units of 0.1 mg, not prescriptions, injections or visits. The separate beneficiary_day_services field counts distinct beneficiary/day occurrences for the particular NPI/code/setting.
Average Medicare payments are $26.95, $27.52 and $27.27 per billing unit. Allowed amounts are higher because they also include deductible, coinsurance and applicable third-party amounts. These source averages describe reported claims; they are not quarterly ASP payment limits or a current drug price. The CSV preserves precision beyond the two decimals printed here.
Even for the same code, modifiers, geography, service mix and payment rules can affect the amounts. This comparison does not rank clinical quality or efficiency. Do not add beneficiary counts across codes or providers as unique patients. Keep a facility record separate if one appears in another lookup; its payment scope differs.
CMS omits provider/code/setting combinations based on ten or fewer beneficiaries. If a lookup has no record, the code prints an explicit message rather than zero activity. provider_coverage.csv distinguishes an NPI visible in the public service file from one absent from that file, and counts its qualifying relationships. It cannot establish whether unpublished activity occurred.
Using the full dataset
Extract the purchased ZIP and replace the three sample tables with the complete files. The same code runs unchanged. The main table has 23 fields and a unique key of year + npi + hcpcs_code + place_of_service. Coverage joins on year and NPI; code summaries join on year and code. Keep identifiers as text.
The download includes six CSV tables, full field dictionaries, source/processing identities, row accounting and the verified example. Coverage describes all NPIs visible in the public source, not a complete registry. Coverage and row accounting exceed typical spreadsheet row limits; the streaming example avoids loading them entirely into memory.
For prescription-drug activity, use the separately priced Part D Prescriber–Drug Reference. For nationwide annual Part B spending, use Part B Drug Spending History. The provider and prescribing selection page explains the different questions. A shared NPI or code does not align patient populations, exclusions or reporting periods automatically.
Sources and versions
Source: CMS Medicare Physician & Other Practitioners by Provider and Service, calendar 2024, modified May 21, 2026 and captured by ACD October 26, 2026 UTC. This product selects source drug-flag Y records with HCPCS Level II codes; drug-flagged CPT records, including some vaccines, and all non-drug-flagged records are excluded and counted.
The source covers Original Medicare physician/supplier non-institutional claims, excluding DMEPOS MAC claims. It does not cover Medicare Advantage or institutional hospital outpatient drug claims. Historical provider attributes do not supply a current contact or licensure directory. The participation/assignment indicator applies to each NPI/code/setting and can vary within a provider.
The currently linked general CMS methodology is dated March 2025. Its publication date is separate from the observation year and data revision. The source and preparation record documents those dates and ACD processing revision 1.
The government source is free. ACD sells preparation, documented scope, validation and delivery. Processing improvements for these retained inputs are included; new source editions may be sold separately. No automatic refresh is promised.
Example checked October 26, 2026 against both these samples and the complete purchased files. Source and processing records, sample checksums · Expected result CSV. Independent preparation; no agency endorsement.