title: Python: Best approach to storing object state in database?
body: <p>I need to store instances (or at least their state) in a database. The idea is that I should be able to re-create the instance on demand. Since I define the classes, I can choose how I would like to store the data.</p>
  
  <p>Consider the following diagram, inheritance diagram:</p>
  
  <pre><code>                    A
                     / \
                    B   C
                   /\   /\
                  D  E F  ...
  </code></pre>
  
  <p>The idea is that the instance can belong to any of those classes and can itself store other objects (that I have completely design control over).</p>
  
  <p>My first thought is to store the state exclusively in a dictionary, dump the dictionary into a json and store it in the database. At run time, load json from the database convert it to dictionary, create an object passing in the dictionary that get's setup and so on...</p>
  
  <p>I'm not sure if that is a good approach, and also if there are any other issues that might crop up. I already came across one, where if you use myobj.dict you don't actually get all the class' parent's attributes though...</p>
  
  <p>Any suggestions?</p>