Skip to content

Instantly share code, notes, and snippets.

@dbrant
Last active April 28, 2022 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbrant/6a15f79668ad36fa3648013927e31ea1 to your computer and use it in GitHub Desktop.
Save dbrant/6a15f79668ad36fa3648013927e31ea1 to your computer and use it in GitHub Desktop.
Download statistics from Google Play Store console using Google Cloud API.
import csv
from google.cloud import storage
# To install Google Cloud dependency:
# pip install --upgrade google-cloud-storage
# Private key to use for authenticating our service account:
key_file = 'playStoreAccessKey.json'
# Bucket name for our data (copy from Play Store Console):
cloud_storage_bucket = 'pubsite_prod_rev_...'
storage_client = storage.Client.from_service_account_json(key_file)
bucket = storage_client.bucket(cloud_storage_bucket)
# Which report to download:
app_package_name = 'com.my.app'
date = '202204'
dimension = 'country'
report_to_download = 'stats/installs/installs_{}_{}_{}.csv'.format(app_package_name, date, dimension)
# For a list of possible report types, see:
# https://support.google.com/googleplay/android-developer/answer/6135870#zippy=%2Cinstalls
# We can also retrieve a list of reports, based on a prefix:
#for b in bucket.list_blobs(prefix='stats/installs/installs_{}_{}'.format(app_package_name, date)):
# print("> " + b.name)
# Do the work of downloading the report and converting from CSV to usable array:
blob = bucket.blob(report_to_download)
lines = blob.download_as_bytes().decode('utf-16').split('\n')
array = list(csv.reader(lines))
# Do whatever we like with the array of data:
for row in array:
print(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment