Geckoboard Developer Community

Python API - problem with decimal numbers


I’m trying to upload a dataset with the Python API.
I’m executing a Postgres SQL query:

rows = curs.fetchall()

The query returns this:

[{‘description’: ‘Order Size 2-9’, ‘amount’: 222, ‘average’: Decimal(‘2.9’)}][rows[0]])

has an error:

TypeError: Object of type Decimal is not JSON serializable


Traceback (most recent call last):
File “/xxx/python/geckoboard/”, line 268, in
File “/xxx/python/geckoboard/”, line 262, in main
File “/xxx/python/geckoboard/”, line 189, in run[rows[i]])
File “/usr/local/lib/python3.7/site-packages/geckoboard/”, line 79, in post’/datasets/’ + self.__id + ‘/data’, body)
File “/usr/local/lib/python3.7/site-packages/geckoboard/”, line 25, in post
response =, body, self.api_key)
File “/usr/local/lib/python3.7/site-packages/geckoboard/”, line 19, in post
return + path, json=body, auth=(api_key, ‘’))
File “/usr/local/lib/python3.7/site-packages/requests/”, line 112, in post
return request(‘post’, url, data=data, json=json, **kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/”, line 58, in request
return session.request(method=method, url=url, **kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/”, line 498, in request
prep = self.prepare_request(req)
File “/usr/local/lib/python3.7/site-packages/requests/”, line 441, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File “/usr/local/lib/python3.7/site-packages/requests/”, line 312, in prepare
self.prepare_body(data, files, json)
File “/usr/local/lib/python3.7/site-packages/requests/”, line 462, in prepare_body
body = complexjson.dumps(json)
File “/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/”, line 231, in dumps
return _default_encoder.encode(obj)
File “/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/”, line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File “/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/”, line 257, in iterencode
return _iterencode(o, 0)
File “/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/”, line 179, in default
raise TypeError(f’Object of type {} ’
TypeError: Object of type Decimal is not JSON serializable

Dataset defined as:

  "ds_name" : "company_order_size_nrt",
  "ds_definition": {
      "amount": {
          "type": "number",
          "name": "Amount",
          "optional": false
      "average": {
          "type": "number",
          "name": "Average",
          "optional": false
      "description": {
          "type": "string",
          "name": "Description",
          "optional": false

Is it possible to upload decimal values? If yes, how to do it via the Python API?



I managed to workaround this by casting the DECIMAL ‘average’ field into a VARCHAR in the query which yields:

[{‘description’: ‘Order Size 1’, ‘amount’: 272, ‘average’: ‘1.00’}

This can be uploaded to the dataset without a problem.
Still it would be interesting to know how to properly upload a DECIMAL value being returned by a Postgres query in the Python API.


Just curious. Have you tried using SQL-Dataset instead?


No, not yet. Just read the doc. It’s definitely worth trying!


The issue can also be workarounded by casting the DECIMAL value to a FLOAT, REAL or DOUBLE in the SQL query. However, it is worth mentioning that the FLOAT datatype is inexact per definition on the DB level and could lead to unexpected results.