Where to look at?
It is very easy to install (with
pip install tabpy command) TabPy and start (with
tabpy command) TabPy instance… but what if you need to make changes is some configuration settings? You may want to use a different port because the default
9004 is in use by some other application, or you may need to run multiple TabPy instances on the same machine for some reason. Or you want to change the level of logging for it to be more/less verbose or location of the log file.
The first thing to look at is the documentation page for how to customize TabPy settings. As you can see there are some settings which names start with
TABPY_ prefix – those can be overwritten with environment variables.
Modifying individual settings with environment variables
If you only need to modify one or two parameters the simplest way to do so is to set the value for the parameter by setting the environment variable with the same name. Example for Windows for how to modify default TabPy port:
(Python 3.6) C:\Users\oleks_000>set TABPY_PORT=6311 (Python 3.6) C:\Users\oleks_000>tabpy 2020-01-20,16:45:59 [DEBUG] (app.py:app:207): Parameter port set to "6311" from config file or environment variable ... 2020-01-20,16:45:59 [INFO] (app.py:app:93): Web service listening on port 6311
For macOS and Linux use
export TABPY_PORT=6311 command instead of
set command in the example above.
The environment variable set in the way shown above won’t keep its value between terminal sessions – as soon as the terminal is closed not just the value of the variable but the variable itself won’t exist anymore.
This is one reason to use a configuration file to preserve configuration settings. Another reason is in the file you can modify multiple settings at once and even have set of files for different configurations.
Starting TabPy with a configuration file
On TabPy documentation page mentioned above (https://github.com/tableau/TabPy/blob/master/docs/server-config.md#custom-settings) there is an example of a configuration file. Copy it to some local file and edit as needed.
In the file, you only need to specify settings that have to be different from defaults. Here’s the file I use for the next example:
[TabPy] TABPY_PORT = 6311 TABPY_MAX_REQUEST_SIZE_MB = 250 TABPY_EVALUATE_TIMEOUT = 60 [loggers] keys=root [handlers] keys=rootHandler [formatters] keys=rootFormatter [logger_root] level=INFO handlers=rootHandler qualname=root propagete=0 [handler_rootHandler] class=StreamHandler level=DEBUG formatter=rootFormatter args=(sys.stdout,) [formatter_rootFormatter] format=%(asctime)s [%(levelname)s] (%(filename)s:%(module)s:%(lineno)d): %(message)s datefmt=%Y-%m-%d,%H:%M:%S
I stored the file as
c:\tabpy\demo.conf and now can use it when starting TabPy with specifying custom configuration using
--config command-line parameter :
(Python 3.6) C:\Users\oleks_000>tabpy --config c:\TabPy\demo.conf 2020-01-20,17:02:12 [INFO] (app.py:app:280): Loading state from state file c:\users\oleks_000\appdata\local\conda\conda\envs\python 3.6\lib\site-packages\tabpy\tabpy_server\state.ini 2020-01-20,17:02:12 [INFO] (app.py:app:311): Password file is not specified: Authentication is not enabled 2020-01-20,17:02:12 [INFO] (app.py:app:327): Call context logging is disabled 2020-01-20,17:02:12 [INFO] (app.py:app:110): Initializing TabPy... 2020-01-20,17:02:12 [INFO] (callbacks.py:callbacks:42): Initializing TabPy Server... 2020-01-20,17:02:12 [INFO] (app.py:app:113): Done initializing TabPy. 2020-01-20,17:02:12 [INFO] (app.py:app:67): Setting max request size to 262144000 bytes 2020-01-20,17:02:12 [INFO] (callbacks.py:callbacks:62): Initializing models... 2020-01-20,17:02:12 [INFO] (app.py:app:93): Web service listening on port 6311
What are those logger settings I see in the configuration file?
Short answer – those are Python logger settings documentation for which you can find at Python logger documentation page. With those setting you can control what is logged (how verbose is the logging), where the log entries are stored (console, file, etc.), in what format (what is in the logged message), how to format timestamp for a message and so on.
This post explains some details about logger configuration for TabPy – How to Configure Logging in TabPy? Another post shows how to use colors for console logging – Add colors to TabPy console output.
And here is post explaining how to configure authentication for TabPy – How to configure TabPy with authentication and use it in Tableau.