Looker Generator

LookBase

class looker_generator.LookBase(model: str, explore: str, fields: list, sorts: dict, filters: dict = None, pivots: list = None, custom_fields: list = None, limit: int = 500, total: bool = False, row_total: bool = False, timezone: str = 'America%2FNew_York')

Stores the parameters of a Looker explore as an object ready to be assembled into a URL.

property source

The model and explore of the LookBase object.

Returns

The strings stored in the “model” and “explore” fields, separated by a “/”.

Return type

str

Setter

Accepts a string of two values, separated by a “/”, and splits it into a list, which will be passed to the “model” and “explore” fields, respectively.

Parameters

new_source (str) – The new source to be used in the LookBase object.

Raises

InputMismatch Exception – If anything other than a string is passed.

property model

The model used by the LookBase object.

Returns

The first half of the “source” property.

Return type

str

Parameters

new_model (str) – The new model to be used for the LookBase object.

Raises

InputMismatch Exception – If anything other than a string is passed.

property explore

The explore used by the LookBase object.

Returns

The second half of the “source” property.

Return type

str

Parameters

new_explore (str) – The new explore to be used by the LookBase object.

Raises

InputMismatch Exception – If anything other than a string is passed.

property fields

A list of the fields stored in the LookBase object.

Setter

If the input is a list, set or tuple, convert it to a list and store it; If the input is a string, split it into a list on the commas; Otherwise, raise an exception.

Parameters

new_fields (list, tuple, set, str) – The fields to be used by the LookBase object.

Returns

The fields currently being used by the LookBase object.

Return type

list

Raises

InputMismatch Exception – If anything other than a list, tuple, set or string is passed.

property sorts

A dict of sorts, containing the criteria of the sort as the key, and whether it is descending as a value.

Setter

If the input is a dict, pass it through; If it is a string, break it on the “+” symbol, and if there was anything to he right of the “+”, set the value to True, or false otherwise.

Parameters

new_sorts (dict, str) – The new sorts to be used by the LookBase object.

Returns

A dict holding the sort parameters as keys, and whether each one is descending as the values.

Return type

dict

Raises

InputMismatch Exception – If anything other than a dict or a string is passed.

property sort_adapter

Functions as an adapter for use with the Looker API.

Returns

The sorts used by the LookBase object, and whether each one is descending, formatted as a list of strings.

Return type

list

property filters

A dict containing the names and values of all the filters of the URL.

Setter

Passes a dict verbatim, or splits a string into a dict holding a single key-value pair.

Parameters

new_filters (dict, str, list) – The new filters to be used by the LookBase object.

Returns

The filters used by the LookBase object

Return type

dict

Raises

InputMismatch Exception – If anything other than a dict, list or string is passed.

Note

Looker stores filters in a pretty weird way, which is the main reason the urllib isn’t able to simply be used verbatim.

property filter_adapter

Functions as an adapter for use with the Looker API.

Returns

A dict of filters and their targets, reformatted to remove plus signs.

Return type

dict

property pivots

Returns a list of the fields used for pivots.

Note

This property is currently unused.

property custom_fields

Returns a list of the custom fields used in the LookBase object.

Note

This property is currently unused.

property limit

The maximum number of rows to be displayed by this LookBase object.

Parameters

new_limit (int) – The number of rows the LookBase object should show. This defaults to 500 and is capped at 5000

Returns

The limit used by the LookBase object

Return type

int

Raises

InputMismatch Exception – If anything other than in int is passed.

property total

Does this explore include an additional row containing the total of each column?

Parameters

new_total (bool) – Sets whether the totals are shown.

Returns

Whether the totals are shown.

Return type

bool

Raises

InputMismatch Exception – If anything other than a bool is passed.

property row_total

Does this explore have an additional column holding the total for each row?

Parameters

new_row_total (bool) – Sets whether the row totals are shown.

Returns

Whether the row totals are shown.

Return type

bool

Raises

InputMismatch Exception if anything other than a boolean is passed.

property timezone

The timezone used by the explore.

Arg

new_timezone: The new timezone to use

Type

new_timezone: str

Returns

The timezone used by the explore.

Return type

str

Raises

Raises an InputMismatch exception is anything other than a string is passed.

property url_constructor

Generates a URL for a Looker explore from the parameters stored within the LookBase object.

Returns

The source and fields of the LookBase object

Return type

str

property generate_url

Creates a URL for an explore to be created by a user.

Returns

The finished URL created by the LookBase object.

Return type

str

property generate_api

Creates a URL for an explore to be created via the Looker API.

Returns

The finished URL for use of the Looker API.

Return type

str

property body

Functions as an adapter for use with the Looker API.

Returns

The parameters of the LookBase object, formatted for use as the “body” argument by the Looker API.

Return type

dict

URL Parser

class looker_generator.URLParser(input_url: str)

Accepts a URL as a string, parsing it into a LookBase object