user2290820
user2290820

Reputation: 2759

How to Store Graphs?

Lets say i have a class Graph defined.

graph iowa = {.....nodes:{edges.......}}

and similar graph clusters.

once the script is running its all in the object.

But how do you store the Graph info (including whatever its attributes were defined) ? Do you save it in a db table, csv ?

Possible unsatisfactory queries: Storing multiple graphs in Neo4J (It says newo4j one instance supports one Graph at a time and to subgraph under one graph if you want to run multiple graphs)

How to store graph data in a database?

*****UPDATE*****: On Alexanders answer below on available Graph DBs, I would like to know if anyone knows of a possible fork of VertexDB where they've imported this high performance lib into any other language preferably NodeJS or Python?

http://www.dekorte.com/projects/opensource/vertexdb/docs/manual.html

And does anyone have experience reading this in using AllegroGraph vs Neo4j?

Upvotes: 7

Views: 7732

Answers (3)

Alexander Zhukov
Alexander Zhukov

Reputation: 4557

The NetworkX python library provides a couple of ways to store graph data:

  1. Serialize a graph to JSON
  2. Pickle a graph
  3. Store a graph in the gml format (link)
  4. Write graph to .dot file (link).

Storing graphs in a relational database is certainly a bad option, because of complexity of the data, complexity of graph queries, which is hard to write in SQL and the performance of these queries. Graph Databases, NOSQL and Neo4j article describes this problem in great details.

However, I think, you should really consider to use Neo4j. I hope after some investigations, you'll find a way to adapt it to your needs. After all, there are a lot of alternatives to the Neo4j.

DB-engines is a great resource to visit. There are a lot of useful information, in particular, you can compare any database with another and find the one, that best suites you.

Also, you can refer to this beautiful answer.

Update:

Since you are using structures, similar to JSON, you can consider using JSON-oriented databases, such as CouchDB or MongoDB. They have decent perfomance and scale better, than Neo4j.

Upvotes: 9

Alexander Zhukov
Alexander Zhukov

Reputation: 4557

The VertexDB implements a RESTful API to provide a query tools, so this is not gonna be a problem to use it with python, as the only thing you'll need is to write appropriate HTTP requests to the server.

Upvotes: 2

ChrisProsser
ChrisProsser

Reputation: 13088

If you have your graph data stored in a dictionary it is pretty simple to write this to a json file with json.dump(), and load it back into memory with json.load(). Or if it is a list of dictionaries you would use json.dumps() and json.loads(). Python docs here.

Upvotes: 2

Related Questions