2   Getting started

Using this Python client library should only need one import:

import gdata.webmastertools.service

3   Authenticating to the Webmaster Tools service

All requests are sending via a GWebmasterToolsService object.

3.2   ClientLogin username/password authentication

The following example shows how to use ClientLogin:

client = gdata.webmastertools.service.GWebmasterToolsService()client.email = 'usernamedomain.com'
client.password = '12345678'
client.source = 'Google-PythonWebmasterToolsSample-1.0')
client.ProgrammaticLogin()

Read more about Account Authentication for Installed Applications.

4   Managing sites

4.1   Retrieving a list of sites

To get a list of sites, invoke GetSitesFeed method of GWebmasterToolsService object. For example:

feed = client.GetSitesFeed()
for entry in feed.entry:
    print entry.title.text

The return value is a SitesFeed object.

4.2   Adding a site

To add a site, invoke AddSite method of GWebmasterToolsService object with being added site URI as the only parameter. For example:

entry = client.AddSite('http://www.example.com/')
print entry.title.text

The return value is a SitesEntry object.

4.3   Verifying site ownership

To verify a sites ownership, invoke VerifySite method of GWebmasterToolsService object with parameters, site URI and verification method. Accepted verification methods are htmlpage and metatag. For example:

client.VerifySite('http://www.example.com/', 'htmlpage')

In order to verify, the requirement of verifying must be done before invoking VerifySite method, which is creating a html page with specific name or adding a specific meta tag to the response at site URI. For what to create or add, check the entry.verification_method in SitesFeed.entry object.

4.4   Deleting sites

To delete a site, invoke DeleteSite method of GWebmasterToolsService object with being deleted site URI as the only parameter. For example:

client.DeleteSite('http://www.example.com/')

5   Managing site settings

Managing site settings require the site verified.

5.1   GeoLocation

Accepted locations are listed in here. Example code:

client.UpdateGeoLocation('http://www.example.com/', 'US')

Read More information about setting a geographic target.

5.2   Crawl rate

Accepted rates are slower, normal, and faster. Example code:

client.UpdateCrawlRate('http://www.example.com/', 'normal')

Read More information about crawl rate.

5.3   Preferred domain

Accepted preferred domain setting are none (default), preferwww (www.example.com) and prefernowww (http://example.com). Example code:

client.UpdatePreferredDomain('http://www.example.com/', 'preferwww')

Read More information about setting your preferred domain.

6   Managing Sitemaps

6.1   Retrieving a list of submitted Sitemaps

To get a list of sitemaps of a site, invoke GetSitemapsFeed method of GWebmasterToolsService object with site URI as the only parameter. For example:

feed = client.GetSitemapsFeed('http://www.example.com/')
for entry in feed.entry:
    print entry.title.text

The return value is a SitemapsFeed object.

6.2   Adding Sitemaps

6.2.1   Add a regular sitemap

To add a regular sitemap to a site, invoke AddSitemap method of GWebmasterToolsService object with parameters, site URI and being added sitemap URI. For example:

entry = client.AddSitemap('http://www.example.com/', 'http://www.example.com/sitemap-index.xml')
print entry.title.text

The return value is a SitemapsEntry object.

6.2.2   Add a mobile sitemap

(Broken) To add a regular sitemap to a site, invoke AddMobileSitemap method of GWebmasterToolsService object with parameters, site URI, being added mobile sitemap URI, and format name. Accepted format name are XHTML, WML, and cHTML. For example:

entry = client.AddMobileSitemap('http://www.example.com/', 'http://www.example.com/sitemap-mobile-example.xml', 'XHTML')

The return value is a SitemapsEntry object.

Read More information about Mobile Sitemaps.

6.2.3   Add a news sitemap

(Untested) To add a news sitemap to a site, invoke AddNewsSitemap method of GWebmasterToolsService object with parameters, site URI, being added news sitemap URI, and publication label(s). Publication label can be a string or a list of strings. For example:

entry = client.AddNewsSitemap('http://www.example.com/', 'http://www.example.com/sitemap-news-example.xml', 'Label')

The return value is a SitemapsEntry object.

Read More information about News Sitemaps2.

6.3   Deleting Sitemaps

To delete a sitemap from a site, invoke DeleteSitemap method of GWebmasterToolsService object with parameters, site URI, being deleted sitemap URI. For example:

client.DeleteSitemap('http://www.example.com/', 'http://www.example.com/sitemap-index.xml')

[1]http://code.google.com/p/gdata-python-client/issues/detail?id=176 is gone.
[2]https://support.google.com/webmasters/answer/74288 is gone.