Skip to content

This repository has simple python scripts to access google products (Big Query, Cloud SQL,Google sheets, Google Analytics).

Notifications You must be signed in to change notification settings

dc-aichara/google-products-with-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repository has python scripts to access google products (Big Query, Cloud SQL,Google sheets, Google Analytics).


To access BigQuery, Cloud SQL, Google Analytics, you must have a project on google cloud platform and a service account.

How to get a project and a service account ?

See documentation for help here and here

To access Google Analytics, you must have permissions to view google analytics account [user account is sufficient]. 
To access google sheets, you must have permission to edit google sheet to be accessed. 

Usage

When you run bq.py for the first time, it will produce a link to authorize and ask to enter authorization code. Copy & paste url in browser and authorize application.

$ cd google-products-with-python

$ python3 bq.py 

   age workclass  functional_weight education  education_num       marital_status occupation  ...    race      sex capital_gain  capital_loss  hours_per_week  native_country income_bracket
0   34         ?             164309      11th              7   Married-civ-spouse          ?  ...   White   Female            0             0               8   United-States          <=50K
1   21         ?             212888      11th              7   Married-civ-spouse          ?  ...   White   Female            0             0              56   United-States          <=50K
2   28         ?             308493   HS-grad              9   Married-civ-spouse          ?  ...   White   Female            0             0              17        Honduras          <=50K
3   47         ?             331650   HS-grad              9   Married-civ-spouse          ?  ...   White   Female            0             0               8   United-States           >50K
4   22         ?              35448   HS-grad              9   Married-civ-spouse          ?  ...   White   Female            0             0              22   United-States          <=50K

$ cd google-products-with-python
# Replace credentials and database server details with your credentials and database server details in csql.py.
$ python3 csql.py

gs.py is a self explanatory python script.
To learn more, please read Medium article.

  • Get view id from your google analytics account and get client secret from google service account.
  • Replace view id and client secret path in ga.py.
  • Edit start and end dates in ga.py.
  • Edit metrics on ga.py.

References :

1. https://cloud.google.com/sql/docs/mysql/connect-external-app#python
2. https://cloud.google.com/bigquery/docs/pandas-gbq-migration
3. https://pygsheets.readthedocs.io/en/latest/index.html
4. https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py

About

This repository has simple python scripts to access google products (Big Query, Cloud SQL,Google sheets, Google Analytics).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages