Explainable, OMOP-native knowledge graph traversal and pathfinding
Project description
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 (sqlite-vec backend, zero config):
pip install "omop-graph[emb]"
For larger deployments use [pgvector] or [faiss-cpu] instead (or in addition).
Full setup is covered in the omop-emb documentation.
Core Concepts
KnowledgeGraph
KnowledgeGraph is the main entry point. It wraps a SQLAlchemy Engine connected to an OMOP vocabulary schema and provides a high-level Pythonic API over the relational tables.
from sqlalchemy import create_engine
from omop_graph.graph.kg import KnowledgeGraph
engine = create_engine("postgresql://user:pass@localhost/omop")
kg = KnowledgeGraph(engine)
# Lookup a concept by label
match_group = kg.label_lookup("Atrial Fibrillation", fuzzy=False)
concept = match_group.best_match
print(f"ID: {concept.concept_id}, Name: {concept.matched_label}")
# Traverse the hierarchy
parents = kg.parents(concept.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 relationshipsIDENTITY— mapping to standard conceptsCOMPOSITION— part-of relationshipsASSOCIATION— lateral clinical associationsATTRIBUTE— 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.
Docker Compose
The included docker-compose.yaml provides a PostgreSQL CDM database and a Python
container with all optional backends pre-installed ([postgres,emb,pgvector,faiss-cpu]).
Default credentials work out of the box:
docker compose up
The python-graph service runs omop-config configure at startup. To override
credentials:
cp .env.example .env
docker compose up
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file omop_graph-1.2.0.tar.gz.
File metadata
- Download URL: omop_graph-1.2.0.tar.gz
- Upload date:
- Size: 430.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39e8e1cb38ba63f943d4b1ac63cc12a44a9965f5afe3eae26121014e30bb2786
|
|
| MD5 |
67ea149465eba5b8c28b6ca9c3e190a4
|
|
| BLAKE2b-256 |
23118ec63fafa26057e412992b5ca42bcc7caa17c824bf219b492b774f3f1340
|
Provenance
The following attestation bundles were made for omop_graph-1.2.0.tar.gz:
Publisher:
python-publish.yml on AustralianCancerDataNetwork/omop-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
omop_graph-1.2.0.tar.gz -
Subject digest:
39e8e1cb38ba63f943d4b1ac63cc12a44a9965f5afe3eae26121014e30bb2786 - Sigstore transparency entry: 2043698017
- Sigstore integration time:
-
Permalink:
AustralianCancerDataNetwork/omop-graph@c49867c852c2b158cc4ae5457f71a91728416880 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/AustralianCancerDataNetwork
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c49867c852c2b158cc4ae5457f71a91728416880 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file omop_graph-1.2.0-py3-none-any.whl.
File metadata
- Download URL: omop_graph-1.2.0-py3-none-any.whl
- Upload date:
- Size: 78.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f96346576875b9767f8d0c4537afb2a2aa483e3ebf519e0c84b610a05f70b1f
|
|
| MD5 |
cf0b120dbf2debfe4b75f598653b57e0
|
|
| BLAKE2b-256 |
1ab9ebcc4e818ceac2ae8ed8ca8c91fcd625dfa9219c5b1f7fbc378fb5c3cffd
|
Provenance
The following attestation bundles were made for omop_graph-1.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on AustralianCancerDataNetwork/omop-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
omop_graph-1.2.0-py3-none-any.whl -
Subject digest:
1f96346576875b9767f8d0c4537afb2a2aa483e3ebf519e0c84b610a05f70b1f - Sigstore transparency entry: 2043698041
- Sigstore integration time:
-
Permalink:
AustralianCancerDataNetwork/omop-graph@c49867c852c2b158cc4ae5457f71a91728416880 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/AustralianCancerDataNetwork
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c49867c852c2b158cc4ae5457f71a91728416880 -
Trigger Event:
workflow_dispatch
-
Statement type: