Looker API with Python

Hi,
I am trying to download some dashboards through looker with Looker API. I tried multiple ways to log in looker followed by the instruction on the website, but none of them success. Can anyone provide me a basic way to first pass the authorization step of Looker API.

Example code tried:
import requests

def log_me_in(id, secret, base_url):
payload = {‘client_id’: id, ‘client_secret’: secret}
url = base_url + ‘/login’
r = requests.post(url, data=payload)
# check for successful auth
if r.status_code == 200:
token = r.json()[‘access_token’]
return token
else:
print(‘Authentication failed’)

def get_look(token, look_id, base_url):
# hard coded for json format response
url = base_url +’/looks/’ + look_id + ‘/run/json?access_token=’ + token
r = requests.get(url)
if r.status_code == 200:
for elem in r.json():
print(str(elem))

0 9 9,351
9 REPLIES 9

What error/status code are you getting when trying to run this? It might be helpful to print the r.status_code instead of just ‘Authentication Failed’, so we know what exactly is going wrong.

If you’re comfortable with not using requests, we have a semi-official Looker SDK for python, with a LOT of documentation here: https://github.com/llooker/python_sdk and it’s installable via pip install lookerapi

Our team found Eric’s how-to pretty useful if you want to continue going the requests route: article

There are 2 types of Dashboards.
1: Embedded Dashboards.
2: combinations of looks.

For type #1, I am also struggling to download the reports.
For type #2 :

We can use below link to log in , find and execute all looks of the given dashboard.

https://github.com/llooker/python_api_samples : lookerapi.py

Just to be 100% clear here, for both types, you’re referring to dashboards accessible within the Looker UI via a path like xxxxxx.looker.com/dashboards/99, right? The word “embedded” tends to refer to something more complex with Looker, but I don’t think you mean that here.

You’re right that there are two types of tiles that can be present on dashboards— There are some that are linked to Looks, and some that are just query-based tiles, and not connected to looks.

What it sounds like to me is that for type 2, you’re hitting the get_dashboard() route, and then for each dashboard_element returned, grabbing the look_id, and then hitting run_look() to execute each associated look. This would work great for look-linked tiles.

But, it sounds like that’s not working for you since you have some tiles that are “query tiles” and not look-linked. In this case, you might want to instead take the query field from the dashboard_element response rather than the look_id. If you pipe that into the run_inline_query() endpoint to execute the query for each tile, you should get the results just like if you were using look_id and run_look().

I know this thread is old, but I’m looking for stuff about the sdk and it’s super hard to find. So here are my issues:

1- the sdk you linked to was made for looker API 3.0. We are now in 3.1. Are there any issues to be aware of if we continue to use this sdk? Any plans to update it?
2- More pressing: I am unable to pip install lookerapi. I get the error
ERROR: Could not find a version that satisfies the requirement lookerapi (from versions: none)

ERROR: No matching distribution found for lookerapi

(I’m running python 3.8.0)

The lookerapi package was recently deprecated— It was never fully supported and so hadn’t been updated in a while.

There is a new package, https://pypi.org/project/looker-sdk/, which is supported & up-to-date that you can install with pip install looker_sdk. The readme is here: https://github.com/looker-open-source/sdk-codegen/blob/master/python/README.rst

I think that should resolve your issues, let me know if it doesn’t.

And, it’s duly noted that SDK info is hard to find. Now that we have fully supported SDKs we’re working on making sure all content out there is up to date, and making our documentation more accessible. Still work to be done!

Thank you! I installed the new sdk and have been trying it for a few days. Some things are working fine, but I’ve run into a problem (could it be a bug, or is it me?):
When I try to get a look or a query, the sdk is supposed to make sure that the response I get comes through in JSON format (or at least that’s what I have read in the documentation). But it isn’t. I am getting an object that looks like this (for a get look request):
LookWithQuery ( key=value, key=value…)
instead of
{key: value, key:value…}
I’ve contacted support, and they were stumped. I raised it as an issue on the github repo, but that hasn’t gotten a response either. Is the SDK not working as it should, or am I missing something?

Finally heard back from Support about this. Apparently the SDK returns these classes and you can get to the attributes with something like look.query (to get the query of that look). But that query is still not JSON. The hidden attribute __dict__ returns the JSON version of it. I don’t understand why the SDK devs would choose to do that kind of thing, considering that all calls to update or create stuff via the SDK still need things in JSON format. But at least I figured out how to do it.

Thank you for your support. I do hope that some examples for these sort of elementary things (like modifying the filters on a look or dashboard) get posted somewhere accessible soon. I saw the recording of a webinar offered by Looker about the stuff you can do with the API. I am sure that many people would like to build sites powered by Looker like the demo featured there (“Fashion.ly”) because it looks awesome. But making these things happen is fairly convoluted (unless you know the ins and outs of how Looker works on the inside - like finding out that queries are immutable!) and the documentation is scarce and the examples are nonexistent… Many will be discouraged and run to the competition!