title: Deserialize Protobuf in python from class name
body: <p>How can I deserialize a protocol buffer message, knowing only the string name of the protoc-generated class?</p>
  
  <p>For some reason, the fully qualified name of the message that I get with <code>DESCRIPTOR.full_name</code> does not match the actual location of the python class, so I am unable to deserialize it with the following function:</p>
  
  <pre><code>def get_class( kls ):
      """Get class given a fully qualified name of a class"""
      parts = kls.split('.')
      module = ".".join(parts[:-1])
      m = __import__( module )
      for comp in parts[1:]:
          m = getattr(m, comp)
      return m
  </code></pre>
  
  <p>I just get <code>ImportError</code> no module (name).</p>
  
  <p>Any help appreciated.</p>
  
  <p>P.S.: In case it helps, the bigger problem I am trying to solve is to serialize the protobuf message to the database, and then deserialize it back out (I am using postgresql with sqlalchemy in this case). Since regular python pickle doesn't work - I am hoping to store a tuple <code>(message_cls_name, message_binary)</code> where <code>message_cls_name</code> is a fully qualified name of the protobuf message, and <code>message_binary</code> is a result of called <code>SerializeToString</code> on the message. The part I am not clear about is how to get the message out and deserialize it into proper protobuf class.</p>