What you'll achieve
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.
Before you begin
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.
Set up a local environment
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:
Once you've created and activated your virtual environment, run the following to install Spectacles:
Set up a config file
spectacles folder, create a file named
config.yaml with the following contents:
Spectacles will use this config file so you don't have to type out these parameters every time.
Test Spectacles connection to Looker
Once you've saved your credentials to file, test the connection to Looker by running the following:
If the connection test is successful, you should see a message confirming your API and Looker instance version.
Run the SQL Validator
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.
If your explore is free of SQL errors, you'll see something that looks like this.
Congratulations! If Spectacles identified any SQL errors in your explore, try fixing them and re-running the validator.