Package for access GA, GAM, MOAT, Qubole, Athena, S3, Rubicon APIs, BigQuery, MySQL
Project description
sroka package
Package providing simple Python access to data in:
- Google AdManager (GAM earlier DoubleClick for Publishers, DFP)
- Google Sheets
- Google BigQuery
- AWS Athena
- AWS s3
- MySQL
Stale, no longer tested:
- Google Analytics
- MOAT
- Qubole
- Rubicon
- Neo4j
Sroka library was checked to work for Python >=3.10, <=3.14.
Developers
Install requirements and enable custom githooks:
pip install -r requirements.txt
git config --local core.hooksPath .githooks/
Check style with flake8:
flake8 .
Please target Pull Requests against dev branch.
Installation
Pypi last release
pip install sroka
GitHub version (beta version)
pip install git+ssh://git@github.com/Wikia/sroka
Configuration
in home folder create ~/.sroka_config (hidden folder) file where you will store:
config.inifile based onconfig.sample.iniwith information to access Qubole, MOAT, Athena, S3 and Rubiconclient_secrets.jsonfor GA accessad_manager.jsonfor GAM accesscredentials.jsonfor Google sheets accessbigquery_credentials.jsonfor BigQuery access
Alternatively, you may set localization of your files during analysis:
from sroka.config.config import setup_env_variables
from sroka.config.config import setup_client_secret
from sroka.config.config import setup_admanager_config
from sroka.config.config import setup_bigquery_config
from sroka.config.config import setup_google_sheets_credentials
setup_env_variables('/file_path/config.ini')
setup_client_secret('/file_path/client_secrets.json')
setup_admanager_config('/file_path/ad_manager.json')
setup_bigquery_config('/file_path/bigquery_credentials.json')
setup_google_sheets_credentials('/file_path/credentials.json')
Getting GA, GAM, BigQuery and Google docs jsons with secrets
Google Analytics
- Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials.
- On the Add credentials to your project page, click the Cancel button.
- At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
- Select the Credentials tab, click the Create credentials button and select OAuth client ID.
- Select the application type Other, enter the chosen name, and click the Create button.
- Click OK to dismiss the resulting dialog.
- Click the file_download (Download JSON) button to the right of the client ID.
GAM
- Follow these instructions
- while adding a service account note that the role needs to have necessary viewing and reporting permissions.
You should end up with .json (!) file with credentials
- Make sure the Name in "OAuth 2.0 client IDs" matches the service account in "Service account keys": here
- Create GAM account as service account not a new user: https://support.google.com/admanager/answer/6078734?hl=en
- Once you have a service account, it can be used to access data in different networks. Simply add it as a new service account through GAM UI of the second network.
- Additional information can be specified in
config.inifile:
- network code - a default value that can be overwritten in a function call
- application name - custom name of your network, if not specified, a generic value will be passed.
Google drive sheets credentials
In order to authorize in Google Sheets you need to generate credentials in Google Console:
You should end up with credentials.json file that should be downloaded to ~/.sroka_config folder.
Google BigQuery credentials
Go to link and follow up instructions
within Setting up authentication section. You should end up with bigquery_credentials.json
json file that should be downloaded to ~/.sroka_config folder.
Getting credentials & access tokens
Qubole
- Find your Qubole API Token (go to user -> My Profile -> my_account -> API Token -> show)
- Copy your Qubole API Token to
config.inifile
Athena and s3 credentials
- You should have your aws_access_key_id and aws_secret_access_key from registration process in AWS console.
- s3bucket_name can be found in AWS console in Athena view when you click
Settings, there you haveQuery result location. The name of location withouts3://and/is what you need. - For Athena usage you need to set also region (AWS regional endpoint), e.g.
'us-east-1'
Rubicon credentials
- You should have your id, username and password from Rubicon
- Copy values to
config.inifile in relevant fields
MySQL connection information
- In order to connect to a remote MySQL server, you need to provide the
hostandportvalues in the configuration. If it is accessible through a unix socket, you need to provide the path to this socket instead in theunix_socketconfiguration field. - If the MySQL server is protected by user credentials, you need to provide the
userandpasswordvalues in the configuration. - You can optionally specify the database to which you want to connect in the
databaseconfiguration field.
Common issues
macOS
If you see an error like ValueError: unknown locale: UTF-8
Please add to ~/.bash_profile lines like this:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
installing sroka
-
If
PyYAMLpackage is not building correctly, it may be caused by the fact that newer versions of pip won’t uninstall the package because it’s handled by disutils. Please installPyYAMLpackage first with--ignore-installedflag. -
If numpy gets messed up during sroka installation it is probably caused by multiple versions installed. Please uninstall all using pip uninstall and then reinstall latest one.
Google APIs cached files
If you encounter RefreshError similar to
google.auth.exceptions.RefreshError: ('invalid_grant: Bad Request', '{\n "error": "invalid_grant",\n "error_description": "Bad Request"\n}')
, try removing all files from ~/.cache directory.
We advise removing all files from ~/.cache directory for each new sroka update.
Credits
All people that contributed to sroka development before going opensource (including CR and QA):
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sroka-0.1.1.tar.gz.
File metadata
- Download URL: sroka-0.1.1.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54cd15f789d660e0fc7e37574881d70eac6cb737400e0a06d9090a96dd32ba8f
|
|
| MD5 |
149cdf4353fa6480f451ade956c6fe4d
|
|
| BLAKE2b-256 |
a90f5853ae344f9cfd03c9ff2e362093ce630acd23f3d72bb110bbc9d816642c
|
File details
Details for the file sroka-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sroka-0.1.1-py3-none-any.whl
- Upload date:
- Size: 33.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cc53658c7a048a6669d6631e4b9514ac58545ffddfb8532d08af6dd9cfe09b8
|
|
| MD5 |
573dde21c77acc19771ea9a2bfaddd9d
|
|
| BLAKE2b-256 |
a0cbcc2d1b2a5e56b57c631cd288a27a5beca8fd7b7e5415907c07595a29647c
|