Skip to main content
Help us improve Python packaging – donate today!

Painless Google Analytics

Project Description

Gapy is a thin service account client for Google Analytics.

Get set up

First you need to create either a service account or client ID in your Google API Console. If you’re authenticating as a service account you’ll need to download your private key.

If you’re authenticating as a web or installed application you’ll need to download your client secrets file. Use the Google Developers Console to do this:

  • Create a Project for thte application, and add the Analytics API to the Enabled APIs list.
  • In “Credentials”, click “Create new Client ID”.
  • Choose “Installed Application” and type should be “Other”.
  • Once it’s generated your ID, click the new “Download JSON” button and save this file as client_secrets.json.

Then just create a gapy client and start querying.

  • storage_path is the location where you want gapy to keep the storage.db file that it will generate the first time it runs.
  • Ids, metrics and dimensions can be provided as lists or single values.
import gapy.client

# For a service account
client = gapy.client.from_private_key(
    "your account name",
    private_key="your private key",
    storage_path="path/to/storage.db")

# For a web or installed application
client = gapy.client.from_secrets_file(
    "/path/to/client_secrets.json",
    storage_path="/path/to/storage.db")
)


reach_data = client.query.get("12345",
            datetime(2012, 1, 1),
            datetime(2012, 2, 2),
            ['ga:visits', 'ga:visitors'],
            'ga:date')

Google API documentation

This library is a layer over the Google Python API. If you wish to work on it, it may be necessary to consult the Google Analytics API documentation.

Release history Release notifications

This version
History Node

1.3.6

History Node

1.3.5

History Node

1.3.4

History Node

1.3.3

History Node

1.3.2

History Node

1.3.1

History Node

1.3.0

History Node

1.2.0

History Node

1.1.0

History Node

1.0.0

History Node

0.0.9

History Node

0.0.8

History Node

0.0.7

History Node

0.0.6

History Node

0.0.5

History Node

0.0.4

History Node

0.0.3

History Node

0.0.2

History Node

0.0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
gapy-1.3.6.tar.gz (5.3 kB) Copy SHA256 hash SHA256 Source None Feb 26, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page