Skip to main content

omop-graph

omop-graph is a lightweight, opinionated knowledge-graph traversal and path-analysis library built on top of the OMOP vocabulary model.

It provides:

  • a stable KnowledgeGraph façade over OMOP concepts and relationships
  • flexible graph traversal (forward, backward, bidirectional)
  • path discovery with transparent scoring
  • traceable explanations of traversal decisions
  • multiple rendering backends (text, HTML, Mermaid)

The library is designed for:

  • interactive analysis (Jupyter)
  • reproducible research
  • downstream tooling (NLP pipelines, ontology alignment, curation tools)

Installation

pip install omop-graph

With embedding support:

pip install "omop-graph[emb]"

For larger deployments use [pgvector] or [faiss-cpu] instead (or in addition). Embedding support still needs a configured vector store, model, and provider (via oa-configurator); it isn't zero-config on its own. Full setup is covered in the omop-emb documentation.


Core Concepts

KnowledgeGraph

KnowledgeGraph is the main entry point. It takes a factory of sessions on the OMOP CDM and provides a high-level Pythonic API over the relational tables.

from omop_graph.db.session import cdm_session_factory
from omop_graph.graph.kg import KnowledgeGraph
from omop_graph.graph.nodes import LabelMatchKind

kg = KnowledgeGraph(cdm_session_factory())  # the configured cdm_db

# Lookup a concept by label
matches = kg.concept_lookup("Atrial Fibrillation", match_kind=LabelMatchKind.EXACT)
concept = matches[0]
print(f"ID: {concept.matched_concept_id}, Name: {concept.matched_concept_label}")

# Traverse the hierarchy
parents = kg.parents(concept.matched_concept_id)

Nodes and Edges

Nodes are OMOP Concepts; Edges are OMOP Concept_Relationships.

Relationships are pre-classified into semantic kinds (PredicateKind):

  • HIERARCHY — parent/child ontological relationships
  • IDENTITY — mapping to standard concepts
  • COMPOSITION — part-of relationships
  • ASSOCIATION — lateral clinical associations
  • ATTRIBUTE — concept attribute relationships

This classification drives traversal filtering and scoring.

Traversal and Paths

from omop_graph.graph.paths import find_shortest_paths
from omop_graph.extensions.omop_alchemy import PredicateKind

ingredient = kg.concept_id_by_code("RxNorm", "6809")    # Metformin
drug = kg.concept_id_by_code("RxNorm", "860975")         # Metformin 500 MG Oral Tablet

paths, trace = find_shortest_paths(
    kg,
    source=drug,
    target=ingredient,
    predicate_kinds=frozenset({PredicateKind.HIERARCHY, PredicateKind.IDENTITY}),
    max_depth=6,
    traced=True,
)

Rendering

Outputs can be rendered as plain text, HTML (Jupyter), or Mermaid diagrams. Rendering auto-detects the environment.

from IPython.display import HTML, display
from omop_graph.render import render_trace

display(HTML(render_trace(kg, trace)))

Project Structure

omop_graph/
├── graph/          # graph logic, traversal, paths, scoring
├── render/         # HTML / text / Mermaid renderers
├── reasoning/      # ontology traversal methods for specific reasoner tasks
│   ├── resolvers/  # resolve labels via exact / fuzzy / full-text / synonym search
│   └── phenotypes/ # set operations for hierarchical groupings
├── oaklib_interface/  # OAK-compliant adapter
├── api.py          # stable public API surface
└── db/             # session helpers

Configuration

omop-graph reads database connection settings from oa-configurator. It requires the CDM database configured by omop-alchemy.

Run once after installation:

omop-config init
omop-config configure omop_alchemy
omop-config configure omop_graph

See Configuration for full details.

Metadata

Release files for omop-graph 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for omop-graph 3.0.1
File Size Uploaded Provenance Actions
omop_graph-3.0.1.tar.gz 472.5 kB With provenance Details for omop_graph-3.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for omop-graph 3.0.1
File Interpreter ABI Platform Actions
omop_graph-3.0.1-py3-none-any.whl Python 3 none any Details for omop_graph-3.0.1-py3-none-any.whl

Total release size: 599.4 kB

Release files / omop_graph-3.0.1.tar.gz

Download URL omop_graph-3.0.1.tar.gz
Size 472.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0588acd7a35f7c7995907dbc7a07bb9eef921603fc44cc52565f11d3fca92786
BLAKE2b-256 checksum
How to use checksums
5767ea27a6ae3bffc5b09c0a5846438908e7f6a7fe8cbae0b34a99ccbbf4f7b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / omop_graph-3.0.1-py3-none-any.whl

Download URL omop_graph-3.0.1-py3-none-any.whl
Size 126.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6680651626a0ed8dacb3804ce80ee13debba68dfb7bb9aa01a868bf1b30ecfb4
BLAKE2b-256 checksum
How to use checksums
7afaeba3f58d00c19b6bb41feea756608c215b7a21f42fc8a8cf49651c130507
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Security for omop-graph 3.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for omop_graph-3.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page