From 9863446f26c6a705aa69657562f591e51c83d939 Mon Sep 17 00:00:00 2001 From: Jon Walls <8075115+ContrastingSounds@users.noreply.github.com> Date: Sun, 29 Mar 2020 12:48:08 +0100 Subject: [PATCH] updated Python examples to explain latest syntax --- .gitignore | 1 + python/README.md | 16 ++++++++++- python/run_inline_query.py | 27 +++++++++++++++++++ .../content_validator_comparison.py | 0 .../create_db_connections.py | 0 .../download_dashboard_pdf.py | 0 .../download_look.py | 0 .../download_tile.py | 0 .../logout_all_users.py | 0 .../run_look_with_filters.py | 0 .../soft_delete_dashboard.py | 0 .../test_connection.py | 0 12 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 python/run_inline_query.py rename python/{ => v0_1_3b7__and_earlier}/content_validator_comparison.py (100%) rename python/{ => v0_1_3b7__and_earlier}/create_db_connections.py (100%) rename python/{ => v0_1_3b7__and_earlier}/download_dashboard_pdf.py (100%) rename python/{ => v0_1_3b7__and_earlier}/download_look.py (100%) rename python/{ => v0_1_3b7__and_earlier}/download_tile.py (100%) rename python/{ => v0_1_3b7__and_earlier}/logout_all_users.py (100%) rename python/{ => v0_1_3b7__and_earlier}/run_look_with_filters.py (100%) rename python/{ => v0_1_3b7__and_earlier}/soft_delete_dashboard.py (100%) rename python/{ => v0_1_3b7__and_earlier}/test_connection.py (100%) diff --git a/.gitignore b/.gitignore index 61348e9c..9d59c501 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ **/.vscode **/.__pycache__ **/*.xcscheme +**/.DS_Store \ No newline at end of file diff --git a/python/README.md b/python/README.md index 22f596b9..699d3f38 100644 --- a/python/README.md +++ b/python/README.md @@ -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 diff --git a/python/run_inline_query.py b/python/run_inline_query.py new file mode 100644 index 00000000..2ca99329 --- /dev/null +++ b/python/run_inline_query.py @@ -0,0 +1,27 @@ +import json + +import looker_sdk + + +sdk = looker_sdk.init31() + +fields = [ + 'hits_eventInfo.eventAction', + 'hits_eventInfo.eventCategory', +] + +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]) diff --git a/python/content_validator_comparison.py b/python/v0_1_3b7__and_earlier/content_validator_comparison.py similarity index 100% rename from python/content_validator_comparison.py rename to python/v0_1_3b7__and_earlier/content_validator_comparison.py diff --git a/python/create_db_connections.py b/python/v0_1_3b7__and_earlier/create_db_connections.py similarity index 100% rename from python/create_db_connections.py rename to python/v0_1_3b7__and_earlier/create_db_connections.py diff --git a/python/download_dashboard_pdf.py b/python/v0_1_3b7__and_earlier/download_dashboard_pdf.py similarity index 100% rename from python/download_dashboard_pdf.py rename to python/v0_1_3b7__and_earlier/download_dashboard_pdf.py diff --git a/python/download_look.py b/python/v0_1_3b7__and_earlier/download_look.py similarity index 100% rename from python/download_look.py rename to python/v0_1_3b7__and_earlier/download_look.py diff --git a/python/download_tile.py b/python/v0_1_3b7__and_earlier/download_tile.py similarity index 100% rename from python/download_tile.py rename to python/v0_1_3b7__and_earlier/download_tile.py diff --git a/python/logout_all_users.py b/python/v0_1_3b7__and_earlier/logout_all_users.py similarity index 100% rename from python/logout_all_users.py rename to python/v0_1_3b7__and_earlier/logout_all_users.py diff --git a/python/run_look_with_filters.py b/python/v0_1_3b7__and_earlier/run_look_with_filters.py similarity index 100% rename from python/run_look_with_filters.py rename to python/v0_1_3b7__and_earlier/run_look_with_filters.py diff --git a/python/soft_delete_dashboard.py b/python/v0_1_3b7__and_earlier/soft_delete_dashboard.py similarity index 100% rename from python/soft_delete_dashboard.py rename to python/v0_1_3b7__and_earlier/soft_delete_dashboard.py diff --git a/python/test_connection.py b/python/v0_1_3b7__and_earlier/test_connection.py similarity index 100% rename from python/test_connection.py rename to python/v0_1_3b7__and_earlier/test_connection.py