⛑ 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)
You might also like...
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

alpaca-trade-api-python is a python library for the Alpaca Commission Free Trading API.

alpaca-trade-api-python is a python library for the Alpaca Commission Free Trading API. It allows rapid trading algo development easily, with support for both REST and streaming data interfaces

WhatsApp Api Python - This documentation aims to exemplify the use of Moorse Whatsapp API in Python
WhatsApp Api Python - This documentation aims to exemplify the use of Moorse Whatsapp API in Python

WhatsApp API Python ChatBot Este repositório contém uma aplicação que se utiliza

A Python interface to AFL, allowing for easy injection of testcases and other functionality.

Fuzzer This module provides a Python wrapper for interacting with AFL (American Fuzzy Lop: http://lcamtuf.coredump.cx/afl/). It supports starting an A

A Python interface module to the SAS System. It works with Linux, Windows, and mainframe SAS. It supports the sas_kernel project (a Jupyter Notebook kernel for SAS) or can be used on its own.

A Python interface to MVA SAS Overview This module creates a bridge between Python and SAS 9.4. This module enables a Python developer, familiar with

Python bindings to the Syncthing REST interface.

python-syncthing Python bindings to the Syncthing REST interface. Python API Documentation Syncthing Syncthing REST Documentation Syncthing Forums $ p

Python interface to the World Bank Indicators and Climate APIs

wbpy A Python interface to the World Bank Indicators and Climate APIs. Readthedocs Github source World Bank API docs The Indicators API lets you acces

A Python interface between Earth Engine and xarray for processing weather and climate data
A Python interface between Earth Engine and xarray for processing weather and climate data

wxee What is wxee? wxee was built to make processing gridded, mesoscale time series weather and climate data quick and easy by integrating the data ca

Comments
  • ♻️ Use flat format for building record tree

    ♻️ Use flat format for building record tree

    eav format ignores requests to include data access group information, so we have to switch to requesting the flat record format. The eav method will stay in for debugging purposes.

    opened by fiendish 0
  • ✨ Include empty fields in record tree

    ✨ Include empty fields in record tree

    For completeness, it seems prudent to include unpopulated fields in the records tree as well so that it can be noticed which fields are not being used.

    opened by fiendish 0
Owner
D3b
Center for Data Driven Discovery in Biomedicine at the Children's Hospital of Philadelphia
D3b
Python interface to the LinkedIn API

Python LinkedIn Python interface to the LinkedIn API This library provides a pure Python interface to the LinkedIn Profile, Group, Company, Jobs, Sear

ozgur 844 Dec 27, 2022
A Python Library to interface with LinkedIn API, OAuth and JSON responses

#Overview Here's another library based on the LinkedIn API, OAuth and JSON responses. Hope this documentation explains everything you need to get star

Mike Helmick 69 Dec 11, 2022
Full-featured Python interface for the Slack API

This repository is archived and will not receive any updates It's time to say goodbye. I'm archiving Slacker. It's been getting harder to find time to

Oktay Sancak 1.6k Dec 13, 2022
A Python Library to interface with Tumblr v2 REST API & OAuth

Tumblpy Tumblpy is a Python library to help interface with Tumblr v2 REST API & OAuth Features Retrieve user information and blog information Common T

Mike Helmick 125 Jun 20, 2022
TeslaPy - A Python implementation based on unofficial documentation of the client side interface to the Tesla Motors Owner API

TeslaPy - A Python implementation based on unofficial documentation of the client side interface to the Tesla Motors Owner API, which provides functiona

Tim Dorssers 233 Dec 30, 2022
A Python package designed to help users of Cisco's FMC interface with its API.

FMCAPI was originally developed by Dax Mickelson ([email protected]). Dax has moved on to other projects but has kindly transferred the ownership of

Mark Sullivan 66 Dec 13, 2022
A client interface for Scrapinghub's API

Client interface for Scrapinghub API The scrapinghub is a Python library for communicating with the Scrapinghub API. Requirements Python 2.7 or above

Scrapinghub 184 Sep 28, 2022
A delightful and complete interface to GitHub's amazing API

ghapi A delightful and complete interface to GitHub's amazing API ghapi provides 100% always-updated coverage of the entire GitHub API. Because we aut

fast.ai 428 Jan 8, 2023
Coinbase Pro API interface framework and tooling

neutrino This project has just begun. Rudimentary API documentation Installation Prerequisites: Python 3.8+ and Git 2.33+ Navigate into a directory of

Joshua Chen 1 Dec 26, 2021
A Terminal User Interface (TUI) for automated trading with Komodo Platform's AtomicDEX-API

PytomicDEX Makerbot A Terminal User Interface (TUI) for automated trading with Komodo Platform's AtomicDEX-API Install sudo apt install wget curl jq g

null 6 Aug 25, 2022