@@ -13,8 +13,8 @@ pip install metabase-python
13
13
```
14
14
15
15
## Usage
16
- This API is still experimental and may change significantly between minor versions.
17
16
17
+ ### Connection
18
18
19
19
Start by creating an instance of Metabase with your credentials.
20
20
``` python
@@ -27,6 +27,7 @@ metabase = Metabase(
27
27
)
28
28
```
29
29
30
+ ### Interacting with Endpoints
30
31
You can then interact with any of the supported endpoints through the classes included in this package. Methods that
31
32
instantiate an object from the Metabase API require the ` using ` parameter which expects an instance of ` Metabase ` such
32
33
as the one we just instantiated above. All changes are reflected in Metabase instantly.
@@ -84,27 +85,29 @@ my_group = PermissionGroup.create(name="My Group", using=metabase)
84
85
for user in User.list():
85
86
# add all users to my_group
86
87
PermissionMembership.create(
87
- using = metabase,
88
88
group_id = my_group.id,
89
- user_id = user.id
89
+ user_id = user.id,
90
+ using = metabase,
90
91
)
91
92
```
92
93
94
+ ### Querying & MBQL
95
+
93
96
You can also execute queries and get results back as a Pandas DataFrame. You can provide the exact MBQL, or use
94
97
the ` Query ` object to compile MBQL (i.e. Metabase Query Language) from Python classes included in this package.
95
98
96
99
``` python
97
100
from metabase import Dataset, Query, Count, GroupBy, TemporalOption
98
101
99
102
dataset = Dataset.create(
100
- using.metabase,
101
103
database = 1 ,
102
104
type = " query" ,
103
105
query = {
104
106
" source-table" : 1 ,
105
107
" aggregation" : [[" count" ]],
106
108
" breakout" : [" field" , 7 , {" temporal-unit" : " year" },],
107
109
},
110
+ using = metabase,
108
111
)
109
112
110
113
# compile the MBQL above using the Query object
@@ -116,6 +119,7 @@ dataset = Dataset.create(
116
119
aggregations = [Count()],
117
120
group_by = [GroupBy(id = 7 , option = TemporalOption.YEAR )]
118
121
).compile(),
122
+ using = metabase
119
123
)
120
124
121
125
df = dataset.to_pandas()
@@ -174,7 +178,8 @@ metric = Metric.create(
174
178
table_id = 1 ,
175
179
aggregations = [Count()],
176
180
filters = [EndsWith(id = 4 , value = " @gmail.com" , option = CaseOption.CASE_INSENSITIVE )]
177
- ).compile()
181
+ ).compile(),
182
+ using = metabase
178
183
)
179
184
```
180
185
0 commit comments