Skip to main content

Installation

PyGoogalytics can be installed using pip:

pip install -U pygoogalytics

Google Analytics API wrapper

client.py defines the class Client which builds googleapiclient.discovery resources for accessing Google Search Console and Google Analytics 3 (UA) data from the respective APIs, and also google.analytics.data_v1beta.BetaAnalyticsDataClient resource for accessing GA4 data, although currently this is only for testing.

Before using this python package you must create a service account and download a JSON key file following the instructions from Google. This process will also give you a service account email address, you need to add this email address to the user list for the Analytics or Search Console account for which you want to obtain data — you only need to give the service account "read" access.

A Client class can create a GoogalyticsWrapper object which has methods to access data the Google services and return a pandas dataframe.

A typical implementation will look like:

from pygoogalytics.client import Client

googalytics_client = Client(key_file_path='<path-to-your-key-file>')
g_wrapper = googalytics_client.wrapper(
  sc_domain='<search-console-domain>', 
  view_id='<ga3-view-id>', 
  ga4_property_id='<ga4-property-id>'
)

ga3_dataframe = g_wrapper.get_df(
  result='GA3', 
  start_date='2023-01-01', 
  end_date='2023-01-07', 
  metrics=['ga:itemRevenue', 'ga:itemQuantity', 'ga:users'],
  dimensions=['ga:dateHourMinute', 'ga:landingPagePath', 'ga:sourceMedium', 'ga:countryIsoCode']
)

The get_df method accepts the following values for the result argument:

  • "GSC": for Google Search Console data
  • "GA3": for Google Analytics 3 (UA) data
  • "URL": for Google Search Console URL inspection data
  • "GA4": for Google Analytics 4 data (note, this is not yet available in production)

Advantages of PyGoogalytics

  1. When using the REST API for GA3 (UA) data one is allowed to request only 10 metrics at once. The PyGoogalytics wrapper allows the passing of any number of compatible dimensions and metrics, when more than ten metrics are passed, the list is partitioned into sub-lists of length 10 and separate API calls are made for each partition, the resulting dataframes are then joined on the dimensions to create a seamless dataframe with all requested metrics.
  2. Both the Search Console and GA3 APIs can return a maximum of 100k rows of data. The PyGoogalytics wrapper automatically paginates the requests and concatenates the results to return a dataframe of arbitrary length.

Google Pandas

googlepandas.py provides the classes GADataFrame and GSCDataFrame, both children of pandas DataFrame specific to storing GA and GSC data with additional metadata fields (e.g. dimensions and metrics) and methods for adding columns and filtering by particular metrics.

Metadata

Release files for pygoogalytics 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygoogalytics 0.1.4
File Size Uploaded
pygoogalytics-0.1.4.tar.gz 23.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pygoogalytics 0.1.4
File Interpreter ABI Platform
pygoogalytics-0.1.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 46.7 kB

Release files / pygoogalytics-0.1.4.tar.gz

Download URL pygoogalytics-0.1.4.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
569c5ec2b5cea8453c33777840013c4c51f17faa009382577b9199fa4ef0652e
BLAKE2b-256 checksum
How to use checksums
9ac3671a131be598789fa945bd0ab2bbf25fee032e179e4639c17529e0665d76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / pygoogalytics-0.1.4-py2.py3-none-any.whl

Download URL pygoogalytics-0.1.4-py2.py3-none-any.whl
Size 23.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fb36535839977fd9c69db13d21181b1678f90942a770cccbcb37b1052b448e90
BLAKE2b-256 checksum
How to use checksums
a55d9d3810dad638cd2daa775503510787d6848032c316dafae9004931c69703
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

0.6.17

2 release files

0.6.16

2 release files

0.6.15

2 release files

0.6.14

2 release files

0.6.11

2 release files

0.6.10

2 release files

0.6.9

2 release files

0.6.8

2 release files

0.6.7

2 release files

0.6.6

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page