How to upload data to Tableau Server in Python

0 votes
I need to execute a python script that will upload/update a data file on a tableau server, so that the dashboard related to the datafile will be automatically updated every time I run the python script. I'm not sure how to go about doing that; the file I need to submit to the tableau server is in csv format, but I believe the server only accepts tableau files? In addition, I'm not sure which API to use for this.
Mar 4, 2022 in Tableau by Vaani
• 7,070 points
2,961 views

1 answer to this question.

0 votes

Then install the tableau-api-lib utility for Python (https://github.com/divinorum-webb/tableau-api-lib ), which may be found at https://github.com/divinorum-webb/tableau-api-lib. Then, to connect to your Tableau Server, follow these steps:

from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_projects_dataframe

tableau_server_config = {
        'my_env': {
                'server': 'https://YourTableauServer.com',
                'api_version': '<YOUR_API_VERSION>',
                'username': '<YOUR_USERNAME>',
                'password': '<YOUR_PASSWORD>',
                'site_name': '<YOUR_SITE_NAME>',
                'site_url': '<YOUR_SITE_CONTENT_URL>'
        }
}

conn = TableauServerConnection(tableau_server_config, env='my_env')
conn.sign_in()

Place to publish:

projects_df = get_projects_dataframe(conn)
print(projects_df[['full_name', 'ID']]

Publish:

response = conn.publish_data_source(
datasource_file_path='superstore_extract.tdsx',
datasource_name='superstore_extract',
project_id=PROJECT_ID_TO_PUBLISH_TO)

Inspect the outcome: print(response.json())

Unlock the Power of Data Visualization with Our Tableau Course.

answered Mar 4, 2022 by Neha
• 9,020 points