Get Started Using Python with Bing Ads Services

To get started developing Bing Ads applications with Python, you can start with the provided examples or follow one of the application walkthroughs for a Web or Desktop application. The examples have been developed with the Bing Ads Python SDK and run with Python Tools for Visual Studio (PTVS) on Visual Studio Community. Your custom configuration may vary.

You will need user credentials with access to Bing Ads either in production or sandbox. For the production environment you will need a production developer token. All sandbox clients can use the universal sandbox developer token i.e., BBD37VB98. For more information, please see Get Started With the Bing Ads API and Sandbox.

To authenticate with a Microsoft Account (email address user name) in production, you must also must register an application and get the corresponding client identifier. You also need to take note of the client secret and redirect URI if you are developing a web application. For authentication details, see Authentication With the SDKs.


The Bing Ads Python SDK uses the suds-jurko-0.6 library as a proxy for all of Bing Ads web services. For more information about using Suds with Bing Ads, see Using Suds.

The Bing Ads Python SDK supports Python 2.6, 2.7, and 3.3 or higher. You should install and run one of the supported versions.

Install the SDK

To install the Bing Ads Python SDK for the first time, run the following either from your IDE or command line prompt.

pip.exe install bingads

To confirm that the Bing Ads Python SDK is installed, run the following. You should see bingads (<version>) in the output list.

pip.exe list

If you already have the Bing Ads Python SDK installed, you can run this command to get the latest bits.

pip.exe install --upgrade bingads


Once you have the Bing Ads Python SDK installed, you can either download the examples from GitHub or follow one of the application walkthroughs for a Walkthrough: Bing Ads Web Application in Python or Walkthrough: Bing Ads Desktop Application in Python application.

Using Suds

The Bing Ads Python SDK uses the suds-jurko SOAP SDK to instantiate programming elements for the Bing Ads API i.e., service operations, data objects, and value sets. You will pass Suds factory objects via either a ServiceClient, BulkServiceManager, or ReportingServiceManager class. Since Suds is included as an SDK dependency, you can use Suds directly to call any of the Bing Ads web services.

Please keep in mind the following rules, suggestions, and tips related to Suds in the Bing Ads Python SDK.

  • One of the most common exceptions we hear about is ERROR:suds.resolver:(ClassGoesHere) not-found. Usually this can be resolved by using the namespace prefix for the Suds object e.g. ns3:ArrayOfstring.


    To discover all SOAP objects with namespace prefix that are available for each service, you can print the soap client. For example, the following statements will return Campaign, AdGroup, ExpandedTextAd, and Keyword, among others.

    campaign_service = ServiceClient(
        version = 12,
        environment = ENVIRONMENT,
    print campaign_service.soap_client
  • For many objects passed to the campaign management service via Suds you can create dictionary objects. From a performance perspective, the dictionary approach is faster than the alternative service.factory.create method.

    ad_groups = {
                    'Name': "Women's Shoe Sale",
                    'AdDistribution': 'Search',
                    'EndDate': {
                        'Day': '31',
                        'Month': '12',
                        'Year': strftime("%Y", gmtime())
                    'CpcBid': {
                        'Amount': 0.09
                    'Language': 'English'
  • For derived types such as ExpandedTextAd, NegativeKeyword, and NegativeKeywordList, the Suds library requires that you use factory.create.

    ads = campaign_service.factory.create('ArrayOfAd')
    expanded_text_ad.TitlePart2='Fast & Easy Setup'
    expanded_text_ad.Text='Huge Savings on red shoes.'
    expanded_text_ad.Path2='shoe sale'
    # With FinalUrls you can separate the tracking template, custom parameters, and 
    # landing page URLs.
    # Final Mobile URLs can also be used if you want to direct the user to a different page 
    # for mobile devices.
    # Set custom parameters that are specific to this ad.
    custom_parameter1.Value='PROMO' + str(index)
  • Any non-primitive elements must be specified for the Suds client e.g. EditorialStatus of type AdEditorialStatus, even though the Bing Ads services do not require such elements.

  • Bing Ads Campaign Management service operations require that if you specify a non-primitives, it must be one of the values defined by the service i.e. it cannot be a nil element. Since Suds requires non-primitives and Bing Ads won't accept nil elements in place of an enum value, you must either set the non-primitives or they must be set to None. Also note that if the element is ready only you must set it to None. For example set expanded_text_ad.EditorialStatus=None.

To call the corresponding methods of a Bing Ads service, you can use an instance of the ServiceClient class and pass the Suds factory object. For more information, see Authentication With the SDKs.

See Also

Bing Ads Client Libraries
Bing Ads Code Examples
Bing Ads Web Service Addresses
Handling Service Errors and Exceptions