Export baserow data as csv and json

Hey guys.

1. Context
I’ve been usefully reading all the baserow documentation and learning how to program in another programming language. One of the languages ​​I’m enjoying the most is python. In my view it is a very simple, practical and didactic language.

Recently I saw that there was this topic open: Export as JSON or CSV and I thought I’d help. I created a python script that takes a json response and creates a final csv file. Initially, I think anyone can adapt this code to the context they need.

2. Idea:
1 I got the data in json with requests, and then convert it to an array
2 then I took the information from the array and saved it in a csv file

3. Example
For example, my general idea would be to use the Baserow API that responds in json. After having the response in json transform it into an array and after that generate a final csv file.

import requests
import json 
import pandas as pd
import numpy as np

def Connect(add_id_table, add_token_baserow):
  return requests.get("https://api.baserow.io/api/database/rows/table/"+add_id_table+"/?user_field_names=true", headers={"Authorization": "Token "+add_token_baserow})

def listDatabase(add_property_name):
  viewList = json.loads(json.dumps(Connect('add_id_table','add_token_baserow').json()))
  return viewList[add_property_name]

testTitleName = []
testTitleLastName = []
for index, item in enumerate(listDatabase('add_property_name')):
  testTitleName.append(item['testTitleName'])
  testTitleLastName.append(item['testTitleLastName']) 

arr = np.arange(testTitleName).reshape(testTitleLastName)  # arr = np.arange(1,11).reshape(2,5)
dataFrame  = pd.DataFrame(testTitleName)
dataFrame.to_csv("my_data_baserow.csv")

4. Final considerations
4.1 What do you all think of this idea?
4.2 Maybe we can create a flask API to convert json data to csv
4.3 I imagine converting json data to csv in Baserow is done through a plugin for that
4.4 This code is in the public domain, use or modify it however you want.
4.5 The codebase of this code is the same one I developed to generate graphs in Baserow.
4.6 This code is something basic for demonstration purposes.
4.7 I hope to contribute in some way to the Baserow community.
4.8 I don’t know if this can help anyone but I tried somehow

Don’t forget that the free plan has limitations
Please, see this: Baserow free tier limits
1.1 Maximum of 3.000 rows per group/workspace in free plan(Baserow)
1.2 Maximum of 2GB of storage in free plan(Baserow)
1.3 Maximum of 1.000 monthly API requests in free plan(Baserow)
1.4 Support via the community, tutorials, FAQ, user docs in free plan(Baserow)

1 Like

Thanks guys for the likes @olgatrykush @Peter. In the future, I will include/export csv and json. This algorithm is basic, but I will follow and add more features.

1 Like