excelguy
excelguy

Reputation: 1624

Export data from Python to Tableau directly

I have a python code that exports data into a csv, then I load that csv into Tableau. I don't want to load a csv into tableau.

Is there a way I can just take the return value of my python script and put it directly into tableau?

Question is similar to Export data from Python into Tableau using JSON? , but they inquire about Json format and the answer was to use csv. I want to skip csv step if possible. The data im returning will be in a tabular format.

Upvotes: 10

Views: 5862

Answers (3)

Nathan
Nathan

Reputation: 1701

One of the existing options in the Tableau Desktop "Connect" screen is "Web Data Connector," which can connect to any kind of web server and get data through a well-documented protocol. I suspect this would include a web server running on localhost written in Python.

If you want to go this route, it would require either changing your existing Python script to turn it into a web server that transmits the script's output over the web data connection, or (preferably) making some very general Python code that could that could wrap an arbitrary script of any type in this way, exposing its output as a web data connection.

You will, of course, have to leave that Python script running, listening for connections from Tableau.

Upvotes: 1

MonteCarloSims
MonteCarloSims

Reputation: 1771

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.

Upvotes: 4

Thinh Pham
Thinh Pham

Reputation: 402

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"

Upvotes: 2

Related Questions