diff --git a/examples/python/cloud-function-content-cleanup-automation/README.md b/examples/python/cloud-function-content-cleanup-automation/README.md index 095629d62..792d2a3bc 100644 --- a/examples/python/cloud-function-content-cleanup-automation/README.md +++ b/examples/python/cloud-function-content-cleanup-automation/README.md @@ -211,13 +211,13 @@ The following steps assume deployment using the Google Cloud UI Console. ```python import looker_sdk -from looker_sdk import models40 +from looker_sdk import models40 as models config_file = "looker.ini" sdk = looker_sdk.init40(config_file) def restore_soft_delete_dashboard(dashboard_id): - dashboard = models40.WriteDashboard(deleted=False) + dashboard = models.WriteDashboard(deleted=False) try: sdk.update_dashboard(str(dashboard_id), body=dashboard) print(f"Successfully restored dashboard {dashboard_id}") @@ -225,7 +225,7 @@ def restore_soft_delete_dashboard(dashboard_id): print(f"Error: {e}") def restore_soft_delete_look(look_id): - look = models40.WriteLookWithQuery(deleted=False) + look = models.WriteLookWithQuery(deleted=False) try: sdk.update_look(str(look_id), body=look) print(f"Successfully restored look {look_id}") diff --git a/examples/python/cloud-function-content-cleanup-automation/main.py b/examples/python/cloud-function-content-cleanup-automation/main.py index 321798eb6..89b08959e 100644 --- a/examples/python/cloud-function-content-cleanup-automation/main.py +++ b/examples/python/cloud-function-content-cleanup-automation/main.py @@ -12,11 +12,11 @@ - Update NOTIFICATION_EMAIL_ADDRESS (email address for content deletion notification). - Toggle dry run of automation off/on. -Last modified: March 2023 +Last modified: Feb 27 2024 """ import looker_sdk -from looker_sdk import models40 +from looker_sdk import models40 as models from looker_sdk import error from google.cloud import storage from google.cloud import exceptions @@ -85,7 +85,7 @@ def get_unused_content_query_id(days: int): """ Get a re-useable query ID for a System Activity query which returns all content that hasn't been used in at least 90 (default) days. This query ID can be used to run the query and send a schedule with the query's results. """ - unused_content_query = models40.WriteQuery( + unused_content_query = models.WriteQuery( model="system__activity", view="content_usage", fields=[ @@ -128,7 +128,7 @@ def get_deleted_content_query_id(days: int): """ Get a re-usable query ID for a System Activity query which returns all content that's been soft deleted for 90+ (default) days. This query ID can be used to run the query and send a schedule with the query's results. """ - deleted_query = models40.WriteQuery( + deleted_query = models.WriteQuery( model="system__activity", view="content_usage", fields=[ @@ -180,7 +180,7 @@ def send_content_notification(query_id: str, delete_type: str, address: str): """ created_date = datetime.today().strftime('%Y-%m-%d') - scheduled_plan_destination_body = models40.ScheduledPlanDestination( + scheduled_plan_destination_body = models.ScheduledPlanDestination( format="csv", type="email", address=address, @@ -189,7 +189,7 @@ def send_content_notification(query_id: str, delete_type: str, address: str): apply_formatting=False, apply_vis=False ) - unused_content_notification = models40.WriteScheduledPlan( + unused_content_notification = models.WriteScheduledPlan( name=f"[Looker Automation] {delete_type.capitalize()} deleted content ({created_date}).", query_id=query_id, scheduled_plan_destination=[ @@ -230,8 +230,8 @@ def get_look_ids(content: list): def soft_delete_dashboard(dashboard_id: str): """ Soft delete the given dashboard. """ # todo: to toggle off safe mode and soft delete dashboards, comment out `deleted=False`` line and uncomment `deleted=True` line - dashboard = models40.WriteDashboard(deleted=False) - # dashboard = models40.WriteDashboard(deleted=True) + dashboard = models.WriteDashboard(deleted=False) + # dashboard = models.WriteDashboard(deleted=True) try: sdk.update_dashboard(dashboard_id, body=dashboard) print(f"Successfully soft deleted dashboard: {dashboard_id}") @@ -242,8 +242,8 @@ def soft_delete_dashboard(dashboard_id: str): def soft_delete_look(look_id: str): """ Soft delete the given look. """ # todo: to toggle off safe mode and soft delete Looks, comment out `deleted=False`` line and uncomment `deleted=True` line - look = models40.WriteLookWithQuery(deleted=False) - # look = models40.WriteLookWithQuery(deleted=True) + look = models.WriteLookWithQuery(deleted=False) + # look = models.WriteLookWithQuery(deleted=True) try: sdk.update_look(look_id, body=look) print(f"Successfully soft deleted Look: {look_id}") diff --git a/examples/python/content_validator_comparison.py b/examples/python/content_validator_comparison.py index a6ffb2738..a4e03d42a 100644 --- a/examples/python/content_validator_comparison.py +++ b/examples/python/content_validator_comparison.py @@ -1,5 +1,5 @@ import looker_sdk -from looker_sdk import models +from looker_sdk import models40 as models import configparser import hashlib import csv diff --git a/examples/python/create_db_connections.py b/examples/python/create_db_connections.py index 056bdd939..4422ec41a 100644 --- a/examples/python/create_db_connections.py +++ b/examples/python/create_db_connections.py @@ -1,5 +1,5 @@ import looker_sdk -from looker_sdk import models +from looker_sdk import models40 as models import base64 with open("credentials_file.json", "rb") as f: diff --git a/examples/python/download_dashboard_pdf.py b/examples/python/download_dashboard_pdf.py index 390f4e1b8..239f66ad3 100644 --- a/examples/python/download_dashboard_pdf.py +++ b/examples/python/download_dashboard_pdf.py @@ -8,7 +8,7 @@ $ python download_dashboard_pdf.py "A Test Dashboard" '{"filter1": "value1, value2", "filter2": "value3"}' $ python download_dashboard_pdf.py "A Test Dashboard" {} "single_column" -Last modified: August 25, 2021 +Last modified: Feb 27 2024 """ import json @@ -19,11 +19,10 @@ from typing import cast, Dict, Optional import looker_sdk -from looker_sdk import models +from looker_sdk import models40 as models sdk = looker_sdk.init40("../../looker.ini") - def main(): dashboard_title = sys.argv[1] if len(sys.argv) > 1 else "" filters = json.loads(sys.argv[2]) if len(sys.argv) > 2 else None diff --git a/examples/python/download_look.py b/examples/python/download_look.py index 219004d6e..443a67304 100644 --- a/examples/python/download_look.py +++ b/examples/python/download_look.py @@ -7,7 +7,7 @@ $ python download_look.py "A simple look" $ python download_look.py "A simple look" 545 842 png -Last modified: August 25, 2021 +Last modified: Feb 27 2024 """ import sys @@ -15,7 +15,7 @@ import time import looker_sdk -from looker_sdk import models +from looker_sdk import models40 as models sdk = looker_sdk.init40("../../looker.ini") diff --git a/examples/python/download_tile.py b/examples/python/download_tile.py index 6c8eea113..3bf6437fa 100644 --- a/examples/python/download_tile.py +++ b/examples/python/download_tile.py @@ -2,7 +2,7 @@ import time import looker_sdk -from looker_sdk import models +from looker_sdk import models40 as models from looker_sdk.rtl import transport class MyTransportOptions(transport.PTransportSettings): timeout = 300 diff --git a/examples/python/kill_queries.py b/examples/python/kill_queries.py index e156dc6c9..8181a9199 100644 --- a/examples/python/kill_queries.py +++ b/examples/python/kill_queries.py @@ -9,11 +9,10 @@ Authors: Lan -Last modified: July 18, 2021 +Last modified: Feb 27 2024 """ import looker_sdk -from looker_sdk import models40 sdk = looker_sdk.init40(config_file='../looker.ini', section='Looker') diff --git a/examples/python/logout_all_users.py b/examples/python/logout_all_users.py index 0c4b14c0e..187eef567 100644 --- a/examples/python/logout_all_users.py +++ b/examples/python/logout_all_users.py @@ -1,8 +1,8 @@ from typing import cast, Sequence import looker_sdk -from looker_sdk import models +from looker_sdk import models40 as models sdk = looker_sdk.init40("../../looker.ini") diff --git a/examples/python/manage_schedules.py b/examples/python/manage_schedules.py index 5e58fad18..be43f8c00 100644 --- a/examples/python/manage_schedules.py +++ b/examples/python/manage_schedules.py @@ -11,11 +11,11 @@ Authors: Lan -Last modified: July 18, 2021 +Last modified: Feb 27 2024 """ import looker_sdk -from looker_sdk import models40 +from looker_sdk import models40 as models sdk = looker_sdk.init40(config_file='../looker.ini', section='Looker') @@ -41,17 +41,17 @@ def get_schedules(id, content, user_id=None, all_users=True): def resume_schedules(id, content, enabled, user_id=None, all_users=True): - """ Pause or resume all schedules of a Look, or a dashboard - - Args: - id: id of the Looker content containing schedules - content(str): 'look', 'dashboard', or 'lookml_dashboard' - enabled (bool): set "True" to resume schedule, or "False" to pause schedule - - Notes: Schedules with "enabled = False" will disappear from Admin > Schedules in Looker UI but - their data can be retrived in Looker's System Activity. Once schedules are resumed with "enabled = True", - they will be sent once and reappear in Admin > Schedules - """ + """ Pause or resume all schedules of a Look, or a dashboard + + Args: + id: id of the Looker content containing schedules + content(str): 'look', 'dashboard', or 'lookml_dashboard' + enabled (bool): set "True" to resume schedule, or "False" to pause schedule + + Notes: Schedules with "enabled = False" will disappear from Admin > Schedules in Looker UI but + their data can be retrived in Looker's System Activity. Once schedules are resumed with "enabled = True", + they will be sent once and reappear in Admin > Schedules + """ "Get all schedules of a Looker content" schedules = get_schedules(id=id, content=content) @@ -59,7 +59,7 @@ def resume_schedules(id, content, enabled, user_id=None, all_users=True): for i in range(0, len(schedules)): sdk.update_scheduled_plan( scheduled_plan_id=schedules[i]['id'], - body=models40.WriteScheduledPlan( + body=models.WriteScheduledPlan( enabled = enabled )) @@ -70,16 +70,16 @@ def resume_schedules(id, content, enabled, user_id=None, all_users=True): def copy_schedules(from_id, to_id, content, user_id=None, all_users=True): - """ Copy schedules from one Looker content to another content. - This script has only been tested for content of the same type (i.e.: look to look, dashboard to dashboard) + """ Copy schedules from one Looker content to another content. + This script has only been tested for content of the same type (i.e.: look to look, dashboard to dashboard) - Args: - from_id: id of the Looker content containing schedules - to_id: id of the Looker content which schedules will be copied to - content(str): 'look', 'dashboard', or 'lookml_dashboard' - user_id(int, optional): If user_id is None then schedules owned by the user calling the API will be returned - all_users(bool, optional): If all_user is True then return schedules owned by all users - """ + Args: + from_id: id of the Looker content containing schedules + to_id: id of the Looker content which schedules will be copied to + content(str): 'look', 'dashboard', or 'lookml_dashboard' + user_id(int, optional): If user_id is None then schedules owned by the user calling the API will be returned + all_users(bool, optional): If all_user is True then return schedules owned by all users + """ "Get all schedules of a Looker content" schedules = get_schedules(id=from_id, content=content, user_id=user_id, all_users=all_users) @@ -88,7 +88,7 @@ def copy_schedules(from_id, to_id, content, user_id=None, all_users=True): for i in range(0, len(schedules)): # Write the base schedule plans with all required fields - body = models40.WriteScheduledPlan( + body = models.WriteScheduledPlan( # Required fields for all content type name = schedules[i]['name'], @@ -110,7 +110,7 @@ def copy_schedules(from_id, to_id, content, user_id=None, all_users=True): elif content == 'lookml_dashboard': body['lookml_dashboard_id'] = to_id - """Additional parameters can be added in the models40.WriteScheduledPlan() method for 'body', + """Additional parameters can be added in the models.WriteScheduledPlan() method for 'body', or through Python's dictionary syntax: body[parameter] = value """ diff --git a/examples/python/run_look_with_filters.py b/examples/python/run_look_with_filters.py index 4031ad820..67169d1d8 100644 --- a/examples/python/run_look_with_filters.py +++ b/examples/python/run_look_with_filters.py @@ -16,7 +16,7 @@ from typing import cast, Dict, List, Union import looker_sdk -from looker_sdk import models, error +from looker_sdk import models40 as models, error sdk = looker_sdk.init40("../../looker.ini") diff --git a/examples/python/test_connection.py b/examples/python/test_connection.py index 0cd3b46fd..7ab617138 100644 --- a/examples/python/test_connection.py +++ b/examples/python/test_connection.py @@ -7,7 +7,7 @@ Notes: Connections to Looker's internal database cannot be tested. -Last modified: August 25, 2021 +Last modified: Feb 27 2024 """ from functools import reduce @@ -15,7 +15,7 @@ from typing import cast, MutableSequence, Sequence import looker_sdk -from looker_sdk import models +from looker_sdk import models40 as models sdk = looker_sdk.init40("../../looker.ini")