Export data from Python to Tableau directly

Consider using TabPy. It returns values created by scripts as calculated fields within a workbook.

Otherwise, Tableau purely operates as a layer on top of a source of data. There is no such thing, unfortunately, as loading data directly into it.

The way I typically handle jobs like this is to have Python load data directly into a data store of some sort. All new information - or overwritten information - is then viewable with the existing data connection of your Tableau workbook.

A simple way to do this, without having to use a formal database is to consistently load the CSV into the same place with the same name. Then once Tableau is opened with the pre-existing connection, all that is needed is a click of 'refresh.'

I understand that your goal is to have Tableau populate your data directly from Python, and I'm sorry this isn't the answer you probably wanted, but there is some backend work that needs to be done. If done properly, though, the end effect to any user could appear to render directly from Python.


Make sure your current Tableau extract is a "Tableau Data Source" and then use the "Tableau Data Extract Command-Line Utility" to push the data into Tableau. You use os.system or subprocess to call the tableau executable. One caveat is this thing only work on Windows.

https://onlinehelp.tableau.com/current/pro/desktop/en-us/extracting_TDE.htm

Loading a csv file example from the Tableau site:

C:\Program Files\Tableau\Tableau 2019.1\bin>tableau addfiletoextract --server https://our_server_name --username OurServerSignIn --password "OurServerPwd" --project "New Animations" --datasource "CurrentYrOverYrStats" --file "C:\Users\user1\Documents\DataUploadFiles\AprMay.csv"