title: MessagePack and datetime
body: <p>I need a fast way to send 300 short messages a second over <code>zeromq</code> between the python multiprocessing processes. Each message needs to contain an <strong><code>ID</code></strong> and <strong><code>time.time()</code></strong></p>
  
  <p><strong><code>msgpack</code></strong> seems like the best way to serialize the dict before sending it via <code>zeromq</code>, and conveniently, <code>msgpack</code> has an example of exactly what I need, except it has a <code>datetime.datetime.now()</code>.</p>
  
  <pre><code>import datetime
  
  import msgpack
  
  useful_dict = {
      "id": 1,
      "created": datetime.datetime.now(),
  }
  
  def decode_datetime(obj):
      if b'__datetime__' in obj:
          obj = datetime.datetime.strptime(obj["as_str"], "%Y%m%dT%H:%M:%S.%f")
      return obj
  
  def encode_datetime(obj):
      if isinstance(obj, datetime.datetime):
          return {'__datetime__': True, 'as_str': obj.strftime("%Y%m%dT%H:%M:%S.%f")}
      return obj
  
  
  packed_dict = msgpack.packb(useful_dict, default=encode_datetime)
  this_dict_again = msgpack.unpackb(packed_dict, object_hook=decode_datetime)
  </code></pre>
  
  <p>The problem is that their example doesn't work, I get this error:</p>
  
  <pre><code>    obj = datetime.datetime.strptime(obj["as_str"], "%Y%m%dT%H:%M:%S.%f")
  KeyError: 'as_str'
  </code></pre>
  
  <p>Maybe because I'm on python 3.4, but I don't know what the issue with strptime. Would appreciate your help.</p>