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.0

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.0
File Size Uploaded
omop_graph-3.0.0.tar.gz 470.6 kB Details

Built distribution (wheel)

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

Total release size: 597.2 kB

Release files / omop_graph-3.0.0.tar.gz

Download URL omop_graph-3.0.0.tar.gz
Size 470.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2184dab10323a541b400d42c94e603f33286b36b0d66a7797ce4f35b64d82104
BLAKE2b-256 checksum
How to use checksums
2d40609efc228073c4d712a4f0328229fa1ffaef317ce180cd52189ff607090b
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 11, 2026.

Transparency log

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

Download URL omop_graph-3.0.0-py3-none-any.whl
Size 126.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7bf0c99f325ba0796c8b0ff2239e68657a08686dcdd0b34aeeda750bd4566e44
BLAKE2b-256 checksum
How to use checksums
ec14e86bfac20c51dc4f70596d5b69d1107093b96356543157d7db1a555ec262
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 11, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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