• Stars
    star
    231
  • Rank 173,434 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

One SDK to rule them all, and in the codegen bind them

SDK Codegen

This Looker Open Source repository is released under the MIT license. By using this repository, you agree to the terms of that license, and acknowledge that you are doing so at your own risk.

While Looker has developed and tested this code internally, we cannot guarantee that the open-source tools used by the scripts in this repository have not been modified with malicious code.

Important - If you are using the Looker TypeScript SDK, please see the note at the bottom of this file explaining changes to dependencies and packaging.

Support

The TypeScript and Python SDKs are officially supported by Looker/Google. Issues can be logged here in the GitHub Issues page, but can also be logged with Looker Support. The other language SDKs are community supported. Issues for these should be logged only in the GitHub Issues page. Details of Looker API and SDK support can be found at https://cloud.google.com/looker/docs/api-sdk-support-policy.

Overview

This repository contains:

The parts of the Looker SDK

We hope to help people who want to use Looker as a platform get up and running quickly, largely by providing pre-built client SDKs in the most popular languages, and implementing consistency across all languages and platforms.

The Looker SDK has several parts:

  • The Looker API, described by an OpenAPI specification (e.g., the Swagger 2.x representation found at https://<your-looker-domain>:19999/api/4.0/swagger.json). The 4.0 API is our current & stable API. As of June 2022, 3.x is deprecated.

  • The Looker API Explorer, an interactive reference, accessible either stand-alone at developers.looker.com/api/explorer/, or installable into your Looker instance as an extension from the Looker Marketplace.

  • Language SDKs, "smarter" client language classes and methods to improve the experience of calling the Looker API in various popular coding languages. Some SDKs are Looker-supported whereas others are community-supported.

SDK multi-API-version support

The 4.0 version of the API is the current and stable version of the API, in addition to the 3.x API which is now deprecated.

Some SDKs support and expose both API versions in the same SDK package, including all Looker-supported SDKs.

For SDKs that support multiple API versions, there will be methods.* and models.* collections generated for each API version. Each API version is exposed under a distinct class name from which to instantiate an initial SDK object.

API-version-specific files generally use shared Run-Time Library (RTL) code in the SDK package to minimize code duplication.

Regardless of which API version you use, API credentials are unchanged, and may continue to be referred to as "API3" credentials.

Looker SDKs

Please review the following table for a breakdown of the options to initialize the desired SDK object.

SDK API 3.1 (deprecated) API 4.0 Notes
Python looker_sdk.init31() looker_sdk.init40()
TypeScript Looker31SDK(), LookerNodeSDK.init31(), or LookerBrowserSDK.init31() Looker40SDK(), LookerNodeSDK.init40() or LookerBrowserSDK.init40() Important - See information on the typescript SDK dependencies at the bottom of this file.
Kotlin Not supported LookerSDK() Community-supported SDK. Uses API 4.0 exclusively. The initializer uses an unversioned name.
Swift Not supported Looker40SDK() Community-supported SDK. Uses API 4.0 exclusively.
Look# Not supported Looker40SDK() Community-supported SDK. Uses API 4.0 exclusively.
GoLook Not supported v4.NewLookerSDK() Community-supported SDK. Uses API 4.0 exclusively.

By supporting both API versions in the same SDK package, we hope the migration path to the latest API is simplified. Both SDK versions can be used at the same time, in the same source file, which should allow for iterative work to move to the new API version.

For example:

import {
  Looker40SDK,
  Looker31SDK,
  NodeSession,
  NodeSettingsIniFile,
} from '@looker/sdk'

const settings = new NodeSettingsIniFile()
const session = new NodeSession(settings)
const sdk = new Looker40SDK(session)
const sdk31 = new Looker31SDK(session)

const me40 = await sdk.ok(sdk.me())
const me31 = await sdk.ok(sdk31.me()) // or sdk31.ok(sdk31.me())

Automatic URL encoding for input values

TL;DR: don't URL encode your inputs because the SDKs will automatically handle it.

All SDKs URL encode (also known as percent encoding) input values for passing to the API endpoints automatically. Furthermore, except for Swift, which has problematic URL decoding support, the other SDKs will avoid double-encoding inputs that may already be encoded.

Using existing, pre-generated SDKs

When a specific language SDK has been developed, Looker makes that SDK available using the standard package manager for that platform. Currently, the Python SDK and the TypeScript SDK can be installed from their respective package managers by following the instructions in their readmes.

For the other SDKs in this repository, you can copy and paste the source code into a module for your own project. Every SDK will eventually have a deployed package version.

If you want to use the generation options for an SDK, read on.

Generating an API language binding

There are three steps for generating an SDK with this project:

  • configure a looker.ini file so the Looker API specification can be retrieved from your Looker server.

    • Note: previous versions of the looker.ini file had an api_version entry. This is no longer required. The code generator project will read an api_versions value if that is found, but the SDKs ignore this value. If api_versions is not found in the ini file, it defaults to "3.1,4.0" for the generator to produce the definitions for the supported API versions.
  • install the code generator project dependencies by running:

yarn install
yarn build

The resources required to run the code generator are in package.json.

Note: If yarn is not installed, use these instructions to install it.

  • run the SDK generator with yarn gen [language]

  • Note: Generating Client SDKs for the Looker API describes the legacy, manual steps for generating an API language binding. This project replaces these manual steps, and uses an improved code generator.

Configuring looker.ini or .env

The code generator and other scripts and tests read a configuration file called looker.ini to fetch the API specification from a server. This configuration file needs to be in the root folder of the code generator.

To create looker.ini, copy looker-sample.ini to looker.ini and fill in the required values. The values for client_id and client_secret can be retrieved by navigating to https://<your_looker_endpoint>/admin/users, editing your user, editing API3 keys, and clicking the "reveal" button to view your client_id and client_secret. If there are currently no API3 credentials, they can be generated by clicking โ€œNew API3 Key.โ€

For your own source code repositories, be sure to configure your version control system to ignore the SDK configuration .ini file so it doesn't accidentally get published somewhere unauthorized people can see it.

Unlike some other OpenAPI code generators, the Looker SDK code generator never writes access information into SDK source code. All SDKs provided by Looker are designed to receive the credentials required to call API methods via a readConfig() method that returns a key/value collection, where client_id and client_secret are retrieved, and used only for the time it takes to complete a login for authentication token retrieval, then they are immediately discarded from memory.

Note: If a .env file is found, this will override values from looker.ini. To use a .env file for configuration instead, copy env-sample to .env and provide the correct values for the environment variables.

Invoke the SDK code generator with the command:

yarn gen

To always use the latest Looker API specification for SDK generation, use:

yarn wipe && yarn gen

The code generator will:

  • read the Looker API configuration(s) from the looker.ini file.

    • Note: Normally there should only be one (1) entry in looker.ini. This first ini section is what is used for the SDKs by default, and also by the code generator.
  • download (if the API specification file is not already present) the Looker API specification file(s) from the configured Looker server(s)

  • convert (if the converted file is not already present) the downloaded Swagger 2 specification file(s) to OpenAPI 3.x

  • validate the OpenAPI 3.x file(s)

  • by default, call the code generator for each active language

    • To generate one specific language SDK, use yarn gen {language}. The supported languages have a factory declared in the Generators array in codeGenerators.ts

When the generator completes successfully, the output will be similar to:

python
  looker
    rtl
      (run-time library hand-written files here)
    sdk
      methods.py (automatically generated)
      models.py (automatically generated)

Note: If you're unable to download the API specification file because you're using an instance of Looker that is self-signed and errors are thrown, you can explicitly turn off SSL verification by putting verify_ssl=false in the looker.ini file configuration section.

Using the Legacy generator

To generate a language currently not supported by Looker's SDK code generator with the OpenAPI generator:

  • configure the desired language in codeGenerators.ts.

  • use yarn legacy to call the OpenAPI generator. This will use the OpenAPI generator to output files to the ./api/* path

Additional scripts

Use

yarn run

to see the list of all scripts that can be run by the code generator.

After generation, the generated code might not conform with the code standards. Changes cannot be committed until they pass the lint tests. This can be checked with the following:

yarn lint

For a faster run, only the modified files can be checked with any of these commands:

yarn lint-changed
yarn lint -q
yarn lint --quick

Fixes can automagically be applied with one of the following:

yarn lint-changed-fix
yarn lint -q -f
yarn lint --quick --fix

SDK Examples

The examples directory contains code snippets and projects written using the Looker language SDKs. You may find useful code in that repository. and are also welcome to contribute additional examples.

API Troubleshooting

See the official documentation for API Troubleshooting suggestions.

Notes

In addition to swagger being deprecated, this visual guide shows why OpenAPI 3.x is preferred to Swagger 2.x.

Securing your SDK credentials

Looker improves on the security of the generated code for SDKs by never storing your server location or API credentials in the source code generated by the Looker code generator. The SDKs also provide some customizable support for providing API configuration values like server location and credentials to the SDK. In every Looker SDK, there is an overrideable method called readConfig() that can be customized to retrieve and return SDK configuration values from your preferred secure storage location.

Each Looker SDK has existing readConfig() examples that read from .ini files or environment variables. These are intended to support a quick start when developing with a Looker SDK. If a production environment prohibits secure use of .ini files or environment variables, another method of retrieving API configuration values is required. The API configuration retrieval function readConfig() can be overridden to support alternate storage scenarios.

Typically, client_id and client_secret are the only key values that will need to be dynamically retrieved from the readConfig() override method because the other configuration values are saved in memory by the initialized SDK client. In the near future, there will be additional authentication flows (such as OAuth) supported by Looker SDKs. The dynamic result that is returned by readConfig() can also be useful in those additional scenarios.

A short TypeScript SDK example that customizes readConfig() is available in the SDK Examples repository.

There is also a Kotlin SDK unit test in this repository with a short example:

class MockSettings(contents: String) : ApiSettings(contents) {
    override fun readConfig(): Map<String, String> {
        return mapOf(
                "base_url" to baseUrl,
                "verify_ssl" to verifySSL.toString(),
                "timeout" to timeout.toString(),
                "headers" to headers.toString(),
                "client_id" to mockId,
                "client_secret" to mockSecret
        )
    }
}

Please consult with the security professionals in your organization to determine the best way to secure your credentials for your own Looker SDK usage.

Warnings for using .ini files to configure the SDK

To streamline getting started with the Looker SDKs, support for reading SDK credentials from an .ini file is included as a simple method for providing access information (server url and API credentials) to the SDK. If the source code to your Looker SDK application is shared in a version control system, the .ini file should be ignored so it never gets inadvertently published.

If the SDK application using an .ini file is available publicly, download or viewing of this .ini file should also be prohibited by the server hosting the application.

Warnings for using Environment variables to configure the SDK

If the host environment for a Looker SDK supports environment variables, the SDK can also read environment variables to retrieve the server url and API credentials. Environment variables could also be visible to intrusive malware that may penetrate your application, so this option for providing credentials should also be used with caution.

Environment variable configuration

Environment variables can be used for any SDK runtime that supports reading environment variables. Environment variables can be used in the:

  • Node version of the TypeScript/JavaScript Looker SDK
  • Python SDK
  • Swift SDK
  • Kotlin SDK
  • Go SDK

The following table describes the environment variables. By default, the SDK "namespace" is "LookerSDK" which is converted to UPPERCASE when used for naming environment variables.

Variable name Description
LOOKERSDK_BASE_URL A URL like https://my.looker.com:19999. No default value.
LOOKERSDK_VERIFY_SSL true, t, yes, y, or 1 (case insensitive) to enable SSL verification. Any other value is treated as false. Defaults to true if not set.
LOOKERSDK_TIMEOUT Request timeout in seconds. Defaults to 120 for most platforms.
LOOKERSDK_CLIENT_ID API3 credentials client_id. This and client_secret must be provided in some fashion to the Node SDK, or no calls to the API will be authorized. No default value.
LOOKERSDK_CLIENT_SECRET API3 credentials client_secret. No default value.

Configuration variable precedence

Configuration variables should be processed as follows:

  • if the default configuration .ini file exists, apply the values
  • if an environment variable exists, apply the value
  • if a configuration value is explicitly in code, apply that value
  • if a command-line switch is supported, apply that value

More Repositories

1

gzr

A Command Line Tool for Looker Content Management
Ruby
120
star
2

look-at-me-sideways

A style guide and linter for Looker's LookML data modeling language
JavaScript
102
star
3

looker-explore-assistant

A React Application for interacting with Looker data through natural language.
TypeScript
93
star
4

henry

A command line tool for Looker instance cleanup
Python
81
star
5

extension-gen-ai

Looker Extension GenAI - using LLMs to make exploration easier and getting dashboard insights
TypeScript
71
star
6

lookr

An R library for the Looker API (4.0)
R
71
star
7

embed-sdk

The Looker browser embedding SDK
TypeScript
70
star
8

actions

TypeScript
58
star
9

components

Looker's UI Components, Design Infrastructure and more
HTML
50
star
10

looker_deployer

A tool to help deploy objects from one Looker instance to another
Python
45
star
11

pylookml

A pythonic api for automatic lookml
Python
41
star
12

sdk-examples

Example source code and projects for the Looker SDKs
Swift
40
star
13

customer-scripts

customer scripts
Shell
36
star
14

dashboard-summarization

TypeScript
22
star
15

extension-examples

Examples and templates for use with the Looker Extension Framework.
JavaScript
22
star
16

block-cortex-sap

Cortex - Order to Cash and Finance
LookML
21
star
17

bqjdbc

Fork of Starschema's JDBC driver for BigQuery. https://code.google.com/p/starschema-bigquery-jdbc/
Java
19
star
18

admin_power_pack

TypeScript
17
star
19

LookerEmbedReference

Examples of how to embed Looker into a web application
JavaScript
16
star
20

app-lookml-diagram

An "ERD for LookML". Now available for download on the Looker Marketplace.
TypeScript
15
star
21

looker-sdk-ruby

Looker SDK for Ruby
Ruby
14
star
22

app-ml-accelerator

Looker extension designed to give business users access to BigQuery and Vertex AI's machine learning capabilities.
LookML
12
star
23

viz-report-table-marketplace-open-source

JavaScript
11
star
24

extension-template-react

TypeScript
11
star
25

looker-scim-proxy

TypeScript
9
star
26

extension-api-explorer

LookML
9
star
27

app-data-dictionary

TypeScript
8
star
28

micro-admin-for-looker

JavaScript
8
star
29

looker-load-testing

locust-based realbrowser load testing for looker instances
Python
8
star
30

lmanage

Python
8
star
31

vertex-ai-actions

Python
7
star
32

chatty

A simple iframe host/client channel manager
TypeScript
7
star
33

github_actions_looker_cicd

This is a repo that walks through the process on how to enable Github actions to automate a basic LookML testing suite.
7
star
34

bqml-actions

BigQuery ML Actions using Google Cloud Functions for Looker
Python
6
star
35

component-examples

JavaScript
6
star
36

block-google-cloud-billing

Ticket # 200225073
LookML
6
star
37

healthcare_demo

This repo contains the LookML for the model and dashboards used with the FHIR healthcare dataset to showcase how Looker can add value to healthcare providers
LookML
6
star
38

viz-force_directed_graph-marketplace

TypeScript
5
star
39

looker-demo-dashboard-match

A Looker Extension Showcasing the Looker API Paired with Generative AI, Powering a Dashboard Search/Recommendation App
TypeScript
5
star
40

custom-action-hub-example

A template for building a custom Looker action hub with your own actions.
TypeScript
5
star
41

themis

Automate health reporting and bring order in your Looker instance
Python
5
star
42

looker-query-insights

JavaScript
5
star
43

extension-template-kitchensink

TypeScript
5
star
44

custom-viz-builder

JavaScript
4
star
45

block-cortex-salesforce

LookML
4
star
46

looker_content_observer

A command line tool for automated checking of dashboards and looks across instances and branches
Python
4
star
47

app-ml-accelerator-src

TypeScript
3
star
48

bqml_semantic_search_block

LookML
3
star
49

marketing_demo

LookML
3
star
50

cluster_terraform

HCL
3
star
51

block-cortex-demand-sensing

LookML
3
star
52

block-multicloud-billing-dashboard

LookML
3
star
53

block-cloud-armor

LookML
2
star
54

ecomm_demo

LookML
2
star
55

block-workspace-audit-logs

LookML
2
star
56

supermetrics_partner

LookML
2
star
57

google_cloud_focus

LookML
2
star
58

block-cortex-meta

LookML
2
star
59

extension-template-redux

TypeScript
2
star
60

blocks_zendesk

LookML
1
star
61

dropbox_app

LookML
1
star
62

block-generate-text-llm

LookML
1
star
63

jk-sandbox

Sandbox for experimentation
Kotlin
1
star
64

block-new-bigquery-optimization-non-marketplace

LookML
1
star
65

google_adwords

LookML
1
star
66

create-looker-extension

Create Looker Extensions with zero manual configuration
JavaScript
1
star
67

snowflake-usage-block

LookML
1
star
68

block-multicloud-billing-bq-export

LookML
1
star
69

block-aws-billing

LookML
1
star
70

ga_360_new

LookML
1
star
71

extension-access-key-demo

TypeScript
1
star
72

datablocks-weathersource

LookML
1
star
73

google_ga360

LookML
1
star
74

block-cortex-sfmc

LookML
1
star
75

thelookevent

LookML
1
star