Explainable, OMOP-native knowledge graph traversal and pathfinding
Project description
Architecture
This library provides a lightweight, query-time knowledge-graph layer over an OMOP vocabulary database, with explicit separation between:
- graph access (nodes, edges, predicates),
- graph algorithms (traversal, pathfinding),
- path scoring and explanation, and
- presentation / inspection utilities.
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 and ranking with transparent scoring
- traceable explanations of why one path is preferred over another
- 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
Core Concepts
KnowledgeGraph
KnowledgeGraph is the main entry point. It wraps an existing SQLAlchemy session connected to an OMOP vocabulary schema. kg-core assumes OMOP semantics and tables.
from omop_graph.graph.kg import KnowledgeGraph
Nodes and Edges
Nodes are OMOP Concepts; Edges are OMOP Concept_Relationships
Relationships are classified into semantic kinds:
- ONTOLOGICAL
- MAPPING
- ATTRIBUTE
- VERSIONING
- METADATA
This classification drives traversal and scoring.
Traversal, Paths and Scoring
You can:
- expand neighbourhoods
- extract subgraphs
- trace traversal decisions
- control which relationship kinds are followed
- discover multiple candidate paths between concepts and rank them
- render simple HTML cards for easy interactive exploration
from omop_graph.graph.paths import find_shortest_paths
from omop_graph.extensions.omop_alchemy import ClassIDEnum
ingredient = kg.concept_id_by_code("RxNorm", "6809") # Metformin
drug = kg.concept_id_by_code("RxNorm", "860975") # Metformin 500 MG Oral Tablet
kg.concept_view(drug) # ConceptView(id=40163924, RxNorm:860975, name='24 HR metformin hydrochloride 500 MG Extended Release Oral Tablet')
kg.concept_view(ingredient) # ConceptView(id=1503297, RxNorm:6809, name='metformin')
paths, trace = find_shortest_paths(
kg,
source=drug,
target=ingredient,
predicate_kinds={
ClassIDEnum.HIERARCHICAL,
ClassIDEnum.IDENTITY,
},
max_depth=6,
traced=True,
)
ranked = rank_paths(kg, paths)
paths = kg.find_shortest_paths(
source=a,
target=b,
max_depth=6,
)
ranked = kg.rank_paths(paths)
Rendering
Outputs can be rendered as:
- plain text (CLI / logs)
- HTML (Jupyter)
- 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 for exact / fuzzy / synonym matches - TODO: embedding matches
├────── phenotypes/ # Set operations to build efficient hierarchical groupings for reasoning
├── api.py # stable public API surface
└── db/ # session helpers
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
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.0.1.tar.gz.
File metadata
- Download URL: omop_graph-1.0.1.tar.gz
- Upload date:
- Size: 326.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 |
f4e05d076d77ceeeea377d8c29945179eea079deff5583c1f1e586b5d5bd15e7
|
|
| MD5 |
b82a96515cfdbf7392d1b8413cac61af
|
|
| BLAKE2b-256 |
0bf15624c19546f834c934384716a93ac870b67a0071513cf5501131f8560ddf
|
Provenance
The following attestation bundles were made for omop_graph-1.0.1.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.0.1.tar.gz -
Subject digest:
f4e05d076d77ceeeea377d8c29945179eea079deff5583c1f1e586b5d5bd15e7 - Sigstore transparency entry: 1322155895
- Sigstore integration time:
-
Permalink:
AustralianCancerDataNetwork/omop-graph@4979942de1832ae8b13809c9b6609e05857f1f34 -
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@4979942de1832ae8b13809c9b6609e05857f1f34 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file omop_graph-1.0.1-py3-none-any.whl.
File metadata
- Download URL: omop_graph-1.0.1-py3-none-any.whl
- Upload date:
- Size: 75.8 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 |
72a4e6757ebf5fa6166a1cfd10376b76328fc7eb30b15d58168e51397bd7d957
|
|
| MD5 |
8f5fcc831cbb53c9ccfde0601bd4b359
|
|
| BLAKE2b-256 |
53dbc1a6f86ea80355317a5ca76466b6fa0b20ec02389c9cc4b360a7288ff5a7
|
Provenance
The following attestation bundles were made for omop_graph-1.0.1-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.0.1-py3-none-any.whl -
Subject digest:
72a4e6757ebf5fa6166a1cfd10376b76328fc7eb30b15d58168e51397bd7d957 - Sigstore transparency entry: 1322155981
- Sigstore integration time:
-
Permalink:
AustralianCancerDataNetwork/omop-graph@4979942de1832ae8b13809c9b6609e05857f1f34 -
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@4979942de1832ae8b13809c9b6609e05857f1f34 -
Trigger Event:
workflow_run
-
Statement type: