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-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>'
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-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'
@divinorum-webb
divinorum-webb / tableau-api-lib-metadata-underlying-data-sources.py
Created April 11, 2020 00:37
Tutorial on using tableau-api-lib and Tableau's REST API and Metadata API to pull underlying data sources across the entire server.
import pandas as pd
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_sites_dataframe
SITE_NAMES = None # if this variable is None then all sites will be queried
# uncomment the line below if defining a subset of sites
# SITE_NAMES = ['SiteA', 'SiteB', 'SiteC'] # optional variable to define a subset of sites
@divinorum-webb
divinorum-webb / tableau-api-lib-create-webhooks.py
Created April 18, 2020 03:53
Creating Tableau Server webhooks using tableau-api-lib.
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_webhooks_dataframe
tableau_server_config = {
'my_env': {
'server': 'https://YourTableauServer.com',
'api_version': '<YOUR_API_VERSION>',
'username': '<YOUR_USERNAME>',
WITH events AS (
SELECT DISTINCT MAX(DATE_TRUNC('day', created_at)) AS last_interaction_date
, hist_target_site_id
, hist_workbook_id
, hist_datasource_id
, hist_flow_id
, historical_event_type_id
FROM historical_events
GROUP BY 2, 3, 4, 5, 6
),
import pandas as pd
from sqlalchemy import create_engine # make sure you also have the psycopg2 package installed via pip
pg_config = {
'host': '<YOUR_HOST_NAME>',
'port': '8060',
'database': 'workgroup',
'username': 'readonly',
'password': '<YOUR_PASSWORD>'