vvaezian / metabase_api_python

A python wrapper for Metabase API
MIT License
131 stars 39 forks source link
api metabase metabase-api metabase-python

PyPI version contributions welcome codecov GitHub license

Installation

pip install metabase-api

Initializing

from metabase_api import Metabase_API

# authentication using username/password
mb = Metabase_API('https://...', 'username', 'password')  # if password is not given, it will prompt for password

# authentication using API key
mb = Metabase_API('https://...', api_key='YOUR_API_KEY')

Functions

REST functions (get, post, put, delete)

Calling Metabase API endpoints (documented here) can be done using the corresponding REST function in the wrapper.
E.g. to call the endpoint GET /api/database/, use mb.get('/api/database/').

Helper Functions

You usually don't need to deal with these functions directly (e.g. get_item_info, get_item_id, get_item_name)

Custom Functions

For a complete list of functions parameters see the functions definitions using the above links. Here we provide a short description:

for city in city_list:

query = q.format(city)

here I included the minimum keys required. You can add more.

my_custom_json = { 'name': 'test_card', 'display': 'table', 'dataset_query': { 'database': db_id, 'native': { 'query': query }, 'type': 'native' } }

See the function definition for other parameters of the function (e.g. in which collection to save the card)

mb.create_card(custom_json=my_custom_json)


- #### `create_collection`
Create an empty collection. Provide the name of the collection, and the name or id of the parent collection (i.e. where you want the created collection to reside). If you want to create the collection in the root, you need to provide `parent_collection_name='Root'`.
```python
mb.create_collection(collection_name='test_collection', parent_collection_id=123)