TabPy server installation and setup for Tableau

 

Introduction

TabPy (the Tableau Python Server) is an Analytics Extension implementation which expands Tableau’s capabilities by allowing users to execute Python scripts and saved functions via Tableau’s table calculations.

Requirements

  • Python 3.6 +

  • Pip

  • Running Tableau server

Installation directions

Note

Its recommended that tabpy be executed in a virtual environment and that is the installation and setup process highlighted below

  • Update pip

python -m pip install --upgrade pip

  • Install virtualenv package

pip install virtualenv

  • Create the Tabpy folder structures. This will be used to hold files needed by Tabpy and those generated by it such as logs. See example below in /opt/tabpy_server/ i.e.



  • Create virtual environment

virtualenv my-tabpy-env

  • Activate the environment

source my-tabpy-env/bin/activate


 

  • Install Tabpy

pip install tabpy

  • Create a password file. This file will be used to hold username and encrypted password details for Tabpy users

touch passwd.txt

  • Create a Tabpy user

tabpy-user add -u <username> -p <password> -f passwd.txt

  • Create a configuration file. This file allows you to pass runtime options to Tabpy easily when starting up

# Open a new file to write to

vim tabpy.conf

 

# Paste in details shared on the sample configuration file below and save

Create a startup script to run tabpy in the background using nohup

# Open file to write to

vim startup.sh

 

#paste in the details below

---------------

#!/bin/bash

 

nohup tabpy --config=tabpy.conf &

---------------

# Make file executable

chmod +x startup.sh

 

# Initialise script

./startup.sh

  • Check that server is running successfully and listening to port 9004


Setting up Tabpy extension on Tableau

After installing Tabpy, we need to add it under Analytics Extensions on Tableau. To do this:-

  • Navigate to Settings → Extensions → Analytic Extensions

  • Enable Analytics Extension for Site and restart Tableau

  • Once done, click on Create new connection and select Tabpy

  • Fill out the details on the form as below:-


    • Connection name: Unique name to identify this connection entry

    • Require SSL: Select No unless you have enabled HTTPS on Tabpy config

    • Hostname: FQDN or IP of node where Tabpy is installed

    • Port: 9004

    • Sign in with username and password: Yes

    • Username and Password: Enter details of user you created earlier

Configuration File Content

Configuration file consists of settings for TabPy itself and Python logger settings. You should only set parameters if you need different values than the defaults.

[TabPy] parameters:

  • TABPY_PORT - port for TabPy to listen on. Default value - 9004.

  • TABPY_QUERY_OBJECT_PATH - query objects location. Used with models, see TabPy Tools documentation for details. Default value - /tmp/query_objects.

  • TABPY_STATE_PATH - state folder location (absolute path) for Tornado web server. Default value - tabpy/tabpy_server subfolder in TabPy package folder.

  • TABPY_STATIC_PATH - absolute path for location of static files (index.html page) for TabPy instance. Default value - tabpy/tabpy_server/static subfolder in TabPy package folder.

  • TABPY_PWD_FILE - absolute path to password file. Setting up this parameter makes TabPy require credentials with HTTP(S) requests. More details about authentication can be found in Authentication section. Default value - not set.

  • TABPY_TRANSFER_PROTOCOL - transfer protocol. Default value - http. If set to https two additional parameters have to be specified: TABPY_CERTIFICATE_FILE and TABPY_KEY_FILE. Details are in the Configuring HTTP vs HTTPS section.

  • TABPY_CERTIFICATE_FILE - absolute path to the certificate file to run TabPy with. Only used with TABPY_TRANSFER_PROTOCOL set to https. Default value - not set.

  • TABPY_KEY_FILE - absolute path to private key file to run TabPy with. Only used with TABPY_TRANSFER_PROTOCOL set to https. Default value - not set.

  • TABPY_LOG_DETAILS - when set to true additional call information (caller IP, URL, client info, etc.) is logged. Default value - false.

  • TABPY_MAX_REQUEST_SIZE_MB - maximal request size supported by TabPy server in Megabytes. All requests of exceeding size are rejected. Default value is 100 Mb.

  • TABPY_EVALUATE_ENABLE - enable evaluate api to execute ad-hoc Python scripts Default value - true.

  • TABPY_EVALUATE_TIMEOUT - script evaluation timeout in seconds. Default value - 30. This timeout does not apply when evaluating models either through the /query method, or using the tabpy.query(...) syntax with the /evaluate method.

  • TABPY_GZIP_ENABLE - Enable Gzip support for requests. Enabled by default.

Sample configuration file

[TabPy]

TABPY_QUERY_OBJECT_PATH = /tmp/query_objects

TABPY_PORT = 9004

# TABPY_STATE_PATH = <package-path>/tabpy/tabpy_server

 

# Where static pages live

TABPY_STATIC_PATH = /opt/tabpy_server/exness_tabpy_server/static

 

# For how to configure TabPy authentication read

# docs/server-config.md.

TABPY_PWD_FILE = /opt/tabpy_server/exness_tabpy_server/passwd.txt

 

# To set up secure TabPy uncomment and modify the following lines.

# Note only PEM-encoded x509 certificates are supported.

# TABPY_TRANSFER_PROTOCOL = https

# TABPY_CERTIFICATE_FILE = /path/to/certificate/file.crt

# TABPY_KEY_FILE = /path/to/key/file.key

 

# Log additional request details including caller IP, full URL, client

# end user info if provided.

TABPY_LOG_DETAILS = true

 

# Limit request size (in Mb) - any request which size exceeds

# specified amount will be rejected by TabPy.

# Default value is 100 Mb.

# TABPY_MAX_REQUEST_SIZE_MB = 100

 

# Enable evaluate api to execute ad-hoc Python scripts

# Enabled by default. Disabling it will result in 404 error.

TABPY_EVALUATE_ENABLE = true

 

# Configure how long a custom script provided to the /evaluate method

# will run before throwing a TimeoutError.

# The value should be a float representing the timeout time in seconds.

TABPY_EVALUATE_TIMEOUT = 30

 

[loggers]

keys=root

 

[handlers]

keys=rootHandler,rotatingFileHandler

 

[formatters]

keys=rootFormatter

 

[logger_root]

level=DEBUG

handlers=rootHandler,rotatingFileHandler

qualname=root

propagete=0

 

[handler_rootHandler]

class=StreamHandler

level=DEBUG

formatter=rootFormatter

args=(sys.stdout,)

 

[handler_rotatingFileHandler]

class=handlers.RotatingFileHandler

level=DEBUG

formatter=rootFormatter

args=('tabpy_log.log', 'a', 1000000, 5)

 

[formatter_rootFormatter]

format=%(asctime)s [%(levelname)s] (%(filename)s:%(module)s:%(lineno)d): %(message)s

datefmt=%Y-%m-%d,%H:%M:%S

Links



That’s it. Just restart and use it.


Comments

Popular posts from this blog

Overview and practical use cases with open source tracing tool for Java Apps. Glowroot. Installation

How only 2 parameters of PostgreSQL reduced anomaly of Jira Data Center nodes

Atlassian Community, let's collaborate and provide stats to vendors about our SQL index usage