Skip to content
This repository was archived by the owner on Sep 25, 2020. It is now read-only.

Python: An example custom config reader #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions python/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@

You can find Python language examples in this folder.

### General examples

|   Example Topic   | Discussion |
| ------------- | ---------- |
| [custom config reader](custom_config_reader.py) | Shows how to implement a custom method of reading your configuration settings, including API credentials |

## Connection management
|   Example Topic   | Discussion |
| ------------- | ---------- |
| [Testing a connection](test_connection.py) | Shows how to obtain and run all supported tests for a given connection name.|

- [Test a specified connection](test_connection.py)

## Manage Dashboards
|   Example Topic   | Discussion |
| ------------- | ---------- |
| [Soft delete dashboard](soft_delete_dashboard.py)| Shows how to look up a dashboards by title and move them to the trash folder. |

- [Soft delete dashboard](soft_delete_dashboard.py)

## Manage Render Tasks

- [Download dashboard tile in specified format](download_tile.py)
- [Download look in specified format](download_look.py)
- [Generate and download dashboard PDFs](download_dashboard_pdf.py)
|   Example Topic   | Discussion |
| ------------- | ---------- |
| [Download dashboard tile in specified format](download_tile.py) | Find the requested dashboard by name, then the requested tile by name. If either name matches, the list of all available items is display. Supported output formats are PNG, JPG, CSV, JSON, and anything else supported by the `run_query` endpoint. This sample shows progress during a render task. |
| [Download look in specified format](download_look.py) | Find the requested look by name, create a render task and write the binary result to file. |
| [Generate and download dashboard PDFs](download_dashboard_pdf.py) | Find the requested dashboard by name, create a render task and write the binary result to file. |

## User Management

- [Disable all active user sessions](logout_all_users.py)
|   Example Topic   | Discussion |
| ------------- | ---------- |
| [Disable all active user sessions](logout_all_users.py) | Shows how to iterate through all users and terminate any active sessions they might have. |
48 changes: 48 additions & 0 deletions python/custom_config_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import attr
from looker_sdk import (
api_settings,
auth_session,
methods,
requests_transport,
serialize,
)
from looker_sdk.rtl import transport as tp


@attr.s(auto_attribs=True, kw_only=True)
class CustomConfigReader(tp.TransportSettings):
"""
A custom configuration reader that implements the PApiSettings protocol and allows
passing of config details as parameters. The get_client_id and get_cient_secret
methods can be modified to fetch credentials from anywhere.
"""

@classmethod
def configure(cls, base_url: str, api_version: str) -> api_settings.PApiSettings:
settings = cls(base_url=base_url, api_version=api_version)
return settings

def get_client_id(self) -> str:
return "client_id"

def get_client_secret(self) -> str:
return "client_secret"


def main():
settings = CustomConfigReader.configure(
base_url="https://<your-looker-server>:19999", api_version="3.1"
)
transport = requests_transport.RequestsTransport.configure(settings)
sdk = methods.Looker31SDK(
auth_session.AuthSession(settings, transport, serialize.deserialize31),
serialize.deserialize31,
serialize.serialize,
transport,
)

me = sdk.me()
print(me)


main()