Skip to main content

Python client for OHDSI WebAPI (MVP: info, sources, vocabulary, concept sets, cohorts).

Project description

OHDSI WebAPI Client (Python)

PyPI version Python 3.11+ License: Apache 2.0

Alpha-stage Python client for interacting with an OHDSI WebAPI instance.

MVP Scope

  • Info & health check
  • Sources listing
  • Vocabulary: concept lookup, search (basic), hierarchy (descendants)
  • Concept Set: CRUD, expression export, resolve (included concepts)
  • Cohort Definitions: CRUD, generate, job polling, inclusion stats, counts

Install (development)

poetry install

(Ensure local venv is in-project: .venv/ created via poetry.toml.)

Environment Configuration

Copy the sample environment file and customize:

cp .env.sample .env
# Edit .env with your settings

The .env file is automatically loaded when you import the package. Key settings:

  • OHDSI_WEBAPI_BASE_URL: Your WebAPI server URL
  • OHDSI_WEBAPI_AUTH_TOKEN: Authentication token (optional)
  • OHDSI_CACHE_ENABLED: Enable/disable caching (default: true)
  • OHDSI_CACHE_TTL: Cache TTL in seconds (default: 300)
  • OHDSI_CACHE_MAX_SIZE: Maximum cache entries (default: 128)
  • INTEGRATION_WEBAPI: Enable live integration tests (default: 0)

Interactive Development

The .env file works seamlessly with Poetry and IPython:

# Environment variables are automatically loaded
poetry run ipython
poetry run python your_script.py
poetry run pytest

Install (from PyPI - when published)

pip install ohdsi-webapi-client

Quickstart

from ohdsi_webapi import WebApiClient

# Uses OHDSI_WEBAPI_BASE_URL from .env if set, otherwise explicit URL
client = WebApiClient("https://atlas-demo.ohdsi.org/WebAPI")

# Check WebAPI health and version
info = client.info()
print(f"WebAPI version: {info.version}")

# List available data sources
sources = client.sources()
for src in sources:
    print(f"Source: {src.source_key} - {src.source_name}")

# Search for concepts
diabetes_concepts = client.vocabulary.search("type 2 diabetes", domain_id="Condition")
print(f"Found {len(diabetes_concepts)} diabetes concepts")

# Get a specific concept
metformin = client.vocabulary.concept(201826)  # Metformin
print(f"Concept: {metformin.concept_name}")

# Work with concept sets
concept_sets = client.conceptset()  # List all concept sets
print(f"Available concept sets: {len(concept_sets)}")

# Get vocabulary domains
domains = client.vocabulary.domains()
print(f"Available domains: {[d.domain_id for d in domains[:5]}...")

client.close()

API Design Philosophy

Predictable REST-Style Methods

This client uses a predictable naming convention that mirrors WebAPI REST endpoints exactly, making it self-documenting for developers:

REST Endpoint Python Method Description
GET /info client.info() WebAPI version and health
GET /source/sources client.sources() List data sources
GET /vocabulary/domains client.vocabulary.domains() List all domains
GET /vocabulary/concept/{id} client.vocabulary.concept(id) Get a concept
GET /conceptset/ client.conceptset() List concept sets
GET /conceptset/{id} client.conceptset(id) Get concept set by ID
GET /conceptset/{id}/expression client.conceptset_expression(id) Get concept set expression

Why This Approach:

  • Self-documenting: client.conceptset() clearly maps to GET /conceptset/
  • Predictable: If you know the REST endpoint, you know the Python method
  • Beginner-friendly: Easy to learn for engineers new to OHDSI
  • No confusion: One clear way to do each operation

See the Supported Endpoints page for the complete mapping.

Testing

Unit tests (mocked, fast)

poetry run pytest

These use respx to mock HTTP endpoints.

Live integration tests (public demo, read-only)

Disabled by default. To run:

export INTEGRATION_WEBAPI=1
export OHDSI_WEBAPI_BASE_URL=https://atlas-demo.ohdsi.org/WebAPI
poetry run pytest tests/live -q

Only GET/read-only endpoints are exercised (concept lookup & search). Write operations are intentionally excluded to avoid mutating the shared demo server.

Local full integration (future)

Spin up a local WebAPI + database (Docker) to safely test create/update/delete for concept sets and cohorts. (Compose file TBD.)

Concept & Concept Sets Summary

  • client.vocabulary.concept(id) fetches a single concept by ID
  • client.vocabulary.search(query) returns concepts matching text
  • client.vocabulary.concept_descendants(id) navigates hierarchy
  • client.conceptset() lists all concept sets
  • client.conceptset(id) gets a specific concept set
  • client.conceptset_expression(id) gets the concept set expression
  • client.conceptset_items(id) resolves expression to concrete included concepts

Additional Documentation

See the docs directory for deeper guides:

Roadmap

  • Auth strategies & configuration
  • Asynchronous job polling patterns

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ohdsi_webapi_client-0.3.0.tar.gz (32.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ohdsi_webapi_client-0.3.0-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file ohdsi_webapi_client-0.3.0.tar.gz.

File metadata

  • Download URL: ohdsi_webapi_client-0.3.0.tar.gz
  • Upload date:
  • Size: 32.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.1 Darwin/24.6.0

File hashes

Hashes for ohdsi_webapi_client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 00f79613b8a7d057fb6de08e070a58b0939ba76b617baefd466999ae7648f695
MD5 863c6bdc50eca1091d1f6b6d6e177fc0
BLAKE2b-256 cbd8b2933b7b176dffcb2322aa75d2582aa6934dbf87b58d37a1f017c9a95a8c

See more details on using hashes here.

File details

Details for the file ohdsi_webapi_client-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ohdsi_webapi_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d7efbcf292f2d735a595eb10b0127c00eef1f39020cbd9d27a4690881c28fb3
MD5 2c7f3a0571dcda9cdfb8b8c4089d1fbb
BLAKE2b-256 0dc9b16a73245411335bbc8eb4c32f41cea676971420c73377b26ca3979691be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page