Clinical Trials API Client
A Python client for interacting with the ClinicalTrials.gov API v2. This library provides an easy-to-use interface for fetching and analyzing clinical trial data.
Installation
You can install the package via pip:
pip install pyctrials
Quick Start
from pyctrials import ClinicalTrialsAPI
# Initialize the client
client = ClinicalTrialsAPI()
# Fetch trials for a specific condition
trials = client.fetch_trials("Pompe Disease")
# Display results
print(f"Found {len(trials)} trials")
print(trials[['nct_id', 'brief_title', 'overall_status']].head())
Features
- Easy-to-use interface for ClinicalTrials.gov API
- Automatic pagination handling
- Retry mechanism for failed requests
- Data parsing and cleanup
- DataFrame-based output for easy analysis
- Comprehensive trial information including:
- Trial identification
- Status information
- Sponsor details
- Study design
- Location information
- And more...
Documentation
ClinicalTrialsAPI
The main class for interacting with the API.
client = ClinicalTrialsAPI(max_retries=5, retry_delay=5)
Parameters:
max_retries(int): Maximum number of retry attempts for failed requestsretry_delay(int): Delay between retry attempts in seconds
Methods
fetch_trials()
trials = client.fetch_trials(
condition="Pompe Disease",
status="RECRUITING",
page_size=10
)
Parameters: other parameters will follow
condition(str): Medical condition to search forstatus(str): Trial status filter (default: 'RECRUITING') (ACTIVE_NOT_RECRUITING ┃ COMPLETED ┃ ENROLLING_BY_INVITATION ┃ NOT_YET_RECRUITING ┃ RECRUITING ┃ SUSPENDED ┃ TERMINATED ┃ WITHDRAWN ┃ AVAILABLE ┃ NO_LONGER_AVAILABLE ┃ TEMPORARILY_NOT_AVAILABLE ┃ APPROVED_FOR_MARKETING ┃ WITHHELD ┃ UNKNOWN) --> visit https://clinicaltrials.gov/data-api/api#get-/studies for more infopage_size(int): Number of results per page (default: 10)
Returns:
- pandas.DataFrame containing the trial data
Examples
Basic Usage
from pyctrials import ClinicalTrialsAPI
# Initialize client
client = ClinicalTrialsAPI()
# Fetch trials
trials = client.fetch_trials("Spinal Muscular Atrophy")
# Show unique sponsors
print(trials['sponsor'].unique())
# Get trials by phase
phase_counts = trials['phase'].value_counts()
print(phase_counts)
Error Handling
try:
trials = client.fetch_trials("Rare Disease")
except Exception as e:
print(f"An error occurred: {e}")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Thanks to ClinicalTrials.gov for providing the API
- Built with Python, pandas, and requests
Citation
If you use this package in your research, please cite:
@software{pyctrials,
author = {Anass Tinakoua},
title = {Clinical Trials API Client},
year = {2024},
publisher = {GitHub},
url = {https://github.com/atinak/pyctrials}
}
Metadata
Release files for pyctrials 0.1.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyctrials-0.1.11.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyctrials-0.1.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.2 kB
Release files / pyctrials-0.1.11.tar.gz
| Download URL | pyctrials-0.1.11.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8724764d61916b17aa0cc8e6903001d277ef64ada912b197727e62b734c92223
|
|
BLAKE2b-256 checksum How to use checksums |
fd00bc895db5142179314c15cb635dabd311b3d92daf128fabdb2f42088753c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|
Release files / pyctrials-0.1.11-py3-none-any.whl
| Download URL | pyctrials-0.1.11-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3675b86d3ab2ca4c38764d59e61e189599504e0272f79c4cb5e4524f6417b6c9
|
|
BLAKE2b-256 checksum How to use checksums |
7e7e55d5ea877d617d9f4ceebe2e272a104b0db785bff8f6a785345718c4f0fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.21
|