@@ -16,8 +16,7 @@ pip install metabase-python
16
16
This API is still experimental and may change significantly between minor versions.
17
17
18
18
19
- Start by creating an instance of Metabase with your credentials. This connection will automatically be used by any
20
- object that interacts with the Metabase API.
19
+ Start by creating an instance of Metabase with your credentials.
21
20
``` python
22
21
from metabase import Metabase
23
22
@@ -28,17 +27,18 @@ metabase = Metabase(
28
27
)
29
28
```
30
29
31
- You can then interact with any of the supported endpoints through the classes included in this package. All changes
32
- are reflected in Metabase instantly.
30
+ You can then interact with any of the supported endpoints through the classes included in this package. Methods that
31
+ instantiate an object from the Metabase API require the ` using ` parameter which expects an instance of ` Metabase ` such
32
+ as the one we just instantiated above. All changes are reflected in Metabase instantly.
33
33
34
34
``` python
35
35
from metabase import User
36
36
37
37
# get all objects
38
- users = User.list()
38
+ users = User.list(using = metabase )
39
39
40
40
# get an object by ID
41
- user = User.get(1 )
41
+ user = User.get(1 , using = metabase )
42
42
43
43
# attributes are automatically loaded and available in the instance
44
44
if user.is_active:
@@ -52,6 +52,7 @@ user.delete()
52
52
53
53
# create an object
54
54
new_user = User.create(
55
+ using = metabase,
55
56
first_name = " <first_name>" ,
56
57
last_name = " <last_name>" ,
57
58
email = " <email>" ,
@@ -67,7 +68,7 @@ Some endpoints also support additional methods:
67
68
``` python
68
69
from metabase import User
69
70
70
- user = User.get(1 )
71
+ user = User.get(1 , using = metabase )
71
72
72
73
user.reactivate() # Reactivate user
73
74
user.send_invite() # Resend the user invite email for a given user.
@@ -78,11 +79,12 @@ Here's a slightly more advanced example:
78
79
from metabase import User, PermissionGroup, PermissionMembership
79
80
80
81
# create a new PermissionGroup
81
- my_group = PermissionGroup.create(name = " My Group" )
82
+ my_group = PermissionGroup.create(name = " My Group" , using = metabase )
82
83
83
84
for user in User.list():
84
85
# add all users to my_group
85
86
PermissionMembership.create(
87
+ using = metabase,
86
88
group_id = my_group.id,
87
89
user_id = user.id
88
90
)
@@ -94,6 +96,7 @@ the exact MBQL (i.e. Metabase Query Language) as the `query` argument.
94
96
from metabase import Dataset
95
97
96
98
dataset = Dataset.create(
99
+ using.metabase,
97
100
database = 1 ,
98
101
type = " query" ,
99
102
query = {
0 commit comments