Simple API wrapper for Google Products
Project description
googlewrapper
General Connector Classes for Google Products
Current Wrappers Available
- Google Analytics
- Google Search Console
- Google Calendar
- Google Big Query
- Google PageSpeed API
- Google Sheets
- Google Docs
Wrappers In the Pipeline
- Gmail
- Google Maps
STEPS
- Acquire Google Credentials from API Console
- Install this package
- Create Connection in Python
- Use product wrapper to make API calls (see links to individual docs above)
Acquire Google Credentials from API Console
First we will need to get our own Google Project set up so we can get our credentials. If you don't have experience, you can do so here Google API Console
After you have your project set up, oAuth configured, and the optional service account (only for Google Big Query connections), you are good to install this package.
Make sure to download your oAuth credentials and save them to your working directory as 'client_secret.json'.
Installation
Create virtual enviornment
I recommended to create a virtualenv using the virtualenv library. Follow these steps:
install the package to main python instance
pip3 install virtualenv
actually create the virtual enviornment
python3 -m virtualenv venv
activate the enviornment
source venv/bin/activate
Now we can install the module:
pip install googlewrapper
OR
python -m pip install googlewrapper
general use for virtual environments
It is recommended to use virtualenvs when working with python and storing all your dependencies in a requirements.txt
file. When you do that, you can simply install all the necessary packages by running the command
pip install requirements.txt -r
This will attempt to install everything in that text file. Normally packages will include dependency installs automatically. For example, when you run pip install googlewrapper
all the dependencies (and unfortuneately there are quite a few) will automatically be installed.
Combining Products Examples
Example 1
Take a list of URLs from Sheets, grab Search Console Data, and import it into Big Query.
from googlewrapper import GoogleSearchConsole, GoogleSheets, GoogleBigQuery
import datetime as dt
# init our objects
sheets = GoogleSheets(YOUR_URL_HERE)
gsc = GoogleSearchConsole()
gbq = GoogleBigQuery()
# get our urls we want to pull
# remember that sheet1 is default
sites = sheets.get_column(1)
'''
this one is a bit more technical
we can pull our column Branded Words right
from sheets then assign it to a dictionary to use
in our GSC object.
Make sure that your url column is the index for
your df. This will happen by default if the urls
are in the first column in google sheets
'''
branded_list = sheets.df()['Branded Words'].to_dict()
# assign those sheets to GSC
gsc.set_sites(sites)
# assign other GSC variables
gsc.set_date(dt.date(2021,1,1))
gsc.set_dims(['page','date','query'])
# get our data
gsc_data = gsc.get_data()
# print the total clicks/impressions and avg position
# for all the sites we just pulled data for
# send them to Big Query
for site in gsc_data:
print(f"{site}'s Data\n"\
f"Clicks: {gsc_data[site]['Clicks'].sum()}\n"\
f"Impressions: {gsc_data[site]['Impressions'].sum()}\n"\
f"Avg Position: {gsc_data[site]['Position'].mean()}\n\n")
# now we will send our data into our GBQ tables for storage
# we will assign the dataset name to be our url
# we will assign table to be gsc
gbq.set_dataset(site)
gbq.set_table('gsc')
# send the data to GBQ
gbq.send(gsc_data[site])
Thanks for using my code
If you found this library useful, I'd appreciate a coffee. Thanks.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for googlewrapper-0.2.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d08a50aeb93dec96da15757d7e5f18a2519abf5e0b56ebb4d5d41547e0b3dcd1 |
|
MD5 | 6be5f2d62a4246b36c2a50d1bc7cc8d4 |
|
BLAKE2b-256 | c0942ce09cb92f49c3262648165199075fea5f7855457d411a008139fc5a659e |