DEV Community

Alex Spinov
Alex Spinov

Posted on

ClinicalTrials.gov Has a Free API — Search 500K+ Trials in Python

If you're in biotech, pharma, or health research — you need this API.

ClinicalTrials.gov has a free API (v2) that lets you search 500,000+ clinical trials worldwide. No API key needed.

I built a Python toolkit around it.

Quick Search

import requests

resp = requests.get('https://clinicaltrials.gov/api/v2/studies', params={
    'query.term': 'cancer immunotherapy',
    'filter.overallStatus': 'RECRUITING',
    'pageSize': 5,
    'format': 'json'
})

for study in resp.json().get('studies', []):
    p = study['protocolSection']
    nct = p['identificationModule']['nctId']
    title = p['identificationModule']['briefTitle']
    status = p['statusModule']['overallStatus']
    print(f'[{nct}] {title}{status}')
Enter fullscreen mode Exit fullscreen mode

Output:

[NCT05847283] CAR-T Cell Therapy for Solid Tumors — RECRUITING
[NCT06123456] Pembrolizumab + Novel Agent Phase 3 — RECRUITING
...
Enter fullscreen mode Exit fullscreen mode

Use Cases

  • Researchers: Find trials in your area, build meta-analysis datasets
  • Investors: Monitor biotech company pipelines
  • Patients: Find recruiting trials near you
  • Journalists: Track drug development progress

Search by Sponsor

# What is Pfizer testing right now?
resp = requests.get('https://clinicaltrials.gov/api/v2/studies', params={
    'query.sponsor': 'Pfizer',
    'filter.overallStatus': 'RECRUITING',
    'pageSize': 5,
    'format': 'json'
})
for s in resp.json().get('studies', []):
    print(s['protocolSection']['identificationModule']['briefTitle'])
Enter fullscreen mode Exit fullscreen mode

Export to CSV

import csv

def export_trials(query, filename='trials.csv'):
    resp = requests.get('https://clinicaltrials.gov/api/v2/studies', params={
        'query.term': query, 'pageSize': 100, 'format': 'json'
    })
    with open(filename, 'w', newline='') as f:
        writer = csv.writer(f)
        writer.writerow(['NCT ID', 'Title', 'Status', 'Phase'])
        for s in resp.json().get('studies', []):
            p = s['protocolSection']
            writer.writerow([
                p['identificationModule']['nctId'],
                p['identificationModule']['briefTitle'],
                p['statusModule']['overallStatus'],
                ', '.join(p.get('designModule', {}).get('phases', []))
            ])

export_trials('Alzheimer')
Enter fullscreen mode Exit fullscreen mode

Full Toolkit

I built a complete toolkit with CLI support:

python search_trials.py 'diabetes' --status RECRUITING --format csv --output trials.csv
Enter fullscreen mode Exit fullscreen mode

👉 GitHub: clinicaltrials-research-toolkit

Part of My Research API Suite

This is one of 9 free research API toolkits I've built:

What Would You Search For?

Drop a comment — what clinical trial data would be useful for your work?


Need custom data extraction? Check my Apify actors for web scraping tools.

Top comments (0)