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

newsource (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

newmodel (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

newexplore (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

newfields (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

newsorts (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 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

newfilters (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 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

newlimit (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 additionl row containing the total of each column?

Parameters

newtotal (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

newrowtotal (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

newtimezone: The new timezone to use

Type

newtimezone: 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 generate_url

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

Returns

A url constructed from the parameters stored within the LookBase object

Return type

str

URL Parser

class looker_generator.URLParser(inputURL: str)

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