Skip to main content

GAPandas

GAPandas is a Python package that lets you query the Google Analytics reporting API and return results in Pandas DataFrames so they can be easily analysed, reported or plotted in Python applications. It is a simple wrapper to Google's official API which is designed to reduce code and simplify development, especially from Jupyter Notebook environments.

Setup

GAPandas is easy to setup. First, you need to obtain a client_secrets.json keyfile from Google Analytics in order to authenticate. Google's documentation explains how to do this. Once you have created a client_secrets.json file, download it and store it on your machine and note the path to the file.

Basic example

To make a query, authenticate by running connect.get_service() passing it the path to your client_secrets.json keyfile.

from gapandas import connect, query

service = connect.get_service('path/to/client_secrets.json')

Now you have a connection, construct an API query to pass to the API. This "payload" must include a start-date and end-date, some metrics and some dimensions stored in a Python dictionary.

The queries can sometimes be fiddly to write. I recommend using the Google Analytics Query Explorer to construct a valid API query or creating a prototype in Google Sheets. In the below example, we'll fetch sessions, pageviews and bounces by date for the past 30 days.

payload = {
    'start_date': '30daysAgo',
    'end_date': 'today',
    'metrics': 'ga:sessions, ga:pageviews, ga:bounces',
    'dimensions': 'ga:date'
}

Now you can then use the query.run_query() function to pass your payload to the API, along with the service object and your Google Analytics view ID.

results = query.run_query(service, '123456789', payload)
print(results)

By default, this will return a Pandas DataFrame containing your query results. However, by passing the optional value of 'raw' at the end of the function you can also return the raw data object. The query method also provides some other features to extract data from the raw object.

results = query.run_query(service, '123456789', payload, 'raw')

You can run multiple queries in succession and use the Pandas merge() function to connect these together. Pandas also makes it very easy to write the data to a file, such as a CSV or Excel document or write it to a database. You can use the data in reports, visualisations or machine learning models with very little code.

Download files

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

Source Distribution

gapandas-0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gapandas-0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file gapandas-0.1.tar.gz.

File metadata

  • Download URL: gapandas-0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5

File hashes

Hashes for gapandas-0.1.tar.gz
Algorithm Hash digest
SHA256 3564db9c7b5030e011a0802296361afd12ab76d93ddeff76a43cb5f9afc3bd9c
MD5 63c089324e67b2733ea35f47986bd83d
BLAKE2b-256 74d1d25f5e3ee8b8c6a38c2400dd3ac0e5c85889e24e551574c2f5672fb2ec6d

See more details on using hashes here.

File details

Details for the file gapandas-0.1-py3-none-any.whl.

File metadata

  • Download URL: gapandas-0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5

File hashes

Hashes for gapandas-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 881d15fb28b85cff1ca7aaa9a7482d66d846490f89dea3245293f2dffc7e35b4
MD5 2b1eb1235d4f8407a09083a7d62d0b31
BLAKE2b-256 1c6d7cdd9d18b72aa93d266fa83c44580693d5d8915ada2177e8d6a51ccb893e

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0

2 files

0.221

2 files

0.23

2 files

0.22

2 files

0.21

2 files

0.20

1 file

0.19

1 file

0.18

1 file

0.17

1 file

0.16

1 file

0.15

2 files

0.14

2 files

0.13

2 files

0.12

2 files

0.11

2 files

This release

0.1 This release

2 files

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