code: def set_value(value_proto, value, exclude_from_indexes=None):
    
    value_proto.Clear()
  
    if isinstance(value, (list, tuple)):
      for sub_value in value:
        set_value(value_proto.array_value.values.add(), sub_value,
                  exclude_from_indexes)
      return  # do not set indexed for a list property.
  
    if isinstance(value, entity_pb2.Value):
      value_proto.MergeFrom(value)
    elif isinstance(value, unicode):
      value_proto.string_value = value
    elif isinstance(value, str):
      value_proto.blob_value = value
    elif isinstance(value, bool):
      value_proto.boolean_value = value
    elif isinstance(value, (int, long)):
      value_proto.integer_value = value
    elif isinstance(value, float):
      value_proto.double_value = value
    elif isinstance(value, datetime.datetime):
      to_timestamp(value, value_proto.timestamp_value)
    elif isinstance(value, entity_pb2.Key):
      value_proto.key_value.CopyFrom(value)
    elif isinstance(value, entity_pb2.Entity):
      value_proto.entity_value.CopyFrom(value)
    else:
      raise TypeError('value type: %r not supported' % (value,))
  
    if exclude_from_indexes is not None:
      value_proto.exclude_from_indexes = exclude_from_indexes
docs: Set the corresponding datastore.Value _value field for the given arg.
  
    Args:
      value_proto: datastore.Value proto message.
      value: python object or datastore.Value. (unicode value will set a
          datastore string value, str value will set a blob string value).
          Undefined behavior if value is/contains value_proto.
      exclude_from_indexes: if the value should be exclude from indexes. None
          leaves indexing as is (defaults to False if value is not a Value
          message).
  
    Raises:
      TypeError: if the given value type is not supported.