Skip to content

Instantly share code, notes, and snippets.

@DylanBaker
Last active June 2, 2023 09:12
Show Gist options
  • Save DylanBaker/93293966d5ddcd209b4c219d667db3bb to your computer and use it in GitHub Desktop.
Save DylanBaker/93293966d5ddcd209b4c219d667db3bb to your computer and use it in GitHub Desktop.
Get LookML Validation Responses from Looker API

Test Looker LookML Validation

The script in this gist validation_results.py gets cached and non-cached LookML validation results from the Looker API and prints them out to the console. This can be helpful when debugging unexpected responses from Looker, particularly in tools like Spectacles.

To run the script, do the following:

(1) Install the necessary requirements.

pip install -U spectacles httpx asyncio

(2) Copy the file and add it to your machine. Fill out the variables on lines 16-18.

(3) Create a file with the script above and run it.

python validation_results.py

This will print out an output like below.

cached results:
{'errors': [], 'models_not_validated': [], 'computation_time': 1.3808789253234863, 'stale': False, 'project_digest': '9c26e1dedbebc9d46a0d9c8f175a4db08b8d7758'}

non-cached results:
{'errors': [], 'models_not_validated': [], 'computation_time': 2.387660026550293, 'project_digest': '9c26e1dedbebc9d46a0d9c8f175a4db08b8d7758'}
from spectacles.client import LookerClient
from spectacles.logger import ch
from spectacles.utils import compose_url
import httpx
import logging
import asyncio
async def print_validation_results():
ch.setLevel(logging.DEBUG)
async_client = httpx.AsyncClient()
client = LookerClient(
async_client=async_client,
base_url="https://your_instance.looker.com",
client_id="",
client_secret="",
)
url = compose_url(client.api_url, ["projects", "spectacles", "validate"])
cached_results = await client.get(url=url, timeout=300)
print("cached results:")
print(cached_results.text)
print("")
url = compose_url(client.api_url, ["projects", "spectacles", "validate"])
results = await client.post(url=url, timeout=300)
print("non-cached results:")
print(results.text)
if __name__ == "__main__":
asyncio.run(print_validation_results())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment