Skip to main content

A Python wrapper for the Google Search Console API

Project description

searchconsole - Python Library for Google Search Console API

Introduction

searchconsole is a Python library that provides an easy-to-use interface for working with the Google Search Console API. With this library, you can fetch data from your Search Console account and use it to analyze your website's performance in search results.

Getting Started

Before you can use the searchconsole library, you need to generate a credentials.json file that will allow you to authenticate with the Google Search Console API. To generate this file, you can use the Credential class provided by the library.

from credential.credential import Crediential

client_id = "kjahfdnjkeahfnulkjbn38294u2389"
client_secret = "32u4393kjbjjk3b4bk331094i3jb"

# create the credentials.json file in your home directory

Credential(client_id=client_id, client_secret=client_secret)

# they will send you a new tab where you can allow the permission and get the key

# Enter your Authorization code here:-

After enter the Authorization you will get the credenial.json then after comment the Credential(client_id=client_id, client_secret=client_secret)

This will create a credentials.json file in your home directory that you can use to authenticate with the API.

Fetching Data

Once you have generated your credentials.json file, you can use the searchconsole library to fetch data from your Search Console account. Here is an example of how to fetch search analytics data for a given domain:

from searchconsole.searchconsole import Searchconsole

domain = "https://www.example.com/"
start_date = "2022-01-01"


# dont write end date they will automatically update as date.today()

authenticate with the API using credentials.json

auth_response = SearchConsole(domain=domain,start_date=start_date, credentials='credentials.json')

# print the data

# print(auth_response)

report_dict = []
for i in auth_response['rows']:
    auth_data = i
    new_dict = {
        "query": auth_data["keys"][0],
        "page": auth_data["keys"][1],
        "country": auth_data["keys"][2],
        "device": auth_data["keys"][3],
        "date": auth_data["keys"][4],
        "clicks": auth_data["clicks"],
        "impressions": auth_data["impressions"],
        "ctr": auth_data["ctr"],
        "position": auth_data["position"]
    }
    report_dict.append(new_dict)
print(report_dict)

Output:

["query", "page", "country", "device", "date","impression","clicks","position","ctr"]

{
"query":"console",
"country":"ind",
"page":"www.example.com",
"device":"Desktop",
"date":"2023-02-13",
"impression":"23",
"clicks":"23",
"position":"2",
"ctr":"2",
}

Requirements

The following dependencies are required to use the searchconsole library:

apiclient oauth2client google-api-python-client httplib2

You can add these requirements to a file called requirements.txt in the root directory of your library, with each requirement on a new line. This will make it easy for users to install all necessary dependencies by running pip install -r requirements.txt.

Unit Testing

The searchconsole library comes with a large and growing set of unit tests to ensure its functionality is working correctly. These unit tests can be found in the tests directory of the library. By running the tests, you can ensure that the library is functioning correctly and catch any errors that may arise.

Conclusion

With the searchconsole library, it is easy to fetch data from your Google Search Console account and use it to analyze your website's performance in search results. By following the steps outlined in this document, you can quickly get started with the library and begin using it to improve your website's search performance.

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

pysearchconsole-1.0.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

pysearchconsole-1.0.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file pysearchconsole-1.0.3.tar.gz.

File metadata

  • Download URL: pysearchconsole-1.0.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.28.1 setuptools/65.6.3 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.8.10

File hashes

Hashes for pysearchconsole-1.0.3.tar.gz
Algorithm Hash digest
SHA256 246df707cdc80ca1ccdfbff4899e0cd2318af1c7103d6eac7be323e22a198867
MD5 afd4f531db1bb977e81c9cc6ca5ba1e1
BLAKE2b-256 ddfe0d3ba008742d2f50efd82e1c1e437b6e328115b82bdddc975ba057c818b4

See more details on using hashes here.

File details

Details for the file pysearchconsole-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pysearchconsole-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.28.1 setuptools/65.6.3 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.8.10

File hashes

Hashes for pysearchconsole-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 019e7533e60be926cf4f350c37f9de190e6512fbc46fc6ab9d220cc7c33fc330
MD5 bc0740970845a9eb370533fe07aabd52
BLAKE2b-256 ff438ba2a53c14c62670b348357deb6f2b9b466bb54b516cd757822b3d2d3800

See more details on using hashes here.

Supported by

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