Giter Club home page Giter Club logo

metabase-google-auth's Introduction

metabase-google-auth

Module for Metabase with Google Authentication login.

How to use

Download repo as zip file, extract all files into the folder of your codes or site-packages (recommended).

Install dependencies

pip install -r requirements.txt

Setup login info

Edit config.py with your login email and password.

Then get session cookie by

MetabaseAuth.get_cookie(domain)

If 2-step verification is enabled you need to grant access using your phone. The session cookie will be stored in token.txt and can be reused until expiration.

Query unfiltered question into DataFrame

Example: get the results for question ID 12345, convert into a DataFrame and export to csv

import MetabaseAuth

domain = 'metabase.xxxxx.xx'
cookie = MetabaseAuth.get_cookie(domain)

df = MetabaseAuth.query(domain, cookie, 12345, export=True)

Query filtered question

For questions with filters, first we need to obtain the format of the question's parameters request. Get the params as a list by

params = MetabaseAuth.get_params(domain, cookie, question_id)

This will open the browser and navigate to the question page. To get the params, put some values into the filters and click run on Metabase.

Example: query a filtered question with ID 12345

params = MetabaseAuth.get_params(domain, cookie, question_id)

df = MetabaseAuth.query(domain, cookie, 12345, params=params)

Modify params

Once params has been obtained, we can either convert it to a string and modify directly, or treat it as a list of dictionary for more complex automation.

Example of a returned params:

# creation_datetime is a Field Fiter with value '2020-12-01~2020-12-31'
# order_id is a normal filter with value '111'
[{'type': 'date/range',
  'target': ['dimension', ['template-tag', 'creation_datetime']],
  'value': '2020-12-01~2020-12-31'},
 {'type': 'category',
  'target': ['variable', ['template-tag', 'order_id']],
  'value': '111'}]

Convert params to string

We can convert params to a parsable string, modify the values and pass it to another query call.

params_str = MetabaseAuth.params_formatting(params)

Load saved cookie and params

Load saved cookie by

cookie = MetabaseAuth.load_cookie()

If cookie has expired you will be prompted to run get_cookie().

Running get_params(question_id) will save the params for that question in params.txt . Load saved params by

params = MetabaseAuth.load_params(question_id)

metabase-google-auth's People

Contributors

kruschev avatar

Stargazers

Reinholds Zviedris avatar gracious avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.