Looker SDK for Python
The `looker-sdk` is the official Python SDK for interacting with the Looker REST API. It provides a convenient, programmatic way to manage Looker instances, run queries, extract data, and automate workflows. Maintained by Google/Looker, it currently supports API 4.0 and requires Python 3.6+. It's actively developed with regular updates to support new Looker features and API versions.
Warnings
- breaking API 3.x (3.0 and 3.1) has been completely removed in Looker v23.18 (August 2023). Any applications or scripts using `looker_sdk.init31()` or directly calling 3.x API endpoints will fail.
- breaking Beginning with Looker 26.18 (expected October 2026), credentials for API login will *exclusively* be accepted in the HTTP request body. Passing credentials via URL query parameters will no longer be supported.
- gotcha Storing API credentials directly in a `looker.ini` file or environment variables without proper security measures is a risk. For production environments, consider more secure storage solutions.
- gotcha The base URL for your Looker instance can vary, especially between AWS and Google Cloud Platform (GCP) hosted instances, potentially requiring a port number.
- deprecated The `lookerapi` Python package (installed via `pip install lookerapi-deprecated`) is an unofficial, unsupported SDK that was fully removed by the end of 2020. It will not receive updates and may not work with newer Python versions or Looker API changes.
Install
-
pip install looker-sdk
Imports
- looker_sdk
import looker_sdk
- init40
sdk = looker_sdk.init40()
- models
from looker_sdk import models
Quickstart
import os
import looker_sdk
# --- Configuration using Environment Variables ---
# Set these environment variables before running:
# LOOKERSDK_BASE_URL: Your Looker instance URL (e.g., https://your.looker.com or https://your.looker.cloud.google.com)
# Note: AWS-hosted instances may require ':19999' port (e.g., https://your.looker.com:19999), while GCP-hosted instances usually omit it.
# LOOKERSDK_API_VERSION: Should be '4.0'
# LOOKERSDK_VERIFY_SSL: 'true' or 'false'
# LOOKERSDK_CLIENT_ID: Your API3 Client ID
# LOOKERSDK_CLIENT_SECRET: Your API3 Client Secret
# LOOKERSDK_TIMEOUT: (Optional) Request timeout in seconds, default is 120.
# Example of setting environment variables (replace with your actual values):
os.environ['LOOKERSDK_BASE_URL'] = os.environ.get('LOOKERSDK_BASE_URL', 'https://your.looker.com')
os.environ['LOOKERSDK_API_VERSION'] = os.environ.get('LOOKERSDK_API_VERSION', '4.0')
os.environ['LOOKERSDK_VERIFY_SSL'] = os.environ.get('LOOKERSDK_VERIFY_SSL', 'true')
os.environ['LOOKERSDK_CLIENT_ID'] = os.environ.get('LOOKERSDK_CLIENT_ID', 'YOUR_CLIENT_ID')
os.environ['LOOKERSDK_CLIENT_SECRET'] = os.environ.get('LOOKERSDK_CLIENT_SECRET', 'YOUR_CLIENT_SECRET')
# Initialize the SDK for API 4.0
try:
sdk = looker_sdk.init40()
print("Looker SDK 4.0 initialized successfully.")
# Make a simple API call to get the current user
me = sdk.me()
print(f"Hello, {me.first_name} {me.last_name} ({me.email})!")
# Example of creating a user (requires appropriate permissions)
# from looker_sdk import models
# new_user_data = models.WriteUser(first_name="Test", last_name="User", email="test.user@example.com")
# new_user = sdk.create_user(body=new_user_data)
# print(f"Created new user: {new_user.first_name}")
except Exception as e:
print(f"Error initializing SDK or making API call: {e}")
print("Please ensure environment variables (LOOKERSDK_BASE_URL, LOOKERSDK_API_VERSION, CLIENT_ID, CLIENT_SECRET) are correctly set.")