Skip to main content

PyMogwai is a Python-based implementation of the Gremlin graph traversal language, designed to create and handle knowledge graphs entirely in Python without the need for an external Gremlin server.

Project description

PyMogwai

PyMogwai is a Python-based implementation of the Gremlin graph traversal language, designed to create and handle knowledge graphs entirely in Python without the need for an external Gremlin server.

pypi Github Actions Build PyPI Status GitHub issues GitHub closed issues API Docs License

Features

  • Supports knowledge graph creation and manipulation
  • Supports the import of arbitrary knowledge graphs with GraphML
  • Implements a variety of traversal steps
  • Enables one to traverse a graph with these steps
  • Ability to integrate data from various sources like Excel, PDF and PowerPoint
  • Simple and Pythonic API for graph operations

Demo

nicegui based demo

Getting started

Creating a Knowledge Graph

To create a graph using PyMogwai

from mogwai.core import MogwaiGraph
graph = MogwaiGraph()

# Add nodes and edges
n1 = graph.add_labeled_node("person", name="Alice", properties={"Age": 30})
n2 = graph.add_labeled_node("person", name="Bob", properties={"Age": 28})
graph.add_labeled_edge(n1, n2, "knows")

Import graphs

from mogwai.parser.graphml_converter import graphml_to_mogwaigraph

graph = graphml_to_mogwaigraph(path, node_label_key="node_label", node_name_key="node_name", edge_label_key="edge_label")

Performing Traversals

To perform any traversal of the graph, create a TraversalSource. Traversals start with a start step (V() or E()), which is followed by a sequence of steps. Note that a traversal can be executed by calling .run() on it.

from mogwai.core.traversal import MogwaiGraphTraversalSource

g = MogwaiGraphTraversalSource(graph)

# Example traversal that returns every person in the graph as a list
res = g.V().has_label("person").to_list().run()
print(res)

In order to use anonymous traversal in complex queries, import the statics module:

from mogwai.core.traversal import MogwaiGraphTraversalSource
from mogwai.core.steps.statics import *

g = MogwaiGraphTraversalSource(graph)

# Example traversal that returns every person in the graph as a list
query = g.V().has_label("person").filter_(properties('age').is_(gte(30))).to_list().by('name')
res = query.run()
print(res)

History

This project started as part of the RWTH Aachen i5 Knowledge Graph Lab SS2024 The original source is hosted at https://git.rwth-aachen.de/i5/teaching/kglab/ss2024/pymogwai 2024-08-15 the repository moved to github for better pypi integration

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

pymogwai-0.1.0.tar.gz (6.7 MB view details)

Uploaded Source

Built Distribution

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

pymogwai-0.1.0-py3-none-any.whl (1.0 MB view details)

Uploaded Python 3

File details

Details for the file pymogwai-0.1.0.tar.gz.

File metadata

  • Download URL: pymogwai-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pymogwai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 947a8ef86b945b67a67f96cd8f70b15d0e65c931035d88475d26b9e0ae21fe71
MD5 01d6c0a7920d769e7f70d3b477e3f0c7
BLAKE2b-256 1279d61bfd56337ce1f3177fd185eee0d4f4200e0378c1d946b5d3084aadd76b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymogwai-0.1.0.tar.gz:

Publisher: upload-to-pypi.yml on juupje/pyMogwai

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

File details

Details for the file pymogwai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pymogwai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pymogwai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49e93b7bd424ad06a57bc57f63bf5b3787ab601d4f68ac3d67d7b91be724e083
MD5 eb8ea7e7b31010f3c965806c2fe06332
BLAKE2b-256 25ca6ceff68d6e8adf603cdf25d93ee9e2c56192b702f1058acc23daf693e59c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymogwai-0.1.0-py3-none-any.whl:

Publisher: upload-to-pypi.yml on juupje/pyMogwai

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