code: def RestrictFeedItemToAdGroup(client, feed_item, adgroup_id):
    
    # Get the FeedItemTargetService
    feed_item_target_service = client.GetService(
        'FeedItemTargetService', 'v201809')
  
    # Optional: Restrict the first feed item to only serve with ads for the
    # specified ad group ID.
    ad_group_target = {
        'xsi_type': 'FeedItemAdGroupTarget',
        'feedId': feed_item['feedId'],
        'feedItemId': feed_item['feedItemId'],
        'adGroupId': adgroup_id
    }
  
    operation = {'operator': 'ADD', 'operand': ad_group_target}
  
    response = feed_item_target_service.mutate([operation])
    new_ad_group_target = response['value'][0]
  
    print('Feed item target for feed ID %s and feed item ID %s was created to '
          'restrict serving to ad group ID %s' %
          (new_ad_group_target['feedId'],
           new_ad_group_target['feedItemId'],
           new_ad_group_target['adGroupId']))
docs: Restricts the feed item to an ad group.
  
    Args:
      client: an AdWordsClient instance.
      feed_item: The feed item.
      adgroup_id: The ad group ID.