Skip to main content

A wrapper for the Google Search Console API.

Project description

Google Search Console for Python

Build Status License: MIT

google-searchconsole takes the pain out of working with the Google Search Console Search Analytics Query API. It is written in Python and provides convenient features to make querying a site's search analytics data easier.

  • Authentication. We provide a few different ways to make generating credentials and authenticating with your account easier. You can use stored fies as well as a way to do the OAuth2 flow interactively.
  • Querying. Easier to query by date ranges and filter by various dimensions. No longer posting large nested JSON, the query object lets you make complex queries with ease.
  • Exploration. You can traverse your account hierarchy, with an account containing webproperties with clear permission levels.
  • Exports. Clean JSON and pandas.DataFrame outputs so you can easily analyse your data in Python or Excel.

This package is built on top of Google's own API Client and is heavily inspired, from design to implementation, by @debrouwere's fantastic google-analytics package.

Quickstart

First, install the package using:

pip3 install git+https://github.com/joshcarty/google-searchconsole

Then, create a new project in the Google Developers Console, enable the Google Search Console API under "APIs & Services". Next, create credentials for an OAuth client ID, choosing the Other Application type. Download a JSON copy of your client secrets.

After that, executing your first query is as easy as

import searchconsole
account = searchconsole.authenticate(client_config='client_secrets.json')
webproperty = account['https://www.example.com/']
report = webproperty.query.range('today', days=-7).dimension('query').get()
print(report.rows)

The above example will use your client configuration file to interactively generate your credentials.

Saving Credentials

If you wish to save your credentials, to avoid going through the OAuth consent screen in the future, you can specify a path to save them by specifying serialize='path/to/credentials.json.

When you want to authenticate a new account you run:

account = searchconsole.authenticate(client_config='client_secrets.json',
                                     serialize='credentials.json')

Which will save your credentials to a file called credentials.json.

From then on, you can authenticate with:

account = searchconsole.authenticate(client_config='client_secrets.json',
                                     credentials='credentials.json')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

searchconsole-0.0.4.tar.gz (8.2 kB view details)

Uploaded Source

File details

Details for the file searchconsole-0.0.4.tar.gz.

File metadata

  • Download URL: searchconsole-0.0.4.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.4

File hashes

Hashes for searchconsole-0.0.4.tar.gz
Algorithm Hash digest
SHA256 74b3c1603ed00fc3aaa45d99cd9c12db62db60dbfb0ac8e2c4a3cb28d37247d6
MD5 440d95ca12f4802ab6ae84f13f51877a
BLAKE2b-256 a252bf755e659d13c9b31f8a828173f996976f31487ed55ba28ef3932e8b1287

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page