⛑ 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
This project is based on discord.py and is meant to be a 'Quick Start Bot' to cut down on the time it takes to write complex discord bots.

This project is based on discord.py and is meant to be a 'Quick Start Bot' to cut down on the time it takes to write complex discord bots.

Alec Ibarra 1 Mar 03, 2022
Updated version of A discord token/password grabber thats grabs all of their tokens, passwords, credit card + alot more

Updated version of A discord token/password grabber thats grabs all of their tokens, passwords, credit card + alot more

Rdimo 556 Aug 05, 2022
A tool to build scripts to toggle between minimal & default services in Windows based on user defined lists.

A tool to build scripts to toggle between minimal & default services in Windows based on user defined lists.

AMIT 29 Jan 01, 2023
Dados Públicos de CNPJ disponibilizados pela Receita Federal do Brasil

Dados Públicos CNPJ Fonte oficial da Receita Federal do Brasil, aqui. Layout dos arquivos, aqui. A Receita Federal do Brasil disponibiliza bases com o

Aphonso Henrique do Amaral Rafael 102 Dec 28, 2022
Python Markov Chain chatbot running on Telegram

Hanasubot Hanasubot (Japanese 話すボット, talking bot) is a Python chatbot running on Telegram. The bot is based on Markov Chains so it can learn your word

12 Dec 27, 2022
Retrieve information from DBLP and update BibTex files automatically

Rebib TLDR: This script retrieves information from DBLP to update your BibTex files. python rebib.py --bibfile xxx.bib It first parses the bib entries

Shangtong Zhang 49 Jan 01, 2023
A Telegram bot to send messages in Telegram groups or Channels using bots anonymously.

Group-chatting-bot A bot to send messeges to group using bot telegram bot ❤️ Support Made with Python3

Pyrogramers 16 Nov 06, 2022
A Fork of Gitlab's Permifrost tool for managing Snowflake Permissions

permifrost-fork This is a fork of the GitLab permifrost project. As the GitLab team is not currently maintaining the project, we've taken on maintenac

Hightouch 7 Oct 13, 2021
Discord Rpc With Python And 2 Buttons

Discord-RPC-With-Python- Discord Rpc With Python And 2 Buttons Packages pypresence time Required Programs Python Latest Version Random IDE Discord :P

Kaz 4 Dec 12, 2021
The accompanying code for the paper "GMAT: Global Memory Augmentation for Transformers" (Ankit Gupta and Jonathan Berant).

GMAT: Global Memory Augmentation for Transformers This repository contains the accompanying code for the paper: "GMAT: Global Memory Augmentation for

Ankit Gupta 7 Oct 21, 2021
Design and build a wrapper for the Open Weather API current weather data service

Design and build a wrapper for the Open Weather API current weather data service that returns a city's temperature, with caching, also allowing for the temperature of the latest queried cities that a

Duan Rafael Ribeiro 1 Jun 27, 2022
Google Search Results via SERP API pip Python Package

Google Search Results in Python This Python package is meant to scrape and parse search results from Google, Bing, Baidu, Yandex, Yahoo, Home depot, E

SerpApi 254 Jan 05, 2023
This repository contains modules that extend / modify parts of Odoo ERP

Odoo Custom Addons This repository contains addons that extend / modify parts of Odoo ERP. Addons list account_cancel_permission Only shows the button

Daniel Luque 3 Dec 28, 2022
Python Library to Extract youtube video Tags without Youtube API

YoutubeTags Python Library to Extract youtube video Tags without Youtube API Installation pip install YoutubeTags Example import YoutubeTags from Yout

Nuhman Pk 17 Nov 12, 2022
Rocks vc Userbot: A Telegram Bot Project That's Allow You To Play Audio And Video Music On Telegram Voice Chat Group

⭐️ Rocks VC Userbot ⭐️ Telegram Userbot To Play Audio And Video Song On VC Chat

Dr Asad Ali 10 Jul 18, 2022
Home Assistant Hilo Integration via HACS

BETA This is a beta release. There will be some bugs, issues, etc. Please bear with us and open issues in the repo. Hilo Hilo integration for Home Ass

66 Dec 23, 2022
A Telegram Video Watermark Adder Bot

Watermark-Bot A Telegram Video Watermark Adder Bot by @VideosWaterMarkRobot Features: Save Custom Watermark Image. Auto Resize Watermark According to

5 Jun 17, 2022
Spotify playlist anonymizer.

Spotify heavily personalizes auto-generated playlists like Song Radio based on the music you've listened to in the past. But sometimes you want to listen to Song Radio precisely to hear some fresh so

Jakob de Maeyer 9 Nov 27, 2022
Apex lets you build, deploy, and manage AWS Lambda functions with ease.

No longer maintained This software is no longer being maintainted and should not be chosen for new projects. See this issue for more information Apex

Apex 25 Dec 23, 2022
A bot can be used to broadcast your messages ( Text & Media ) to the Subscribers

Broadcast Bot A Telegram bot to send messages and medias to the subscribers directly through bot. Authorized users of the bot can send messages (Texts

Shabin-k 8 Oct 21, 2022