⛑ REDCap API interface in Python

Overview

Logo for The Center for Data Driven Discovery

REDCap API in Python

Description

Supports structured data extraction for REDCap projects. The API module d3b_redcap_api.redcap.REDCapStudy can be logically divided into three parts...

Part 1: The low level interface

These are generic request/response handlers implemented here because there's no "official" Python SDK from Vanderbilt for the REDCap API, and the closest thing there is (https://github.com/redcap-tools/PyCap) wasn't being actively maintained when I wanted it.

(If someone wants to replace this part using PyCap at some point, go ahead. Just don't break any of Part 3 in the process.)

Functions: _get_response, _get_json, _get_text, _act_file

Part 2: API functions

With the exception of get_records, which semi-intelligently retrieves records in batches instead of all at once to evade server errors from response timeouts, these all mirror the same/similarly named commands described in the REDCap API documentation at https://<your_redcap_server>/api/help/. For CHOP users that would be https://redcap.chop.edu/api/help.

(If someone wants to replace this part using PyCap at some point, go ahead. Just don't break any of Part 3 in the process.)

Functions:

Getters Setters Deleters
get_arm_names (Export Arms) set_arm_names (Import Arms)) NA
get_event_metadata (Export Events) set_event_metadata (Import Events) NA
get_instrument_labels (Export Instruments) NA NA
get_field_export_names (Export List of Export Field Names) NA NA
get_file (Export a File) set_file (Import a File) delete_file (Delete a File)
get_redcap_version (Export REDCap Version) NA NA
get_project_info (Export Project Info) set_project_info (Import Project Info) NA
get_project_xml (Export Project XML) NA NA
get_users (Export Users) set_users (Import Users) NA
get_data_dictionary (Export Metadata (Data Dictionary)) set_data_dictionary (Import Metadata (Data Dictionary)) NA
get_instrument_event_mappings (Export Instrument-Event Mappings) set_instrument_event_mappings (Import Instrument-Event Mappings) NA
get_records (Export Records) set_records (Import Records) delete_records (Delete Records)
get_repeating_forms_events (Export Repeating Instruments and Events) set_repeating_forms_events (Import Repeating Instruments and Events) NA
get_report_records (Export Reports) NA NA

Part 3: Whole project retrieval and structuring

Functions:

Name Purpose

get_selector_choice_map

Returns a map for every field that needs translation from a numeric index to a label value:

{
  <field_name>: {
    <index>: <value>,
    ...indexes
  },
  ...fields
}

get_records_tree

Returns all data from the project in the nested form:
{
  <event>: {                   # event data
    <instrument>: {            # event instrument data
      <record_id>: {           # subject data for this event instrument
        <instance>: {          # subject event instrument instance
          <field>: {<values>}, # set of field values
          ...fields
        },
        ...instances
      },
      ...records
    },
    ...instruments
  },
  ...events
}

There are also some extra utility functions for converting the records tree into one or more Pandas DataFrames...

Name Purpose

d3b_redcap_api.df_utils.to_df

Converts one get_records_tree()[event][instrument] to a pandas DataFrame

d3b_redcap_api.df_utils.all_dfs

Calls to_df on every instrument found in the records tree and returns a dict keyed by the instrument name if the instrument name is unique or by event_instrument if not.

Example Usage:

from d3b_redcap_api.redcap import REDCapStudy
from d3b_redcap_api.df_utils import all_dfs

r = REDCapStudy("https://redcap.chop.edu/api/", PROJECT_API_TOKEN)
study_data, errors = r.get_records_tree(raw_selectors=False)

as_dataframes = all_dfs(study_data)
Owner
D3b
Center for Data Driven Discovery in Biomedicine at the Children's Hospital of Philadelphia
D3b
Simple web-based hcaptcha bypass

Hcaptcha-Bypass !!! If you found this useful, please click the STAR button !!! Simple web-based hcaptcha bypass Just a demonstration right now, and yo

Kieronia 4 Oct 06, 2021
Use CSV files as a Nornir Inventory source with hosts, groups and defaults.

nornir_csv Use CSV files as a Nornir Inventory source with hosts, groups and defaults. This can be used as an equivalent to the Simple Inventory plugi

Matheus Augusto da Silva 2 Aug 13, 2022
Telegram tools

Telegram-Tools Telegram tools. Explanation English | 中文 Features Export group memebrs Add users to the group Send message to users Setup API Open http

4 Apr 02, 2022
For specific function. For my own convenience. Remind owner to share data to another DITO user.

For specific function. For my own convenience. Remind owner to share data to another DITO user.

Meigo 1 Dec 14, 2021
ELiza music is a telegram music bot project, allow you to play music on voice chat group telegram.

❤️ 𝗘𝗹𝗶𝘇𝗮 𝗠𝘂𝘀𝗶𝗰 ❤️ Unmaintained. The new repo of @MrsElizaRobot is private. (It is no longer based on this source code. The completely rewrit

Team Eliza 2 Dec 08, 2022
Automate and Manage Telegram Channels

Channel Automation Bot @ChannelAutomateBot A star ⭐ from you means a lot to us! Telegram bot to automate and manage channels. Usage Deploy to Heroku T

Stark Bots 61 Dec 29, 2022
Python-random-quote - A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

amir mohammad fateh 1 Jan 02, 2022
Updater for PGCG (Paradox Game Converters Group) converters written in Python.

Updater Updater for PGCG (Paradox Game Converters Group) converters written in Python. Needs to be put inside an "Updater" directory in the root conve

Paradox Game Converters 2 Jan 10, 2022
A telegram bot writen in python for mirroring files on the internet to Google Drive

owner of this repo :- AYUSH contact me :- AYUSH Slam Mirror Bot This is a telegram bot writen in python for mirroring files on the internet to our bel

Thanusara Pasindu 1 Nov 21, 2021
Terraform module to ship CloudTrail logs stored in a S3 bucket into a Kinesis stream for further processing and real-time analysis.

AWS infrastructure to ship CloudTrail logs from S3 to Kinesis This repository contains a Terraform module to ship CloudTrail logs stored in a S3 bucke

Nexthink 8 Sep 20, 2022
Gorrabot is a bot made to automate checks and processes in the development process.

Gorrabot is a Gitlab bot made to automate checks and processes in the Faraday development. Features Check that the CHANGELOG is modified By default, m

Faraday 7 Dec 14, 2022
Bot made with Microsoft Azure' cloud service

IttenWearBot Autori: Antonio Zizzari Simone Giglio IttenWearBot è un bot intelligente dotato di sofisticate tecniche di machile learning che aiuta gli

Antonio Zizzari 1 Jan 24, 2022
Project for the discipline of Visual Data Analysis at EMAp FGV.

Analysis of the dissemination of fake news about COVID-19 on Twitter This project was the final work for the discipline of Visual Data Analysis of the

Giovani Valdrighi 2 Jan 17, 2022
Send pm to Admin - Telegram

Send pm to Admin - Telegram

Ahoora 3 Nov 17, 2022
A muti pairs martingle trading bot for Binance exchange.

multi_pairs_martingle_bot English Documentation A muti pairs martingle trading bot for Binance exchange. Configuration { "platform": "binance_futur

51bitquant 62 Nov 16, 2022
A wrapper for slurm especially on Taiwania2 (HPC CLI)A wrapper for slurm especially on Taiwania2 (HPC CLI)

TWCC-slurm-wrapper A wrapper for slurm especially on Taiwania2 (HPC CLI). For Taiwania2 (HPC CLI) usage, please refer to here. (中文) How to Install? gi

Chi-Liang, Liu 5 Oct 07, 2022
Dribble sign up screen built in python and kivy

Dribble sign up screen built in python and kivy contains Dribble icon with icon position and shadow animation.

1 Dec 06, 2021
API which uses discord+mojang api to scrape NameMC searches/droptime/dropping status of minecraft names, and texture links

API which uses discord+mojang api to scrape NameMC searches/droptime/dropping status of minecraft names, and texture links

2 Dec 22, 2021
Wonderful Phoenix-Bot

Phoenix Bot Discord Phoenix Bot is inspired by Natewong1313's Bird Bot project yet due to lack of activity by their team. We have decided to revive th

Senior Developer 0 Aug 12, 2021
Bot for automated buying boxes on Binance

V 1.0 Bot for automated buying boxes on Binance В settings.py выставляем свои COOKIE и свой CSRFTOKEN В settings.py для headers выставляем свои параме

Matvey 3 Jan 18, 2022