I need to run some link prediction models on a graph database using the networkx package in python. The graph database is currently stored in Azure Cosmos DB. I have been able to connect to the database using gremlin-python package, but I cannot extract the data in any form that can be converted to a graph object for networkx. I need the vertices and all of their attributes as well as the edges connecting them.
Here’s what I have so far, which just returns an empty dataframe. The vertex information will appear in the terminal, but I cannot save it as an object. How can I extract the data from Cosmos DB into a format that can be converted to a graph object in python? Thanks.
Code:
from gremlin_python.driver import client, serializer,protocol
import pandas as pd
def get_vertices(client, vertices):
callback = client.submitAsync(vertices)
for result in callback.result():
print("\t{0}".format(result))
return(pd.DataFrame(callback.result()))
if __name__ == "__main__":
client = client.Client('<endpoint>','g',
username=="<username>”
password="<password>”
message_serializer=serializer.GraphSONSerializersV2d0())
vertices = "g.V().valueMap().by(unfold()).toList()"
Vdata = get_vertices(client, vertices)
print(Vdata.head())