Skip to content

Instantly share code, notes, and snippets.

View divinorum-webb's full-sized avatar
🐍
python

Elliott divinorum-webb

🐍
python
  • Amsterdam
View GitHub Profile
@divinorum-webb
divinorum-webb / AuthEndpoint.py
Created May 21, 2019 04:02
Gist for Tableau Server API AuthEndpoint class
class AuthEndpoint(BaseEndpoint):
"""
Authorization endpoint for Tableau Server API requests.
:param ts_connection: The Tableau Server connection object.
:type ts_connection: class
:param sign_in: Boolean flag; True if signing in, False otherwise.
:type sign_in: boolean
:param sign_out: Boolean flag; True if signing out, False otherwise.
:type sign_out: boolean
@divinorum-webb
divinorum-webb / TableauPublishPOSTExample.py
Created May 30, 2019 04:06
Sample code for publishing a Tableau workbook with Python using JSON
import os
import json
import requests
from requests.packages.urllib3.fields import RequestField
from requests.packages.urllib3.filepost import encode_multipart_formdata
def _make_multipart(parts):
mime_multipart_parts = []
for name, (filename, blob, content_type) in parts.items():
@divinorum-webb
divinorum-webb / tableau-api-lib-create-user.py
Last active July 6, 2021 05:42
tableau-api-lib-create-user
import pandas as pd
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_groups_dataframe
NEW_USER_NAME = '<YOUR_NEW_USER_NAME>'
NEW_USER_FULL_NAME = '<YOUR_NEW_USER_FULL_NAME>'
NEW_USER_EMAIL = '<YOUR_NEW_USER_EMAIL>'
NEW_USER_PASSWORD = '<YOUR_NEW_USER_PASSWORD>' # this is listed here for this tutorial, but manage passwords as you see fit
GROUP_NAMES = ['YOUR', 'DESIRED', 'GROUP', 'NAMES']
@divinorum-webb
divinorum-webb / tableau-api-lib-create-subscription.py
Last active November 2, 2021 21:42
tableau-api-lib-create-subscription
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_schedules_dataframe, get_users_dataframe, get_views_dataframe
SAMPLE_SCHEDULE_ID = <YOUR_SCHEDULE_ID>
SAMPLE_USER_ID = <USER_ID_FOR_USER_SUBSCRIBED>
SAMPLE_CONTENT_ID = <VIEW_OR_WORKBOOK_ID_FOR_SUBSCRIPTION>
SAMPLE_CONTENT_TYPE = <VIEW_OR_WORKBOOK> # this value can 'view' or 'workbook' and is not case sensitive
tableau_server_config = {
@divinorum-webb
divinorum-webb / tableau-api-lib-create-sync-group-subscriptions.py
Last active March 21, 2020 00:06
tableau-api-lib-create-sync-group-subscriptions
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_groups_dataframe, get_group_users_dataframe, get_schedules_dataframe, \
get_subscriptions_dataframe
TEST_GROUP_ID = '<YOUR_GROUP_ID>'
TEST_SCHEDULE_ID = '<YOUR_SCHEDULE_ID>'
TEST_CONTENT_ID = '<YOUR_VIEW_ID>'
TEST_CONTENT_TYPE = 'view' # in this tutorial, my subscription is for a Tableau view
TEST_SUBSCRIPTION_SUBJECT = '<YOUR_SUBSCRIPTION_SUBJECT>'
import io
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_views_dataframe, get_view_data_dataframe
VIEW_ID = '<YOUR_VIEW_ID>'
CUSTOM_PARAMS = {
'region': 'vf_Region=East,West',
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_users_dataframe, get_sites_dataframe
SITE_NAME_TEXT = '<YOUR_OPTIONAL_SITE_NAME_TEXT>'
TABLEAU_SERVER_CONFIG = {
'my_env': {
'server': 'https://YourTableauServer.com',
'api_version': '<YOUR_API_VERSION>',
@divinorum-webb
divinorum-webb / tableau-api-lib-clone-schedules.py
Last active March 31, 2020 19:23
Template code for the step-by-step tutorial on cloning Tableau Server schedules using tableau-api-lib.
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_schedules_dataframe
from tableau_api_lib.utils.cloning import clone_schedules
TABLEAU_SERVER_CONFIG = {
'my_env': {
'server': 'https://<YOUR_SERVER>.com',
'api_version': '<YOUR_API_VERSION>',
'username': '<YOUR_USERNAME>',
@divinorum-webb
divinorum-webb / create-hyper-extract-from-csv.py
Created April 3, 2020 19:13
Creating a Tableau Hyper extract from a CSV file with Python using the Hyper API
from tableauhyperapi import HyperProcess, Connection, TableDefinition, SqlType, Telemetry, Inserter, CreateMode, TableName
from tableauhyperapi import escape_string_literal
PATH_TO_CSV = 'sample_csv_for_hyper.csv'
PATH_TO_HYPER = 'test_hyper_extract_api.hyper'
# Step 1: Start a new private local Hyper instance
with HyperProcess(Telemetry.SEND_USAGE_DATA_TO_TABLEAU, 'myapp' ) as hyper:
@divinorum-webb
divinorum-webb / create-hyper-extract-from-pandas-dataframe.py
Created April 3, 2020 19:18
Creating a Tableau Hyper extract from a Pandas DataFrame using the Hyper API
import pandas as pd
from tableauhyperapi import HyperProcess, Connection, TableDefinition, SqlType, Telemetry, Inserter, CreateMode, TableName
from tableauhyperapi import escape_string_literal
PATH_TO_CSV = 'sample_csv_for_hyper.csv'
PATH_TO_HYPER = 'test_hyper_extract_api.hyper'