Skip to content
All projects
Core engineering libraryData Manager

redcap_api.py — Typed REDCap API Facade

BCHPR · 4 REDCap servers · 2023 – present

REDCap exposes one POST endpoint per project, dispatched by form parameters rather than typed routes, with no retry, no pagination, and no bulk file endpoint. This 6,561-line facade wraps 16 of those endpoints behind a typed surface of 42 exported names.

Highlights

  • Retry and backoff on 429 and 5xx, with read and connect budgets split apart — a read timeout means REDCap is still generating the export, and every retry pays that cost again.
  • REDCap has no offset pagination, so large exports are walked as date windows and reassembled in chronological order.
  • Report downloads stream to disk in 1 MB chunks and only move into place once complete, so a failure cannot leave a truncated file for the next stage to read.
  • Data-dictionary deployment defaults to a dry run and refuses to proceed without a backup directory: a metadata import replaces the dictionary wholesale, with no merge and no undo.
  • File-field operations documented against a real trap — an http:// call to the file endpoint returns a 301 that silently drops the POST body, so the call appears to succeed and returns the redirect page.
  • Bulk deletion returns a per-record accounting of succeeded, failed, and never-existed rather than a single boolean.