title: Is there a copy constructor for Map Fields in Python Protocol Buffers?
body: <p><a href="https://developers.google.com/protocol-buffers/docs/reference/python-generated#map-fields" rel="noreferrer">Python Generated Code</a> explains most use-cases of protobuf <a href="https://developers.google.com/protocol-buffers/docs/reference/python-generated#map-fields" rel="noreferrer">map fields</a> in Python but not how to copy one map to another.</p>
  
  <p>Given simple map</p>
  
  <pre><code>message Src {
      map&lt;string, string&gt; properties = 1;
      ...
  }
  
  message Dst {
      map&lt;string, string&gt; properties = 1;
      ...
  }
  </code></pre>
  
  <p>You cannot assign a value to an embedded message field, so there's no doing:</p>
  
  <pre><code># Will not work.
  dst = Dst()
  dst.properties = src.properties
  </code></pre>
  
  <p>Nor is there an implementation of <a href="https://developers.google.com/protocol-buffers/docs/reference/python/google.protobuf.message.Message-class#CopyFrom" rel="noreferrer">CopyFrom</a> since map is not itself a message, it's a field within a message.</p>
  
  <pre><code># Will not work.
  dst = Dst()
  dst.properties.CopyFrom(src.properties)
  </code></pre>
  
  <p>I also can't copy the entire message since I only want the map.</p>
  
  <pre><code># Copies unwanted fields!
  dst = Dst()
  dst.CopyFrom(src)
  </code></pre>
  
  <p>I hope I don't have to iterate over all keys and assign one-by-one!</p>
  
  <pre><code># Iterate over map keys
  for key in src.properties:
      dst.properties[key] = src.properties[key]
  </code></pre>