By the end of this tutorial, you'll be able to use Spectacles CLI to check the validity of the SQL defined in the dimensions of your Looker project.
You'll need to give Spectacles a Looker API key so it can run tests. Follow this guide for our recommendations on how to set up an API key for Spectacles.
Client ID: 4x2vgxNvCD3RYDM05gnaClient Secret: KDDwdDMm8MXyrJNqXBchbdmY
We recommend creating a separate folder and Python virtual environment for Spectacles.
If you already have a preferred approach for creating a Python virtual environment, you can skip this step!
- Create a folder called
- Create a Python virtual environment for Spectacles. If you don't already have a preferred way of doing this, we recommend pyenv-virtualenv. Follow the instructions to install pyenv and pyenv-virtualenv. Then, from your
spectaclesfolder, run the following:
pyenv virtualenv 3.8 spectacles && pyenv local spectacles
Once you've created and activated your virtual environment, run the following to install Spectacles:
pip install spectacles
spectacles folder, create a file named
config.yaml with the following contents:
# Replace with the URL of your Looker instancebase_url: https://analyzely.looker.com# Replace with the actual values from your API keyclient_id: 4x2vgxNvCD3RYDM05gnaclient_secret: KDDwdDMm8MXyrJNqXBchbdmY
Spectacles will use this config file so you don't have to type out these parameters every time.
Once you've saved your credentials to file, test the connection to Looker by running the following:
spectacles connect --config-file config.yaml
If the connection test is successful, you should see a message confirming your API and Looker instance version.
Connected to Looker version 7.8.18 using Looker API 3.1
You're ready for the final step! To run the SQL Validator, you'll need:
- The name of your Looker project
- A model and explore to test
What's the name of my Looker project?
Projects are listed at the bottom of the Develop menu in Looker.
Replace your project name, model name, and explore name (separated by a
/) below, then run this command to launch the SQL Validator and test production (the default when a branch or commit isn't specified).
spectacles sql \ --config-file config.yaml \ --project my_project \ --explores my_model/my_explore
If your explore is free of SQL errors, you'll see something that looks like this.
============= Testing 1 explore [batch mode] [concurrency = 10] ============== ✓ eye_exam.users Completed SQL validation in 2 seconds.
Congratulations! If Spectacles identified any SQL errors in your explore, try fixing them and re-running the validator.