title: Represent graph data as a key-value object
body: <p>I'm starting to dig into graph databases, but i have no idea, how these graphs are stored internally. Let's say i have this graph (taken from <a href="http://en.wikipedia.org/wiki/Graph_database" rel="noreferrer">Wikipedia</a>):</p>
  
  <p><img src="https://upload.wikimedia.org/wikipedia/commons/3/3a/GraphDatabase_PropertyGraph.png" width="450" height="300" /></p>
  
  <p><strong>How do i serialize this graph as a key-value object?</strong> (a Python dict, for example)</p>
  
  <p>I imagine two dicts, one for vertices and one for edges:</p>
  
  <pre class="lang-python prettyprint-override"><code>{'vertices':
   {'1': {'Name': 'Alice', 'Age': 18},
    '2': {'Name': 'Bob', 'Age': 22},
    '3': {'Type': 'Group', 'Name': 'Chess'}},
   'edges':
   {'100': {'Label': 'knows', 'Since': '2001/10/03'},
    '101': {'Label': 'knows', 'Since': '2001/10/04'},
    '102': {'Label': 'is_member', 'Since': '2005/7/01'},
    '103': {'Label': 'Members'},
    '104': {'Label': 'Members'},
    '105': {'Label': 'is_member', 'Since': '2011/02/14'}},
   'connections': [['1', '2', '100'], ['2', '1', '101'],
                   ['1', '3', '102'], ['3', '1', '103'],
                   ['3', '2', '104'], ['2', '3', '105']]}
  </code></pre>
  
  <p>But i'm not sure, whether this is the most practical implementation. Maybe the "connections" should be inside "vertices" dict. So, what is the best way to implement graph datastore using key-value objects? What and where can i read more about it?</p>
  
  <p>Possibly related, but not a duplicate: <a href="https://stackoverflow.com/q/6376586/596361">How to represent a strange graph in some data structure</a></p>