Skip to main content

Implement Shortest Path (Dijkstra) with Apache AGE

Apache AGE is a PostgreSQL extension that provides graph database functionality. The goal of the Apache AGE project is to create single storage that can handle both relational and graph model data so that users can use standard ANSI SQL along with openCypher, the Graph query language. This repository hosts the development of the Python driver for this Apache extension (currently in Incubator status). Thanks for checking it out.

Apache AGE is:

  • Powerful -- AGE adds graph database support to the already popular PostgreSQL database: PostgreSQL is used by organizations including Apple, Spotify, and NASA.
  • Flexible -- AGE allows you to perform openCypher queries, which make complex queries much easier to write.
  • Intelligent -- AGE allows you to perform graph queries that are the basis for many next level web services such as fraud & intrustion detection, master data management, product recommendations, identity and relationship management, experience personalization, knowledge management and more.

Features

  • Shortest Path implemented using dijkstra algorithm
  • Used Apache AGE graph database

Installation

Requirements

sudo apt-get update
sudo apt-get install python3-dev libpq-dev
pip install --no-binary :all: psycopg2

Install via PIP

pip install apache-age-dijkstra
pip install antlr4-python3-runtime==4.9.3

Build from Source

git clone https://github.com/Munmud/apache-age-dijkstra
cd apache-age-python
python setup.py install

View Samples

Instruction

Import

from age_dijkstra import Age_Dijkstra

Making connection to postgresql (when using this docker reepository)

con = Age_Dijkstra()
con.connect(
    host="localhost",       # default is "172.17.0.2" 
    port="5430",            # default is "5432"
    dbname="postgresDB",    # default is "postgres"
    user="postgresUser",    # default is "postgres"
    password="postgresPW",  # default is "agens"
    printMessage = True     # default is False
)

Get all edges

edges = con.get_all_edge()
  • structure : { v1 : start_vertex, v2 : end_vertex, e : edge_object }

Get all vertices

nodes = []
for x in con.get_all_vertices():
    nodes.append(x['property_name'])

Create adjacent matrices using edges

init_graph = {}
for node in nodes:
    init_graph[node] = {}
for edge in edges :
    v1 = edge['v1']['vertices_property_name']
    v2 = edge['v2']['vertices_property_name']
    dist = int(edge['e']['edge_property_name'])
    init_graph
    init_graph[v1][v2] = dist

Initialized Graph

from age_dijkstra import  Graph
graph = Graph(nodes, init_graph)

Use dijkstra Algorithm

previous_nodes, shortest_path = Graph.dijkstra_algorithm(graph=graph, start_node="vertices_property_name")

Print shortest Path

Graph.print_shortest_path(previous_nodes, shortest_path, start_node="vertices_property_name", target_node="vertices_property_name")

Create Vertices

con.set_vertices(
    graph_name = "graph_name", 
    label="label_name", 
    property={"key1" : "val1",}
    )

Create Edge

con.set_edge( 
    graph_name = "graph_name", 
    label1="label_name1", 
    prop1={"key1" : "val1",}, 
    label2="label_name2", 
    prop2={"key1" : "val1",}, 
    edge_label = "Relation_name", 
    edge_prop = {"relation_property_name":"relation_property_value"}
)

For more information about Apache AGE

License

Apache-2.0 License

Metadata

Release files for apache-age-dijkstra 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apache-age-dijkstra 0.2.2
File Size Uploaded
apache-age-dijkstra-0.2.2.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for apache-age-dijkstra 0.2.2
File Interpreter ABI Platform
apache_age_dijkstra-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / apache-age-dijkstra-0.2.2.tar.gz

Download URL apache-age-dijkstra-0.2.2.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3391eccf5f5862016ed47f3a60ab406af27574e7994df7e38063eb2fa62e9672
BLAKE2b-256 checksum
How to use checksums
71ceb43e5217dada17adb132deedb3adbf32a865144f6ae6b1170543ad21c455
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / apache_age_dijkstra-0.2.2-py3-none-any.whl

Download URL apache_age_dijkstra-0.2.2-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3c7c6b3421f0d20a57d39ef11c4cf26d54cc7d53141377f50d216227ca217de
BLAKE2b-256 checksum
How to use checksums
10f2a2149182f7266deb04d14df9bde4386cb425ed69d70be36c50b1ae588263
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

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