StarThinker 2.0 Is Here

Paul Kenjora At Google
StarThinker
Published in
2 min readAug 22, 2021

The new 2.0 version of StarThinker has done away with the singleton pattern. Every task and function now takes a configuration and parameter object. The configuration contains authentication information while the parameters contain task specific values.

Note the Configuration Class is the main replacement for the prior singleton and is now a parameter to each function. The credentials along with the flag ‘user’ or ‘service’ are resolved at the moment the API call is made, retaining the ability to switch between the two for different end points.

import json# import StarThinker functions
from starthinker.util.configuration import Configuration
from starthinker.util.sheets import sheets_create
from starthinker.util.google_api import API_DBM

# initialize credentials ( replaces project singleton )
config = Configuration(user='[USER CREDENTIALS JSON OR PATH]')

# create a sheet ( note the new config parameter )
sheets_create(config, 'user', 'Test Sheet', 'Test Tab')

# list all your reports in DV360
for report in API_DBM(
config,
'user',
iterate=True
).queries().listqueries().execute():
print(json.dumps(report, indent=2, sort_keys=True))

One benefit is that multiple instances using different credentials can now be safely instantiated in parallel within the same process. Another benefit is that each task can now be used as a function, simply pass the JSON parameters in.

The update does not affect the JSON recipes, UI, Dags, or Colabs, it was mainly an architectural change contained within the python libraries and tasks. All tutorials and examples on GitHub have been updated. The prior 1.0.11 version has been packaged as a release. It is OK to install version 2.0 over a running instance of 1.0.

--

--