### Start Flask Development Server Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/python/lookersdk-flask/README.md Launch the Flask development server, making the application accessible locally for testing and interaction. ```bash flask run ``` -------------------------------- ### Build and Develop Looker Extension Playground Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-playground/README.md These shell commands are executed in the `sdk-codegen` root and `packages/extension-playground` directories, respectively. They install project dependencies, build the SDK, and start the development server for the Extension Playground. ```Shell yarn && yarn build ``` ```Shell yarn develop ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/python/lookersdk-flask/README.md Install all necessary Python packages and libraries for the Flask application from the `requirements.txt` file. ```bash pip install -r requirements.txt ``` -------------------------------- ### Initialize Application Database Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/python/lookersdk-flask/README.md Execute the Flask command to set up and initialize the application's database schema. ```bash flask init-db ``` -------------------------------- ### Run Looker TypeScript SDK Examples with Yarn Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/typescript/README.md This snippet provides the general command-line syntax for executing Looker TypeScript SDK examples using `yarn`. It demonstrates how to specify a command and optional additional command-line options, serving as the primary method for running all provided examples. ```bash yarn {command} [other command-line options] ``` -------------------------------- ### Set up and Run API Explorer File Server Source: https://github.com/looker-open-source/sdk-codegen/blob/main/apix-files/README.md Instructions to clone the repository, install dependencies, build the project, mine source code, navigate to the APIX files directory, and start the file server locally. The server will be accessible at `http://localhost:30000`. ```sh yarn && yarn build yarn mine cd apix-files yarn serve ``` -------------------------------- ### Start Extension Tile Playground Development Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-tile-playground/README.md These shell commands provide two options to start the development server for the extension tile playground. The first command runs `yarn develop` within the `packages/extension-tile-playground` directory, while the second runs `yarn dev:tile` from the root of `sdk-codegen`. ```Shell yarn develop ``` ```Shell yarn dev:tile ``` -------------------------------- ### Execute Specific Looker TypeScript SDK Examples Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/typescript/README.md This section lists various `yarn` commands, each corresponding to a specific TypeScript SDK example. These commands allow users to run different functionalities, such as managing APIs, handling configurations, downloading dashboards, or managing schedules. Each command targets a distinct use case of the Looker API. ```bash yarn run-dual yarn run-config yarn run-sudo yarn run-tile yarn run-dashboard yarn run-bulk-disable-schedules yarn run-bulk-reassign-schedules yarn run-validate-branch yarn run-generate-api-credentials yarn run-test-connections yarn run-pdt-mapping ``` -------------------------------- ### Create and Activate Python Virtual Environment Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/python/lookersdk-flask/README.md Initialize a new Python virtual environment named `venv` and activate it to manage project-specific dependencies in isolation. ```bash virtualenv venv && source venv/bin/activate ``` -------------------------------- ### Build Looker SDK Codegen Project Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-tile-playground/README.md This shell command installs project dependencies using `yarn` and then builds the `sdk-codegen` project. This step is essential to compile the extension code before running it. ```Shell yarn && yarn build ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/python/lookersdk-flask/README.md Change the current working directory to the root of the Flask application within the cloned `sdk-codegen` repository. ```bash cd sdk-codegen/examples/python/lookersdk-flask ``` -------------------------------- ### Looker SDK Utility Methods Example Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/typescript/README.md This example (`utils.ts`) contains various utility methods for the Looker SDK. These utilities include functionalities such as finding and listing dashboards, locating tiles on dashboards, listing queryable tiles, and a general-purpose `waitForRender` routine with progress indicators. It provides common helper functions for interacting with the Looker API. ```TypeScript File: utils.ts Purpose: Provides SDK utility methods for tasks like: - Finding a dashboard by name - Listing dashboards and IDs - Finding a tile on a dashboard - Listing queryable tiles for a dashboard - General-purpose `waitForRender` routine with progress ticks ``` -------------------------------- ### LookML Model Connection Configuration Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-playground/README.md Configures the connection for the LookML model. Replace `` with an actual connection string available in your Looker instance. ```LookML connection: "" ``` -------------------------------- ### Run Looker SDK Java Example Project with Maven Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/java/example_maven/README.md Commands to compile and execute the example Java project using Maven. Ensure the '.env' file is configured with Looker client ID and secret, and the SDK JAR is in place before running these commands. ```Shell ./mvnw compile ./mvnw exec:java ``` -------------------------------- ### Run Looker SDK Java Example Project with Gradle Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/java/example_gradle/README.md This snippet shows the shell command to execute the example Java application using Gradle. It assumes the `looker-kotlin-sdk.jar` is in place and the `.env` file is configured with Looker API credentials. ```Shell ./gradlew run ``` -------------------------------- ### Custom Configuration Reader Example Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/typescript/README.md This example (`customConfigReader.ts`) demonstrates how to implement a custom method for reading configuration settings, including sensitive API credentials. It provides flexibility for managing authentication and connection details outside of standard methods. ```TypeScript File: customConfigReader.ts Purpose: Implement custom configuration reading, including API credentials. ``` -------------------------------- ### Set Flask Environment Variables Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/python/lookersdk-flask/README.md Configure the `FLASK_APP` and `FLASK_ENV` environment variables to specify the main application file and enable development mode for Flask. ```bash export FLASK_APP=app export FLASK_ENV=development ``` -------------------------------- ### Install Looker Python SDK Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb Installs the Looker SDK library using pip, the Python package installer. This is the initial step to set up the development environment for interacting with the Looker API. ```Python pip install looker_sdk ``` -------------------------------- ### Build and Run API Explorer Development Server Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-api-explorer/README.md This shell command sequence is executed from the root of the `sdk-codegen` project. It first installs dependencies (`yarn`), then builds the project (`yarn build`), and finally starts the development server for the API Explorer (`yarn dev:xapix`), making it accessible in Looker. ```sh yarn && yarn build && yarn dev:xapix ``` -------------------------------- ### Mine Looker SDK Examples Source: https://github.com/looker-open-source/sdk-codegen/blob/main/apix-files/README.md Command to specifically mine the repository's source code for examples demonstrating the usage of Looker SDKs. This process generates the `examplesIndex.json` file, which is checked into the repository. ```sh yarn mine:examples ``` -------------------------------- ### Install Project Dependencies with Yarn Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/api-explorer/README.md This command installs all necessary project dependencies using Yarn. It should be run after cloning the repository to set up the development environment for the OpenAPI Explorer. ```sh yarn install ``` -------------------------------- ### Install Looker SDK Packages for TypeScript/JavaScript Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/sdk/README.md This snippet provides commands to install the necessary Looker SDK packages using either Yarn or npm. It includes `@looker/sdk` and `@looker/sdk-rtl`, which are essential for both Node and browser environments. Additional dependencies might be required based on the project setup. ```Bash yarn add @looker/sdk @looker/sdk-rtl ``` ```Bash npm install @looker/sdk @looker/sdk-rtl ``` -------------------------------- ### Looker TypeScript SDK Package Overview Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/typescript/README.md This section describes the three core packages of the Looker TypeScript SDK: `@looker/sdk-rtl` for runtime utilities, `@looker/sdk` for API methods, and `@looker/sdk-node` for Node.js specific dependencies. It clarifies their purpose and usage context, particularly distinguishing between browser and Node.js environments. ```APIDOC @looker/sdk-rtl: Description: Contains a run time library needed to invoke the Looker API methods. Dependency: Automatically pulled in when referencing `@looker/sdk`. @looker/sdk: Description: Contains the Looker API methods. @looker/sdk-node: Description: Contains the dependencies needed to run the Looker SDK in a node environment. Usage: Required for `node` or `ts-node` environments; NOT for browser usage. ``` -------------------------------- ### Run Development Commands for Looker SDK Codegen and Hackathon Extension Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/hackathon/README.md These shell commands are crucial for setting up and running the Looker SDK Codegen project and the associated Hackathon extension locally. They cover installing dependencies, building the project, starting a local access token server, and launching the extension in development mode. ```shell yarn install ``` ```shell yarn build ``` ```shell yarn start ``` ```shell yarn dev:hack ``` -------------------------------- ### Build Kotlin Looker SDK JAR with Gradle Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/java/example_gradle/README.md This snippet provides the shell commands to navigate to the Kotlin SDK directory and build the `looker-kotlin-sdk.jar` using Gradle. This JAR is a prerequisite for running the example Java project. ```Shell cd {repolocation}/kotlin ./gradlew jar ``` -------------------------------- ### LookML Extension Manifest Definition Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-playground/README.md Defines the `manifest.lkml` file for the Extension Playground. This includes the project name, application details, the local development URL, and necessary entitlements for the extension to function correctly within Looker, such as raw API requests and core API methods. ```LookML project_name: "extension-playground" application: extension-playground { label: "Extension Playground" url: "https://localhost:8080/dist/bundle.js" entitlements: { local_storage: no navigation: no new_window: no raw_api_request: yes use_form_submit: yes use_embeds: yes core_api_methods: ["me"] external_api_urls: [] oauth2_urls: [] } } ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/looker-open-source/sdk-codegen/blob/main/bin/looker-resources-index/README.md Before using the resource management scripts, install all necessary project dependencies. This command ensures that all required packages are available for subsequent operations. ```shell yarn install ``` -------------------------------- ### Install @looker/extension-utils Package Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-utils/README.md Instructions for installing the `@looker/extension-utils` package using either Yarn or npm. This package provides essential utilities for building Looker applications. ```shell yarn add @looker/extension-utils ``` ```shell npm install @looker/extension-utils ``` -------------------------------- ### Looker SDK Configuration Example (looker.ini) Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb An example configuration for the Looker SDK using a `looker.ini` file. This file specifies the base URL for the Looker API, along with the client ID and client secret required for authentication. If this file is present in the working directory, the SDK will automatically use these settings. ```APIDOC [Looker] # Base URL for API. Do not include /api/* in the url base_url=https://self-signed.looker.com:19999 # API client id client_id=YourClientID # API client secret client_secret=YourClientSecret ``` -------------------------------- ### Create Reusable Fetch Proxy with `extensionSDK.createFetchProxy` Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-sdk/README.md The `extensionSDK.createFetchProxy` method allows creating a reusable fetch proxy object with a predefined base URL and an initial `init` object. This is particularly useful for consistently including credentials (like cookies) across multiple requests. The example shows how to configure `credentials: 'include'` and then use the created proxy for subsequent GET and POST operations. ```ts const dataServerFetchProxy = extensionSDK.createFetchProxy(postsServer, { credentials: 'include' }) // Get const response: any = await dataServerFetchProxy.fetchProxy('/posts') if (response.ok) { // Do something with response.body } else { // error handling } // Post const response = await dataServerFetchProxy.fetchProxy( '/posts', { method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify(myDataObj) if (response.ok) { // Continue } else { // Error handling } ``` -------------------------------- ### Start API Explorer Development Server Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/api-explorer/README.md This command initiates the development server for the `@looker/api-explorer` workspace. It monitors for code changes and automatically reloads, facilitating active development. Before running this, ensure all other packages have been built at least once using `yarn build`. ```sh yarn workspace @looker/api-explorer develop ``` -------------------------------- ### Looker SDK Configuration via INI File Example Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/README.rst An example `looker.ini` file structure for configuring the Looker SDK. This file specifies the base URL, client ID, client secret, and SSL verification settings. It's crucial to note the security warning about not committing this file to version control due to sensitive credentials. ```ini [Looker] # Base URL for API. Do not include /api/* in the url. If hosted on GCP, remove the :19999 leaving just https://your.cloud.looker.com base_url=https://your.looker.com:19999 # API 3 client id client_id=YourClientID # API 3 client secret client_secret=YourClientSecret # Set to false if testing locally against self-signed certs. Otherwise leave True verify_ssl=True ``` -------------------------------- ### Install Looker SDK using pipenv Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/README.rst Command to install the `looker_sdk` package into the project's virtual environment using pipenv. It specifies Python 3.8.2 and includes pre-release versions. ```bash pipenv --python 3.8.2 install --pre looker_sdk ``` -------------------------------- ### Install Looker SDK Code Generator Dependencies Source: https://github.com/looker-open-source/sdk-codegen/blob/main/README.md Commands to install the necessary Node.js dependencies and build the Looker SDK code generator project using Yarn. ```sh yarn install yarn build ``` -------------------------------- ### Install pyenv for Python Version Management Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/README.rst Provides commands to install pyenv, a tool for managing multiple Python versions. Instructions are provided for both macOS (using Homebrew) and Linux (using a curl script). pyenv is highly recommended for development environments. ```bash brew install pyenv ``` ```bash curl https://pyenv.run | bash ``` -------------------------------- ### Install pipenv for Project Dependency Management Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/README.rst Command to install pipenv, a virtual environment and dependency manager, using Homebrew. pipenv is used to manage project-specific Python environments and dependencies. ```bash brew install pipenv ``` -------------------------------- ### Example Output of Looker SDK Generation Source: https://github.com/looker-open-source/sdk-codegen/blob/main/README.md Illustrates the typical directory structure and files generated by the Looker SDK code generator for a language like Python, showing automatically generated and hand-written files. ```plain-text python looker rtl (run-time library hand-written files here) sdk methods.py (automatically generated) models.py (automatically generated) ``` -------------------------------- ### Build Kotlin Looker SDK JAR with Gradle Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/java/example_maven/README.md Commands to build the Kotlin Looker SDK JAR file from its source, which is a prerequisite for this Java project. This JAR needs to be copied into the project's 'lib' directory. ```Shell cd {repolocation}/kotlin ./gradlew jar ``` -------------------------------- ### Install Looker Extension SDK for React using npm Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-sdk-react/README.md Instructions to add the `@looker/extension-sdk-react` package to a project using the npm package manager. ```sh npm install @looker/extension-sdk-react ``` -------------------------------- ### Install Looker SDK for Node.js with npm Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/sdk-node/README.md Command to install the core Looker SDK, its runtime library, and the Node.js-specific package using npm. These packages are essential for developing applications that interact with the Looker API in a Node.js environment. ```bash npm install @looker/sdk @looker/sdk-rtl @looker/sdk-node ``` -------------------------------- ### Execute Looker Query and Print Response Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb This snippet demonstrates how to execute a previously created Looker query using its ID and retrieve the results in JSON format. It's a basic example of synchronous query execution via the SDK. ```python response = sdk.run_query(query_id=new_query.id, result_format="json") print(response) ``` -------------------------------- ### Install Looker Extension SDK for React using Yarn Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-sdk-react/README.md Instructions to add the `@looker/extension-sdk-react` package to a project using the Yarn package manager. ```sh yarn add @looker/extension-sdk-react ``` -------------------------------- ### Example Full Link Header Content Source: https://github.com/looker-open-source/sdk-codegen/blob/main/docs/paging.md This snippet provides a concrete example of a complete `Link` header as returned by the Looker API. It demonstrates the structure and content for `first`, `last`, `next`, and `prev` relations, including the `limit` and `offset` parameters in the URIs. ```HTTP ; rel="first", ; rel="last", ; rel="next", ; rel="prev" ``` -------------------------------- ### Define Looker Viz Extension Dashboard Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-tile-playground/README.md This LookML dashboard definition creates a dashboard named 'Viz Extension Demo'. It includes an element of type 'tile_extensions::vis', which integrates the custom visualization extension into the dashboard layout, displaying product count data. ```LookML - dashboard: viz_extension title: Viz Extension Demo layout: newspaper preferred_viewer: dashboards-next description: '' elements: - title: Viz Extension name: Viz Extension model: thelook explore: products type: 'tile_extensions::vis' fields: [products.count, calculation_1] sorts: [products.count desc] limit: 500 query_timezone: America/Los_Angeles row: 0 col: 8 width: 25 height: 16 ``` -------------------------------- ### Configure LookML Model Connection Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-tile-playground/README.md This LookML snippet defines the connection for a LookML model. Replace the placeholder with a valid database connection name to link your model to a data source. ```LookML connection: "" ``` -------------------------------- ### Install Looker SDK for Node.js with Yarn Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/sdk-node/README.md Command to add the Looker SDK packages, including the core SDK, runtime library, and Node.js-specific dependencies, to your project using Yarn. This prepares your environment for Looker API interactions. ```bash yarn add @looker/sdk @looker/sdk-rtl @looker/sdk-node ``` -------------------------------- ### Configure Looker SDK with Custom API Settings Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/hackathon/artifact.ipynb Demonstrates how to extend `api_settings.ApiSettings` to provide custom client ID, client secret, and base URL for the Looker SDK initialization. This allows hardcoding credentials or overriding default configuration file settings for specific SDK instances. ```python import looker_sdk from looker_sdk import api_settings class MyApiSettings(api_settings.ApiSettings): def __init__(self, *args, **kw_args): super().__init__(*args, **kw_args) def read_config(self) -> api_settings.SettingsConfig: config = super().read_config() config["client_id"] = "" config["client_secret"] = "" config["base_url"] = "https://hack.looker.com:19999" return config sdk = looker_sdk.init40(config_settings=MyApiSettings()) ``` -------------------------------- ### Configure Looker SDK API Credentials via INI File Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/sdk-node/README.md Example `looker.ini` file demonstrating how to set up the base URL, API client ID, and client secret for the Looker SDK. This configuration allows the SDK to authenticate and connect to your Looker server. ```ini [Looker] # Base URL for API. Do not include /api/* in the url base_url=https://:19999 # API 3 client id client_id=your_API3_client_id # API 3 client secret client_secret=your_API3_client_secret ``` -------------------------------- ### Initialize Go Looker SDK and Fetch User Information Source: https://github.com/looker-open-source/sdk-codegen/blob/main/go/README.md This snippet demonstrates the fundamental steps to set up the Go Looker SDK. It covers loading configuration from a file or environment, establishing an authenticated session, initializing the SDK client, and making a basic API call to retrieve the current user's details. ```Go import ( "fmt" "github.com/looker-open-source/sdk-codegen/go/rtl" v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" ) func main() { // Get settings from either looker.ini file OR environment: // looker.ini file cfg, err := rtl.NewSettingsFromFile("path/to/looker.ini", nil) // environment cfg, err := rtl.NewSettingsFromEnv() // Create new auth session with sdk settings. // The auth session will fetch/refresh the access // token from your Looker instance's `login` endpoint. session := rtl.NewAuthSession(cfg) // Create new instance of the Go Looker SDK sdk := v4.NewLookerSDK(session) // Call the Looker API e.g. get your user's name me, err := sdk.Me("", nil) fmt.Printf("Your name is %s %s\n", *(me.first), *(me.last)) } ``` -------------------------------- ### Create New User using WriteUser Model with Looker SDK (Python) Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb This example shows how to create a new user in Looker by providing user details within a `looker_sdk.models.WriteUser` instance. This approach leverages pre-built SDK models to ensure data is correctly formatted for the API, reducing potential errors. The snippet then prints the ID and first name of the newly created user. ```python user = sdk.create_user( body = looker_sdk.models.WriteUser(first_name="Jane", last_name="Doe") ) print(user.id, user.first_name) ``` -------------------------------- ### Initialize and Use Looker Kotlin SDK Source: https://github.com/looker-open-source/sdk-codegen/blob/main/kotlin/README.md This Kotlin example illustrates how to initialize the Looker SDK using settings from a `looker.ini` file and establish an authenticated session. It then demonstrates making basic API calls, such as retrieving the current user's information and a list of all users, to verify connectivity and functionality. ```kotlin import com.looker.sdk.ApiSettings import com.looker.rtl.AuthSession import com.looker.sdk.LookerSDK val localIni = "./looker.ini" val settings = ApiSettings.fromIniFile(localIni, "Looker") val session = AuthSession(settings) val sdk = LookerSDK(session) // Verify minimal SDK call works val me = sdk.ok(sdk.me()) /// continue making SDK calls val users = sdk.ok>(sdk.all_users()) ``` -------------------------------- ### Call External APIs with `extensionSDK.fetchProxy` Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-sdk/README.md The `extensionSDK.fetchProxy` method allows Looker extensions to call third-party APIs through the Looker host. It acts as a proxy to the host's `window.fetch` API. Entitlements must be defined for the extension to use this feature. This example demonstrates both GET and POST requests. ```ts // Get const response: any = await extensionSDK.fetchProxy(`${postsServer}/posts`) if (response.ok) { // Do something with response.body } else { // error handling } // Post const response = await extensionSDK.fetchProxy( `${postsServer}/posts`, { method: 'POST', headers: { "Content-Type": "application/json" }, body: JSON.stringify(myDataObj) if (response.ok) { // Continue } else { // Error handling } ``` -------------------------------- ### TypeScript SDK Mixed Mode API Response Example Source: https://github.com/looker-open-source/sdk-codegen/blob/main/docs/rationale.md This TypeScript SDK method (`run_inline_query`) demonstrates handling of a mixed-mode API response, which can return either binary content or a string. The JSDoc explicitly notes the possibility of binary content, guiding developers on potential return types. ```typescript /** * POST /queries/run/{result_format} -> string * * **Note**: Binary content may be returned by this method. */ async run_inline_query( request: Partial, options?: Partial, ) { return this.post( encodeURI(`/queries/run/${request.result_format}`), { limit: request.limit, apply_formatting: request.apply_formatting, apply_vis: request.apply_vis, cache: request.cache, image_width: request.image_width, image_height: request.image_height, generate_drill_links: request.generate_drill_links, force_production: request.force_production, cache_only: request.cache_only, path_prefix: request.path_prefix, rebuild_pdts: request.rebuild_pdts, server_table_calcs: request.server_table_calcs, }, request.body, options, ) } ``` -------------------------------- ### Looker SDK `run_look` Method API Reference Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb This entry provides a structured overview of the `run_look` method within the Looker SDK, as described in the accompanying text. It outlines the method's parameters, their types, and the available options for `result_format`, emphasizing how to find comprehensive API documentation in the `methods.py` file or via IDE inspection. ```APIDOC looker_sdk.sdk.api40.methods.run_look( look_id: int, // The ID of the Look to run. result_format: str = "json" // The desired format for the results. Options include: csv, json, json_detail, txt, html, md, xlsx, sql (raw query), png, jpg. ) -> Any // Returns the Look results in the specified format. ``` -------------------------------- ### Basic Looker SDK API Interaction in Python Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/README.rst Demonstrates how to initialize the Looker SDK for Python, retrieve user information, and create new users. It illustrates how to process API responses as both dictionary-like objects and model instances, and how to provide input using either model instances or plain dictionaries. Requires prior SDK configuration. ```python import looker_sdk # For this to work you must either have set environment variables or created a looker.ini as described below in "Configuring the SDK" sdk = looker_sdk.init40() # or init31() for the older v3.1 API my_user = sdk.me() # output can be treated like a dictionary print(my_user["first_name"]) # or a model instance (User in this case) print(my_user.first_name) # input methods can take either model instances like WriteUser sdk.create_user( body=looker_sdk.models.WriteUser(first_name="Jane", last_name="Doe") ) # or plain dictionaries sdk.create_user(body={"first_name": "Jane", "last_name": "Doe"}) ``` -------------------------------- ### Create New User using Python Dictionary with Looker SDK (Python) Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb This snippet provides an alternative method for creating a new user, using a standard Python dictionary to supply the user's first and last names. While less 'Lookery' than using SDK models, this method offers flexibility for developers comfortable with dictionary structures. The created user's ID and first name are printed upon successful creation. ```python user = sdk.create_user( body={"first_name": "Jane", "last_name": "Doe"} ) print(user.id, user.first_name) ``` -------------------------------- ### Install Python 3.8.2 using pyenv Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/README.rst Command to install a specific version of Python (3.8.2) using the pyenv version management tool. This ensures a consistent Python environment for the project. ```bash pyenv install 3.8.2 ``` -------------------------------- ### Define Looker Extension Manifest Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-tile-playground/README.md This LookML manifest defines two Looker applications, 'vis' and 'tile', for the 'tile_extensions' project. It specifies their bundle URLs, dashboard mount points, and required entitlements such as local storage, form submission, and core API methods like 'run_inline_query' for the 'tile' application. ```LookML project_name: "tile_extensions" application: vis { label: "Visualization" # file: "bundle.js" url: "https://localhost:8080/dist/bundle.js" mount_points: { dashboard_vis: yes } entitlements: { local_storage: yes use_form_submit: yes core_api_methods: [] external_api_urls: [] oauth2_urls: [] scoped_user_attributes: [] global_user_attributes: [] } } application: tile { label: "Tile" # file: "bundle.js" url: "https://localhost:8080/dist/bundle.js" mount_points: { dashboard_tile: yes } entitlements: { local_storage: yes use_form_submit: yes core_api_methods: ["run_inline_query"] external_api_urls: [] oauth2_urls: [] scoped_user_attributes: [] global_user_attributes: [] } } ``` -------------------------------- ### Conventional Commit Scope Example Source: https://github.com/looker-open-source/sdk-codegen/blob/main/CONTRIBUTING.md An example illustrating the use of an optional scope within a Conventional Commit message. The scope provides additional context by specifying a particular component, package, or section of the codebase that the change affects. ```text feat(RunIt): Now has even more colors 🌈 ``` -------------------------------- ### connectExtensionHost() Configuration Options Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-sdk/README.md Describes the optional configuration object that can be passed to `connectExtensionHost()`. This object allows specifying an initialization callback, a callback for setting the initial route, and a required Looker host version for compatibility checks. ```APIDOC connectExtensionHost(config?: object) config: initializedCallback: (error?: string) => void (optional) - Callback after host communication, receives error if initialization fails. setInitialRoute: (route: string) => void (optional) - Callback to set the initial route (likely to be removed). requiredLookerVersion: string (optional) - Specifies the minimum required Looker host version. ``` -------------------------------- ### Retrieve Current User Object with Looker SDK (Python) Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb This snippet demonstrates how to fetch the current user's information using the `sdk.me()` method. It illustrates two ways to access properties of the returned user object: using dot notation (model attribute access) and dictionary-style key access, both yielding identical results. This is a fundamental 'Hello World' equivalent for interacting with the Looker API. ```python my_user = sdk.me() #Output is an instance of the User model, but can also be read like a python dict. This applies to all Looker API calls that return Models. #Example: The following commands return identical output. Feel free to use whichever style is more comfortable for you. print(my_user.first_name) #Model dot notation print(my_user["first_name"]) #Dictionary ``` -------------------------------- ### TypeScript SDK String API Response Example Source: https://github.com/looker-open-source/sdk-codegen/blob/main/docs/rationale.md This TypeScript SDK method (`role`) serves as an example of an API call that returns a standard string-based response, such as JSON, XML, or plain text. Methods of this nature do not include specific notes about binary content in their documentation. ```typescript /** * GET /roles/{role_id} -> IRole} */ async role( /** * @param {number} role_id id of role */ role_id: number, options?: Partial, ) { return this.get( encodeURI(`/roles/${role_id}`), null, null, options, ) } ``` -------------------------------- ### Conventional Commit Message Examples Source: https://github.com/looker-open-source/sdk-codegen/blob/main/CONTRIBUTING.md Examples demonstrating the Conventional Commits specification for Pull Request titles. These titles follow a `[optional scope]: ` format and are crucial for generating CHANGELOGs and adhering to semantic versioning. Common types like 'fix', 'feat', and 'chore' are illustrated. ```text fix(BrowserSession): Fixed issue with Oauth flow feat(NewComponentName): Component to support exciting new thing chore(deps): Updated package dependency X from version y to z ``` -------------------------------- ### Verify Looker SDK Authentication in Swift Source: https://github.com/looker-open-source/sdk-codegen/blob/main/swift/looker/README.md This Swift code snippet demonstrates the basic steps to initialize the Looker SDK and verify successful authentication. It reads configuration from `looker.ini`, sets up the transport and authentication sessions, and then makes a simple API call (`sdk.me()`) to retrieve the current user's record. ```Swift import looker /// read the Looker configuration file let config = try? ApiConfig("looker.ini") /// unwrap optional config results let settings = config! /// Use the standard transport based on URLSession let xp = BaseTransport(settings) /// Use the authentication session manager to automatically handle session expiration /// See the section below for more on `AuthSession` let auth = AuthSession(settings, xp) /// Create you Looker SDK instance let sdk = LookerSDK(auth) /// Retrieve the API user record. If this return nil, your Looker server or credentials are bad let me = try? sdk.ok(sdk.me()) /// continue making SDK calls ``` -------------------------------- ### Jinja2 Template for Flask Authentication and Message Display Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/python/lookersdk-flask/app/templates/base.html This Jinja2 template defines the core structure for a Flask application's main page, handling user authentication links (login, logout, register) based on session status and displaying system messages. It serves as a foundational example for integrating user interface elements with a Python Flask backend. ```Jinja2 {% block title %}{% endblock %} - Looker SDK Flask Example [Looker SDK Flask Example](/) ============================= {% if session['user_id'] %}* **Logged in!** * **[Log Out]({{ url_for('auth.logout') }})** {% else %}* **[Register]({{ url_for('auth.register') }})** * **[Log In]({{ url_for('auth.login') }})** * [See Code](https://github.com/looker-open-source/sdk-codegen/tree/main/examples/python/looker_flask_example) {% endif %} {% block header %}{% endblock %} {% for message in get_flashed_messages() %} {{ message }} {% endfor %} {% block content %}{% endblock %} ``` -------------------------------- ### Run Existing Query by ID Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb This snippet demonstrates how to execute an existing Looker query using its ID. It uses `sdk.run_query` to fetch results in JSON format, illustrating a basic query execution without any modifications. This is useful for running queries that are already defined on the Looker instance. ```python response = sdk.run_query(query_id = second_query.id, result_format="json") print(response) ``` -------------------------------- ### Install @looker/code-editor Package Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/code-editor/README.md Instructions to add the `@looker/code-editor` package as a dependency to your project using Yarn or npm. ```sh yarn add @looker/code-editor ``` ```sh npm install @looker/code-editor ``` -------------------------------- ### Initialize Looker SDK 4.0 (Python) Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb Initializes the Looker SDK using version 4.0. When environment variables are set (as shown in the previous snippet), the `init40()` function automatically detects and uses them for configuration. Alternatively, a specific `.ini` file path can be passed as an argument to `init40()`. ```python sdk = looker_sdk.init40() print('Looker SDK 4.0 initialized successfully.') ``` -------------------------------- ### Import Looker SDK and Utility Libraries Source: https://github.com/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb Imports essential Python libraries required for the tutorial: `looker_sdk` for API interactions, `os` for managing environment variables, and `json` for handling JSON data structures. ```Python import looker_sdk #Note that the pip install required a hyphen but the import is an underscore. import os #We import os here in order to manage environment variables for the tutorial. You don't need to do this on a local system or anywhere you can more conveniently set environment variables. import json #This is a handy library for doing JSON work. ``` -------------------------------- ### Perform OAuth2 Implicit Flow Authentication Source: https://github.com/looker-open-source/sdk-codegen/blob/main/packages/extension-sdk/README.md Provides an example of initiating an OAuth2 implicit authentication flow using `extensionSDK.oauth2Authenticate`, handling both successful authentication and potential errors. ```ts try { const response = await extensionSDK.oauth2Authenticate( 'https://accounts.google.com/o/oauth2/v2/auth', { client_id: GOOGLE_CLIENT_ID, scope: GOOGLE_SCOPES, response_type: 'token', } ); const { access_token, expires_in } = response; // The user is authenticated, it does not mean the user is authorized. // There may be further work for the extension to do. } catch (error) { // The user failed to authenticate } ``` -------------------------------- ### Python Package Requirements Source: https://github.com/looker-open-source/sdk-codegen/blob/main/examples/python/cloud-function-content-cleanup-automation/requirements.txt This snippet lists the core Python packages and their specific versions required for the project to function correctly. These are typically installed using pip from a requirements.txt file. ```Python looker_sdk google-cloud-storage==2.7.0 google-api-core==2.11.0 ```