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 / devyx-example-not-using-cte.sql
Created December 5, 2023 20:45
devyx-example-not-using-cte
SELECT
hvc.customer_id
, total_revenue
, days_since_first_seen
FROM (
SELECT
customer_id
, SUM(total_revenue) AS total_revenue
FROM transaction_details td
LEFT JOIN customer_details cd
@divinorum-webb
divinorum-webb / devyx-sql-example-cte.sql
Created December 5, 2023 20:43
devyx-sql-example-cte
WITH high_value_customers AS (
SELECT
customer_id
, SUM(total_revenue) AS total_revenue
FROM transaction_details td
LEFT JOIN customer_details cd
ON td.card_id = cd.card_id
GROUP BY 1
ORDER BY 2 DESC
HAVING total_revenue > 500
@divinorum-webb
divinorum-webb / tableau-api-lib-query-project-permissions.py
Created August 17, 2022 20:07
tableau-api-lib-query-project-permissions
import pandas as pd
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.sample import sample_config
from tableau_api_lib.utils import querying, flatten_dict_column, flatten_dict_list_column
# sample config
tableau_server_config = {
'tableau_env': {
@divinorum-webb
divinorum-webb / tableau-api-lib-query-workbook-permissions.py
Last active July 23, 2022 19:01
tableau-api-lib-query-workbook-permissions.py
import pandas as pd
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.sample import sample_config
from tableau_api_lib.utils import querying, flatten_dict_column, flatten_dict_list_column
# sample config
tableau_server_config = {
'tableau_env': {
@divinorum-webb
divinorum-webb / tableau-api-lib-download-view-crosstab.py
Last active June 14, 2023 06:16
Template code for downloading view data and pivoting it using Python and tableau-api-lib
import pandas as pd
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.sample import sample_config
from tableau_api_lib.utils import querying
from tableau_api_lib.utils.common import flatten_dict_column
# sample config
tableau_server_config = {
@divinorum-webb
divinorum-webb / tableau-api-lib-remove-content-owners.py
Created May 29, 2020 20:20
Template code for removing Tableau users who own content using Python and tableau-api-lib
import pandas as pd
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils import querying, flatten_dict_column
# using personal access tokens is preferred; otherwise, comment those details out and use username / password
tableau_server_config = {
'my_env': {
'server': 'https://10ax.online.tableau.com', # replace with your own server
@divinorum-webb
divinorum-webb / tableau-api-lib-query-metadata-all-sites.py
Last active August 29, 2023 12:42
Template code for querying the Tableau Metadata API for all sites on a server
import pandas as pd
from pandas.io.json import json_normalize
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils import flatten_dict_column, flatten_dict_list_column
from tableau_api_lib.utils.querying import get_sites_dataframe
# using personal access tokens is preferred; otherwise, comment those details out and use username / password
tableau_server_config = {
@divinorum-webb
divinorum-webb / tableau-api-lib-query-metadata-all-sites.py
Created May 20, 2020 22:25
Template code for querying the Tableau Metadata API for all sites on a server
import pandas as pd
from pandas.io.json import json_normalize
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils import flatten_dict_column, flatten_dict_list_column
from tableau_api_lib.utils.querying import get_sites_dataframe
# using personal access tokens is preferred; otherwise, comment those details out and use username / password
tableau_server_config = {
@divinorum-webb
divinorum-webb / tableau-api-lib-impact-analysis-milestone3.py
Created May 6, 2020 22:56
Template code for the third milestone in my Medium blog series on building impact analysis reports for Tableau.
from sqlalchemy import create_engine
import pandas as pd
from pandas.io.json import json_normalize
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils import flatten_dict_column, flatten_dict_list_column
from tableau_api_lib.utils.querying import get_projects_dataframe
from tableauhyperapi import HyperProcess, Connection, TableDefinition, SqlType, Telemetry, Inserter, CreateMode, TableName
@divinorum-webb
divinorum-webb / tableau-hyper-api-pandas-dataframe.py
Last active May 6, 2020 22:06
Template code for building a Tableau .hyper data extract from a Pandas DataFrame.
# this code snippet will not run by itself; this is a piece of a larger workflow.
# a Pandas DataFrame named 'combined_df' is the source of data in this example
PATH_TO_HYPER = 'workbooks_and_owners.hyper'
# Step 1: Start a new private local Hyper instance
with HyperProcess(Telemetry.SEND_USAGE_DATA_TO_TABLEAU, 'myapp' ) as hyper:
# Step 2: Create the the .hyper file, replace it if it already exists
with Connection(endpoint=hyper.endpoint,