A Python wrapper for interacting with Metabase's API.
Project description
metabase-python
An unofficial Python library for the Metabase API.
Installation
pip install metabase-python
Usage
This API is still experimental and may change significantly between minor versions.
Start by creating an instance of Metabase with your credentials. This connection will automatically be used by any object that interacts with the Metabase API.
from metabase import Metabase
metabase = Metabase(
host="<host>",
user="<username/email>",
password="<password>",
)
You can then interact with any of the supported endpoints through the classes included in this package. All changes are reflected in Metabase instantly.
from metabase import User
# get all objects
users = User.list()
# get an object by ID
user = User.get(1)
# attributes are automatically loaded and available in the instance
if user.is_active:
print("User is active!")
# update any available attribute
user.update(is_superuser=True)
# delete an object
user.delete()
# create an object
new_user = User.create(
first_name="<first_name>",
last_name="<last_name>",
email="<email>",
password="<password>"
)
The methods .list()
, .get()
, .create()
, .update()
, .delete()
are available on all
endpoints that support them in Metabase API.
Some endpoints also support additional methods:
from metabase import User
user = User.get(1)
user.reactivate() # Reactivate user
user.send_invite() # Resend the user invite email for a given user.
Here's a slightly more advanced example:
from metabase import User, PermissionGroup, PermissionMembership
# create a new PermissionGroup
my_group = PermissionGroup.create(name="My Group")
for user in User.list():
# add all users to my_group
PermissionMembership.create(
group_id=my_group.id,
user_id=user.id
)
You can also execute queries and get results back as a Pandas DataFrame. Currently, you need to provide
the exact MBQL (i.e. Metabase Query Language) as the query
argument.
from metabase import Dataset
dataset = Dataset.create(
database=1,
type="query",
query={
"source-table": 1,
"aggregation": [["count"]],
"breakout": ["field", 7, {"temporal-unit": "year"},],
},
)
df = dataset.to_pandas()
Endpoints
For a full list of endpoints and methods, see Metabase API.
Endpoints | Support |
---|---|
Activity | ❌ |
Alert | ❌ |
Automagic dashboards | ❌ |
Card | ❌ |
Collection | ❌ |
Card | ❌ |
Dashboard | ❌ |
Database | ❌ |
Dataset | ✅ |
❌ | |
Embed | ❌ |
Field | ✅ |
Geojson | ❌ |
Ldap | ❌ |
Login history | ❌ |
Metric | ✅ |
Native query snippet | ❌ |
Notify | ❌ |
Permissions | ❌ |
Premium features | ❌ |
Preview embed | ❌ |
Public | ❌ |
Pulse | ❌ |
Revision | ❌ |
Search | ❌ |
Segment | ✅ |
Session | ❌ |
Setting | ❌ |
Setup | ❌ |
Slack | ❌ |
Table | ✅ |
Task | ❌ |
Tiles | ❌ |
Transform | ❌ |
User | ✅ |
Util | ❌ |
Contributing
Contributions are welcome!
License
This library is distributed under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for metabase_python-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c46d7a526ebcd4f0a6d93756d3867fadd9be82011e1c78211b66fb2279320c28 |
|
MD5 | b04de51fe5336c3546fd14f0fe2897e2 |
|
BLAKE2b-256 | 15255752b8243c89462a5359a1255410f394bc2843b5aea43add538637d6d07a |