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.