Creating a Data Dictionary Using Looker's API

Looker will not be updating this content, nor guarantees that everything is up-to-date. 


Alternatively to the method described below, you can use the Looker Data Dictionary from the Looker Marketplace if your admin has enabled certain Labs features.

You can use the Looker API to create a data dictionary based on the definitions and descriptions of fields defined in the Looker modeling layer. Creating a data dictionary can be useful for:

  • Creating a reference source for all consumers of external reports.
  • Providing a location for business users to search all metrics descriptions to identify the appropriate dimension or measure for analysis.
  • Making it easy for external stakeholders to identify and locate the unique metrics for their business.
  • Auditing LookML models to assess whether consistent naming conventions are followed, whether there are redundant fields, or if fields are annotated with descriptions.

 

Step 1:

Authenticate into the API following the steps outlined in the Authentication with an SDK section of the Looker API Authentication documentation.

Step 2:

Define fields with descriptions and other parameters within the model in your Looker instance.

Step 3:

Call the lookML_model_explore endpoint via the API and pull in the appropriate fields you want to identify within your data dictionary.

Here is a sample Ruby code that puts the above steps all together:

        #Get Data Dictionary

require 'looker-sdk'

module ApplicationHelper

def self.api_auth
sdk = LookerSDK::Client.new(
# Looker/API Credentials
:client_id => ENV['API_CLIENT_ID'],
:client_secret => ENV['API_SECRET'],
:api_endpoint => ENV['API_ENDPOINT']
)
return sdk
end

def self.get_field_values(model_name, explore_name)

sdk = self.api_auth()
fields = {:fields => 'id, name, description, fields'}

#API Call to pull in metadata about fields in a particular explore
fields = sdk.lookml_model_explore(model_name, explore_name, fields)


my_fields = []

#Iterate through the field definitions and pull in the description, sql, and other looker tags you might want to include in your data dictionary.
fields[:fields][:dimensions].to_a.each do |x|
dimension = {
:field_type => 'Dimension',
:view_name => x[:view_label].to_s,
:field_name => x[:label_short].to_s,
:type => x[:type].to_s,
:description => x[:description].to_s,
:sql => x[:sql].to_s
}
my_fields << dimension
end

fields[:fields][:measures].to_a.each do |x|
measure = {
:field_type => 'Measure',
:view_name => x[:view_label].to_s,
:field_name => x[:label_short].to_s,
:type => x[:type].to_s,
:description => x[:description].to_s,
:sql => x[:sql].to_s
}

my_fields << measure
end

return my_fields
end

end

Step 4:

Format the results from the get_field_values call. Consider using plugins to allow for search and sort functionality. In our example, we use the DataTable JS plugin.

Examples:

Default Dictionary with Pagination and Sorts:

99d80b45-7707-4393-b109-6ed8e9c8dc6d.jpg

 

Dictionary Filtered to Fields that Contain the Word lifetime:

b97f3cec-a99b-4476-9918-8279aea6f600.jpg

Additional information on data dictionaries combining the API and Python to output a data dictionary to .csv can be found here in the Community post Writing a Simple Data Dictionary to CSV Using the Looker API and the Python requests library

Version history
Last update:
‎05-10-2022 11:34 AM
Updated by: