Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

updated Python examples to explain latest syntax #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
**/.vscode
**/.__pycache__
**/*.xcscheme
**/.DS_Store
16 changes: 15 additions & 1 deletion python/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Python Examples for the Looker API

You can find Python language examples in this folder.
You can find Python language examples in this folder.

NOTE: Due to changes from version 0.1.3b8, older examples have been moved to [an archive folder](v0_1_3b7__and_earlier). Code using the older syntax can be identified by use of the `from looker_sdk import client` import, and `sdk = client.setup()` initialization command. Up to date code will use the `sdk = looker_sdk.initXX()` syntax.

## Run queries

- [Define a query with a JSON body](run_inline_query.py)

## Looker administration

- [Get a data dictionary for an explore](lookml_model_explore.py)
- [Assign groups to a role](assign_groups_to_role.py)
- [Disable users by email](disable_users_by_email.py)

# Previous SDK syntax

## Connection management

Expand Down
27 changes: 27 additions & 0 deletions python/run_inline_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import json

import looker_sdk


sdk = looker_sdk.init31()

fields = [
'hits_eventInfo.eventAction',
'hits_eventInfo.eventCategory',
]
Comment on lines +8 to +11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps useful to clarify fields and sort_order take input as <model>.<dimension|measure>.


sort_order = [
'hits_eventInto.eventCategory asc'
]

body = looker_sdk.models.WriteQuery(
model= 'google_analytics_block',
view= 'ga_sessions', # explore is what view means here
fields= fields,

)

response = sdk.run_inline_query('json', body)
data_table = json.loads(response)

print(data_table[0:10])