โ›‘ 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
OSINT tool to get information from a Github and Gitlab profile and find user's email addresses leaked on commits.

gitrecon OSINT tool to get information from a Github or Gitlab profile and find user's email addresses leaked on commits. ๐Ÿ“š How does this work? GitHu

GOฮ ZO 211 Dec 17, 2022
Python package and CLI for user-friendly integration with SAS Viya

sasctl A user-friendly Python interface for SAS Viya. Full documentation: https://sassoftware.github.io/python-sasctl Table of Contents Overview Prere

SAS Software 30 Dec 14, 2022
A hilarious program that translates text to Google's

Bork, bork, bork! A hilarious program that translates text in a file to Google's "bork bork bork' language. How to use Download the main.py file. Chan

The Algorithmic 1 Dec 17, 2021
ShotsGram - For sending captures from your monitor to a telegram chat (robot)

ShotsGram pt-BR Envios de capturas do seu monitor para um chat do telegram. Essa

Carlos Alberto 1 Apr 24, 2022
Upload on Doodstream by Url, File and also by direct forward post from other channel...

Upload on Doodstream by Url, File and also by direct forward post from other channel...

Pส€แด‡แด…แด€แด›แดส€ 8 Aug 10, 2022
An implementation of webhook used to notify GitHub repository events to DingTalk.

GitHub to DingTask An implementation of webhook used to notify GitHub repository events to DingTalk.

Prodesire 5 Oct 02, 2022
Python version of PlaceNL's headless bot with automatic access token refresh

Reddit /r/place 2022 headless bot This headless Python bot will automatically login to reddit, obtain access tokens (and refreshes them when they expi

19 May 21, 2022
A code that can make an account bump your discord server 24/7!

BumpCord A code that can make an account bump your discord server 24/7! The main.py is the main file. keep_alive.py prevents your repl from going to s

Phantom 28 Aug 20, 2022
Discord bot that displays Jazz Jackrabbit 2 server status, current gamemode as "Playing.." status

JJ2-server-status-discord-bot Discord bot that displays Jazz Jackrabbit 2 server status, current gamemode as "Playing.." status How to setup: 0. Downl

2 Dec 09, 2021
Bitcoin-chance-wheel - Try your luck at getting bitcoins

Program Features - โœ๏ธ Why did we name this tool the Lucky Wheel? - โœ๏ธ This tool

hack4lx 20 Dec 22, 2022
Powerful Telegram userbot to turn your PROFILE PICTURE & LAST NAME into a real time clock & to change your BIO automatically.

DATE_TIME_USERBOT-TeLeTiPs Powerful Telegram userbot to turn your PROFILE PICTURE & LAST NAME into a real time clock & to change your BIO automaticall

53 Jan 05, 2023
A discord bot can stress ip addresses with python tool

Python-ddos-bot Coded by Lamp#1442 A discord bot can stress ip addresses with python tool. Warning! DOS or DDOS is illegal, i shared for educational p

IrgyGANS 1 Nov 16, 2021
A Code that can make your Discord Account 24/7!

Online-Forever Make your Discord Account Online 24/7! A Code written in Python that helps you to keep your account 24/7. The main.py is the main file.

Phantom 556 Dec 29, 2022
SongLink Discord Bot - Discord bot to share music links easily

SongLink_Discord_Bot Discord bot to share music links easily. Take a link from y

Edgar Lefevre 4 Feb 18, 2022
๐ŸŽ„ JustaGrabber - A discord token grabber written in python3

๐ŸŽ„ JustaGrabber - A discord token grabber written in python3 ๐ŸŽ‡ Made by kldiscord https://github.com/kldiscord ๐ŸŒŸ Please leave a star if you liked Jus

1 Dec 19, 2022
A web app via which users can buy and sell stocks using virtual money

finance Virtual Stock Trader. A web app via which users can buy and sell stocks using virtual money. All stock prices are real and provided by IEX. Fe

Kiron Deb 0 Jan 15, 2022
2b2t Priority queue discord bot announcer

2b2t Priority queue discord bot announcer Commands !prioq - Checks the priority queue length and sends it. !start - Starts a loop that sends the sta

Gumi 5 Jun 06, 2022
Stream Telegram files to web

Telegram File Stream Bot A Telegram bot to stream files to web Demo Bot ยป Report a Bug | Request Feature Table of Contents About this Bot Original Rep

Wrench 572 Jan 09, 2023
A modular Telegram Python bot running on python3 with a sqlalchemy, redislab, mongo database, telethon, and pyrogram.

Zeldris Robot A modular Telegram Python bot running on python3 with a sqlalchemy, redislab, mongo database, telethon, and pyrogram. How to set up/depl

IDNCoderX 42 Dec 21, 2022
Multipurpose Discord bot hosted on replit.com

RockyBot Multipurpose Discord bot hosted on https://replit.com/ Installing Dependencies Install poetry through pip: pip install poetry Then simply exe

Rocky 2 May 18, 2022