Package: looker-sdk
The Looker SDK for Python provides a convenient way to communicate with the
Looker API available on your Looker server. The library requires python3.6+
and is annotated using the typing module.The SDK uses a plug-in architecture (also known as dependency injection) for
initializing that supports run-time specific transports (currently onlyRequestsTransport) and different approaches for managing API authentication
(AuthSessionandOAuthSession). The methods and models are generated from
the Looker API spec by a new code generator developed at Looker.Pleasereport any issuesencountered, and indicate the SDK language in the report.Basic Usageimportlooker_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 APImy_user=sdk.me()# output can be treated like a dictionaryprint(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 WriteUsersdk.create_user(body=looker_sdk.models.WriteUser(first_name="Jane",last_name="Doe"))# or plain dictionariessdk.create_user(body={"first_name":"Jane","last_name":"Doe"})Full tutorialGo from installation all the way to creating a functional micro-application in this 20-30 minute interactive tutorial.This tutorial is hosted in Google Colaboratory, an interactive online notebook. You can follow along right in the notebook by clicking the button below.Sample project setupInstall python 3.8. We highly recommend usingpyenvto install
different versions of python. Mac users should usehomebrewto install pyenv:brewinstallpyenvLinux users should usecurlhttps://pyenv.run|bashPut this in your shell configuration script:exportPATH=$PATH:$HOME/.pyenv/bineval"$(pyenvinit--path)"eval"$(pyenvinit-)"eval"$(pyenvvirtualenv-init-)"Follow theremaining steps 3 - 5ofhttps://github.com/pyenv/pyenv#basic-github-checkoutotherwise your python3.8
installation may break.Now you’re ready to install python 3.8:pyenvinstall3.8.2We’ll usepipenv(fantastic virtualenv manager) to manage project dependencies.brewinstallpipenvCreate a project directorymkdirlooker-sdk-exampleSet python3.8 as the base interpreter for this directorycdlooker-sdk-example/pyenvlocal3.8.2Install looker_sdk using pipenvpipenv--python3.8.2install--prelooker_sdkConfiguring the SDKThe SDK supports configuration throughan.inifile on disksetting environment variablesproviding your own implementation of the ApiSettings class. The latter override the former.Note: The.iniconfiguration for the Looker SDK is a sample
implementation intended to speed up the initial development of python
applications using the Looker API. See this note onSecuring your SDK Credentialsfor warnings about using.inifiles that contain your
API credentials in a source code repository or production environment.In order to configure the SDK client, create a “looker.ini” file to reference
duringclient.setup()example file:[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=TrueNote: If the application using the Looker SDK is going to be committed to a version control system, be sure toignorethelooker.inifile so the API credentials aren’t unintentionally published.For any.inisetting you can use an environment variable instead. It takes the form ofLOOKERSDK_<UPPERCASE-SETTING-FROM-INI>e.g.LOOKERSDK_CLIENT_SECRETA final option is to provide your own implementation of the ApiSettings class. It is easiest to subclassapi_settings.ApiSettingsand override theread_configfunction (don’t forget a call tosuper().read_config()if appropriate, Example below). However, at a minimum your class must implement theapi_settings.PApiSettingsprotocol.importosimportlooker_sdkfromlooker_sdkimportapi_settingsclassMyApiSettings(api_settings.ApiSettings):def__init__(self,*args,**kw_args):self.my_var=kw_args.pop("my_var")super().__init__(*args,**kw_args)defread_config(self)->api_settings.SettingsConfig:config=super().read_config()# See api_settings.SettingsConfig for required fieldsifself.my_var=="foo":config["client_id"]=os.getenv("FOO_CLIENT")config["client_secret"]=os.getenv("FOO_SECRET")else:config["client_id"]=os.getenv("BAR_CLIENT")config["client_secret"]=os.getenv("BAR_SECRET")returnconfigsdk=looker_sdk.init40(config_settings=MyApiSettings(my_var="foo"))...Code exampleSee many python sdk examples in our examples repoChangelogLocated in our github repo