Wrapper Types

Setting values on Wrapper Types

Many of the fields on the objects in the Google Ads API are a Wrapper Type, which includes types such as StringValue and Int64Value. In the Python client library there are two ways to set the values for Wrapper types.

  1. Set the value field directly (recommended)

    All protobuf objects retrieved from the client already have Wrapper Types as values for the appropriate fields and you can set their values by reassigning their value field. For example, the name field on a Campaign object is a StringValue:

    from google.ads.google_ads import client
    campaign = client.get_type('Campaign')
    campaign.name.value = 'campaign name'
  2. Initialize a Wrapper Type and copy it onto the object

    Using the same example above, here is how you can copy an existing Wrapper Type onto a protobuf object:

    from google.ads.google_ads import client
    string_value = client.get_type('StringValue')
    campaign = client.get_type('Campaign')
    string_value.value = 'campaign name'

As you can see setting the value field on Wrapper Types is more concise and required less code. It is therefore the recommended way to update Wrapper Types in the Python client library.