A selection of Python 3 scripts to achieve various tasks in Looker
Each script is saved as a single self contained python file in the root directory. Some shared functions are in the helpers/ directory.
- Python 3.7+
- looker_sdk available on PyPI
looker.inifile stored (usually in the same directory as the scripts) and containing Looker API credentials as explained in docs on PyPI- See
looker.ini.examplefor sample format
- See
- Run
pipenv shell && pipenv installto install required modules using pipenv (recommended) or usepip install -r requirements.txt
This CLI runs all of the Looker data tests against a Looker project and displays a pass/fail result and the total % success rate.
--helpor-hto print help--silentor-sto surpress insecure request warnings--listor-lto list all available looker projects on environment--projectsor-pfollowed by a space-separated list of projects to test against. Omitting this will run against all projects--devor-dto run against the current state of the user's development branch. Omitting this will run against production
python run_data_tests.py -p fooWill run all tests in projectfoo, in production modepython run_data_tests.py -d -p bar bazWill run all tests in projectsbarandbaz, in development mode
This is a CLI that runs a query containing all of the fields in an explore and surfaces any errors.
- By default, this will return on the first error discovered
- Use the
-cor--continueargument to attempt to iteratively find all errors. This uses many more API queries - NOTE Error checking is very simplistic - Looker does not surface error codes for failed queries, so we are literally looking for the string 'error' to appear in the results
-exploresor-efollowed by a space-separated list of explores to test against. Omitting this will run against all explores-modelsor-mfollowed by a space-separated list of models to test against. Omitting this will run against all models--devor-dto run against the current state of the user's development branch. Omitting this will run against production--continueor-cwill continue on errors. Omitting this will stop on the first error. Caution this is a recursive function that removes the fields causing problems and re-runs the query, so it can lead to very many API calls in cases with lots of errors
python validate_explore_sql.py -dc -e fooWill run all fields in explorefoofor all models, in development mode, continuing on errorspython validate_explore_sql.py -m barWill run all explores in modelbar, in production mode.python validate_explore_sql.py -m bar -e baz batWill run thebazandbatexplores in modelbar, in production mode.
- validate_sql.py
- Batch mode for validating explore fields in chunks
- Validate fields by name
- Improve error finding and continuation logic