Medicare Part D Drug Spending Data: Unit Cost, Claims, and Beneficiary Counts via API
Pull Medicare Part D drug spending from CMS: total cost, claims, beneficiaries, and unit price by drug name or manufacturer. Track pharmaceutical pricing trends. No API key required.
The actor referenced in this article. Pay only for results delivered.
Medicare Part D covers prescription drugs for over 50 million Americans. CMS publishes the full spending dataset each year: how much Medicare paid per drug, per manufacturer, per provider. Our Medicare Part D Scraper makes that data queryable by drug name or manufacturer without downloading multi-gigabyte flat files.
What you get per record
drug_name— generic or brand namemanufacturer— pharmaceutical companytotal_spending— total Medicare spend (USD)total_claims— number of prescription claimstotal_beneficiaries— number of Medicare beneficiariesunit_cost_avg— average cost per unitcost_per_beneficiary— total spend divided by beneficiariesyear— data yearscraped_at— ISO timestamp
Python example
import requests, time
run = requests.post(
"https://api.apify.com/v2/acts/themineworks~medicare-part-d-drug-spending/runs",
headers={"Authorization": f"Bearer {APIFY_TOKEN}"},
json={
"drug": "ozempic",
"maxResults": 100
}
)
run_id = run.json()["data"]["id"]
while True:
r = requests.get(
f"https://api.apify.com/v2/actor-runs/{run_id}",
headers={"Authorization": f"Bearer {APIFY_TOKEN}"}
).json()
if r["data"]["status"] in ("SUCCEEDED", "FAILED"):
break
time.sleep(5)
records = requests.get(
f"https://api.apify.com/v2/actor-runs/{run_id}/dataset/items",
headers={"Authorization": f"Bearer {APIFY_TOKEN}"}
).json()
for r in records:
print(r["drug_name"], r["year"])
print(f" Total spend: ${r['total_spending']:,.0f}")
print(f" Claims: {r['total_claims']:,}")
print(f" Avg unit cost: ${r['unit_cost_avg']:.2f}")
Year-over-year pricing trend
import pandas as pd
df = pd.DataFrame(records)
df["total_spending"] = pd.to_numeric(df["total_spending"], errors="coerce")
df["unit_cost_avg"] = pd.to_numeric(df["unit_cost_avg"], errors="coerce")
trend = df.groupby("year").agg({
"total_spending": "sum",
"total_claims": "sum",
"unit_cost_avg": "mean"
}).reset_index()
print(trend)
Top drugs by total Medicare spend
run = requests.post(
"https://api.apify.com/v2/acts/themineworks~medicare-part-d-drug-spending/runs",
headers={"Authorization": f"Bearer {APIFY_TOKEN}"},
json={"maxResults": 500, "sortBy": "total_spending"}
)
# ... poll and fetch
df = pd.DataFrame(records)
print(df.nlargest(20, "total_spending")[["drug_name", "manufacturer", "total_spending", "unit_cost_avg"]])
Parameters
| Parameter | Default | Notes |
|---|---|---|
drug | — | Drug name (partial match supported) |
manufacturer | — | Manufacturer name filter |
year | latest | Data year |
sortBy | "total_spending" | Sort field |
maxResults | 100 | Maximum records to return |
Use cases
Pharma market intelligence. Track how Medicare spending on your drug or a competitor’s has shifted year over year. Identify which manufacturers are gaining Medicare market share.
Drug pricing research. Compare unit costs across similar drug classes. Identify where generic entry has compressed prices versus branded drugs maintaining premium positioning.
Investment research. Before taking a position in a pharmaceutical company, map their Medicare revenue exposure by drug. High Medicare concentration is both an opportunity and a regulatory risk.
Policy analysis. Quantify total Medicare expenditure on a drug class to model the fiscal impact of coverage or pricing policy changes.
Healthcare consulting. Deliver data-backed pharmaceutical cost benchmarking to hospital systems and payers negotiating formulary contracts.
Pricing
$0.002 per record. Empty queries are not charged.
Available on Apify.
Explore the scraper referenced in this article — see inputs, outputs, and pricing, then run it on Apify.
Airbnb Scraper: Listing Prices, Ratings, and Availability Without the API
Airbnb has no public listings API. Here's how to pull nightly price, rating, superhost status and coordinates from Airbnb search results using Python.
Maps Leads: Verified Email Extraction from Google Maps Business Listings
How to pull B2B leads from Google Maps with MX-verified emails, past the official API's 120-result cap, and pay only for contactable businesses.
Realtor.com Scraper: Property and Agent Data Without the MLS Paywall
Scrape Realtor.com listings in Python — price, beds, baths, county, and the listing agent + brokerage office on every record. No login, no API key.