Skip to content

Commit 627b53a

Browse files
committed
add format_rows option to get_card_data function and apply new versioning format
1 parent 8ff485c commit 627b53a

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.4
2+
### Changed
3+
- New versioning format (3.4 instead of 0.3.4)
4+
- Added `format_rows` option to `get_card_data` function
5+
16
## 0.3.3
27
### Changed
38
- Authentication using API key

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,3 @@ Deletes the item (Card, Dashboard, Pulse). Currently Collections and Segments ca
169169
```python
170170
mb.delete_item('card', item_id=123)
171171
```
172-
173-
## Notes
174-
There are also two other Python wrappers for Metabase API [here](https://github.com/mertsalik/metabasepy) and [here](https://github.com/STUnitas/metabase-py).

metabase_api/metabase_api.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ def search(self, q, item_type=None):
9090

9191

9292

93-
def get_card_data(self, card_name=None, card_id=None, collection_name=None,
94-
collection_id=None, data_format='json', parameters=None):
93+
def get_card_data(self, card_name=None, card_id=None, collection_name=None, collection_id=None,
94+
data_format='json', parameters=None, format_rows=False):
9595
'''
9696
Run the query associated with a card and get the results.
97-
The data_format keyword specifies the format of the returned data:
97+
98+
Keyword arguments:
99+
data_format -- specifies the format of the returned data:
98100
- 'json': every row is a dictionary of <column-header, cell> key-value pairs
99101
- 'csv': the entire result is returned as a string, where rows are separated by newlines and cells with commas.
100-
To pass the filter values use 'parameters' param:
102+
parameters -- can be used to pass filter values:
101103
The format is like [{"type":"category","value":["val1","val2"],"target":["dimension",["template-tag","filter_variable_name"]]}]
102104
See the network tab when exporting the results using the web interface to get the proper format pattern.
105+
format_rows -- whether the returned results should be formatted or not
103106
'''
104107
assert data_format in [ 'json', 'csv' ]
105108
if parameters:
@@ -113,9 +116,11 @@ def get_card_data(self, card_name=None, card_id=None, collection_name=None,
113116
collection_id=collection_id,
114117
item_type='card')
115118

116-
# add the filter values (if any)
117119
import json
118-
params_json = {'parameters':json.dumps(parameters)}
120+
params_json = {
121+
'parameters':json.dumps(parameters),
122+
'format_rows':'true' if format_rows else 'false'
123+
}
119124

120125
# get the results
121126
res = self.post("/api/card/{}/query/{}".format(card_id, data_format), 'raw', data=params_json)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="metabase-api",
8-
version="0.3.3.1",
8+
version="3.4",
99
author="Vahid Vaezian",
1010
author_email="vahid.vaezian@gmail.com",
1111
description="A Python Wrapper for Metabase API",

0 commit comments

Comments
 (0)