How do you create a Protobuf Struct from a Python Dict?

Should be as simple as

from google.protobuf.struct_pb2 import Struct
from google.protobuf import json_format

s = Struct()
s.update({"key": "value"})

json_format.MessageToDict(s)

Ok, I immediately found out how to do this after writing the question. Leaving the answer for anyone else who might end up having this problem.

We have to import Struct from google.protobuf.struct_pb2. Then update will work without a problem.

Hence,

from google.protobuf.struct_pb2 import Struct

s = Struct()
s.update({"key": "value"})

will return an object with representation

fields {
  key: "key"
  value {
    string_value: "value"
  }
}