Skip to main content

A Python client for interacting with the ClinicalTrials.gov API v2

Project description

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 requests
  • retry_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 for
  • status (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 info
  • page_size (int): Number of results per page (default: 10)

Returns:

  • pandas.DataFrame containing the trial data

Examples

Basic Usage

from clinical_trials_api 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}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyctrials-0.1.10.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyctrials-0.1.10-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pyctrials-0.1.10.tar.gz.

File metadata

  • Download URL: pyctrials-0.1.10.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pyctrials-0.1.10.tar.gz
Algorithm Hash digest
SHA256 da6191cc59632ec7ebd00486c6152e41ca04acf3730a57c7ad0142f67cc1e139
MD5 da0ed43a453a22e2451c8b0f88b846ec
BLAKE2b-256 e35dabc9f3fbd7e8b6c0fdf4988e153c59d22cc05dc3ac04d71fc4d8a718c7b0

See more details on using hashes here.

File details

Details for the file pyctrials-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: pyctrials-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pyctrials-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 cef5f39e7fedd854dec481cf78c788a4552fb0bfa9c9bbecdf710c8a776d6a18
MD5 181c3ba7faf5d47ee3859694bc0561f6
BLAKE2b-256 5df239d97619ed6f1181a9d292b5acdc122c8b48c8596fcffb27d0b7e9280e78

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page