Skip to main content

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

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

omop_graph-1.1.0.tar.gz (320.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

omop_graph-1.1.0-py3-none-any.whl (76.8 kB view details)

Uploaded Python 3

File details

Details for the file omop_graph-1.1.0.tar.gz.

File metadata

  • Download URL: omop_graph-1.1.0.tar.gz
  • Upload date:
  • Size: 320.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for omop_graph-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a0728c1ff4092043bad58ae97a3c3eb57e5fa4646b137dc1b2dc3957a3716383
MD5 6752418c50b0947227c933ce7c7101a3
BLAKE2b-256 e84294db4862bd4a18acfdb1a8f5fb2e3c849a16b907a9ccdb3ca9a08a22a30f

See more details on using hashes here.

Provenance

The following attestation bundles were made for omop_graph-1.1.0.tar.gz:

Publisher: python-publish.yml on AustralianCancerDataNetwork/omop-graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file omop_graph-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: omop_graph-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 76.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for omop_graph-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 460f941ecd03daae61d36a7a9d95337bc2e2b6049e56242534ed01bde2ea2fc3
MD5 a09e6598e4ed37ac07e8f8ae0fc7c397
BLAKE2b-256 2764d21e9d4d8cffc8d2f110eb836307ee0e8ccc4125c6cfba8479ed63d71d17

See more details on using hashes here.

Provenance

The following attestation bundles were made for omop_graph-1.1.0-py3-none-any.whl:

Publisher: python-publish.yml on AustralianCancerDataNetwork/omop-graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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