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['domainId'] 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.4.1.tar.gz (33.3 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.4.1-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ohdsi_webapi_client-0.4.1.tar.gz
  • Upload date:
  • Size: 33.3 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.4.1.tar.gz
Algorithm Hash digest
SHA256 f4b5bcda5ed94415b92935995fbc1872d1b3613deff2e7d0dd1521af5eacadb4
MD5 497d0ad28c3c1d20e372a3761ba374b4
BLAKE2b-256 650f0fb00cdd539f88940e73077d9d98ab929691db19e0c9de28de167c3bf545

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ohdsi_webapi_client-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af8f0e9704cee0e9ea62fd14e1743cea242952a7cdd680571abc25cde4bc3567
MD5 7c952d7800bf00f566faed1f66c743e8
BLAKE2b-256 d39b7381e7c8e3b66f6295bc7e6e016a3fc72f5a7eba28b7191ea371568fe57e

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