Documentation Python quickstart Blog Free tools Enterprise solutions hello@quanticdata.ioLog in

Collectors · Research & science

openFDA API in Python

Drug adverse-event reports from the FDA FAERS database — drugs, reactions, seriousness. One POST from Python with query, rows back as JSON with 22 fields, $0.0004 per delivered report. No proxies or parsers to maintain.

A Python requests snippet that posts {
A Python requests call to the openfda collector returns one dict per report, at $0.0004 each.

First call

Install, call, read the rows.

pip install requests
The only dependency.
import os, requests

r = requests.post(
    "https://api.quanticdata.io/v1/scraper/collectors/openfda/run",
    headers={"Authorization": f"Bearer {os.environ['QD_API_KEY']}"},
    json={
        "query": "ibuprofen",
        "max_results": 50,
    },
    timeout=120,
)
r.raise_for_status()
run = r.json()["payload"]
print(run["count"], "rows,", run["cost"]["usd"], "USD")
for row in run["results"]:
    print(row.get("report_id"), row.get("serious"), row.get("serious_reasons"), row.get("drugs"))
Python: one FDA adverse events (openFDA) run (Per farmaco), printing report_id, serious, serious_reasons, drugs

The key comes from an environment variable, never from the code. The run answers in the same request when it finishes in time; payload.results holds the rows and payload.cost what they cost.

Request parameters

What the collector takes.

Input of the FDA adverse events (openFDA) collector
ParameterTypeRequiredMeaning
querystringyesA drug name, or an openFDA field:value query.
max_resultsintegerno (default 50)How many reports to deliver at most (1–500). You pay only for delivered reports.

Response fields

22 fields per report.

Fields of each row (report)
FieldTypeWhat it holds
rankinteger1-based position.
report_idstringFAERS safety report id.
seriousbooleanWhether the report is flagged serious.
serious_reasonsstring[]Death, hospitalization, life-threatening…
drugsstring[]Reported medicinal products.
reactionsstring[]Reactions (MedDRA terms).
patient_sexstring, nullablemale/female when reported.
patient_agestring, nullablePatient age as reported.
countrystring, nullableCountry of occurrence.
received_datestring, nullableReceived date (ISO).
report_typestring, nullableReport type code.
suspect_drugsstring[]Drugs the reporter held responsible.
drug_rolesstring[]Roles present in the report: suspect, concomitant, interacting.
generic_namesstring[]Generic names of the reported drugs.
brand_namesstring[]Brand names of the reported drugs.
indicationsstring[]What the drugs were taken for.
reaction_outcomesstring[]Outcomes of the reactions (recovered, fatal…).
patient_age_yearsnumber, nullablePatient age in years, when reported in years.
patient_weight_kgnumber, nullablePatient weight, kg.
latest_updatestring, nullableDate of the latest information on the report.
reporterstring, nullableWho reported: physician, pharmacist, consumer…
manufacturer_report_idstring, nullableManufacturer's own report number.

Add ?format=csv to the runs endpoint to get the same rows as CSV.

Long runs

Run in the background, then poll.

A run that needs more time can go to the background: send "async": true, get 202 with the run id, and poll the runs endpoint until the status is done. Reading a run is free.

import os, time, requests

H = {"Authorization": f"Bearer {os.environ['QD_API_KEY']}"}
r = requests.post("https://api.quanticdata.io/v1/scraper/collectors/openfda/run", headers=H,
                  json={**{"query":"ibuprofen","max_results":50}, "async": True}, timeout=30)
run_id = r.json()["payload"]["run_id"]
while True:
    run = requests.get(f"https://api.quanticdata.io/v1/scraper/collectors/runs/{run_id}", headers=H, timeout=30).json()["payload"]
    if run["status"] in ("done", "failed"):
        break
    time.sleep(5)
print(run["status"], run["count"])
Python: background run and polling

Errors

What can come back, and what is billed.

Collector run errors
StatusMeaningBilled
400The input does not match the collector (payload.errors)No
401Missing or wrong API keyNo
402Balance and free credit do not cover the run: top upNo
422The input can never resolve; retrying the same input cannot helpNo
424The run failed at the source (blocked, timed out, layout changed); safe to retryNo
429Rate limit or a per-account brake; wait for Retry-AfterNo

Only delivered rows are billed: a run that delivers nothing costs nothing.

Price

$0.0004 per delivered report.

What FDA adverse events (openFDA) rows cost at list price
RowsCost
1$0.0004
1,000$0.40
10,000$4.00

Up to 500 reports per run; split larger jobs into several runs. The $2 free credit every month covers about 5,000 reports. No subscription; paid tiers lower the unit price. All collector prices: collector pricing.

Before you run it

Questions developers ask

Is there a free FDA adverse events (openFDA) API?

Every account gets $2 of free usage each month, about 5,000 reports of this collector at $0.0004 each, with no card.

Do I have to handle proxies, retries or blocks?

No. The collector runs on our network and handles them; a run blocked at the source returns 424 and is not billed.

How many rows can one run return?

Up to 500 reports per run (the max_results input, where the collector has one).

Can an AI agent run it?

Yes: the MCP server exposes it as the run_collector tool, with the same input and price. See the MCP server.

Run it on the free credit.

Create an API key, export it as QD_API_KEY and run the example. $0.0004 per delivered report, no subscription.