tableau_rest_api 1.5.0 – 100% Unicode and more

The tableau_rest_api  Python library was built to specifically to encounter any issues that a user would run into when trying to solve business problems by implementing the Tableau REST API. v.1.5.0 brings some major changes, which I’m haphazardly listing out in this post. I highly recommend updating, but it you may need to update all your scripts to Unicode strings and there could be a few methods that work differently. It should be much faster on interactions with the REST API (the culmination of a lot of changes from many different versions).

100% Unicode

As mentioned in the Unicode post, Python 2.7 strings are different from Unicode strings, which start with a “u’ ” and look like

unicode_string = u'This is a Unicode string'

Starting with v1.5.0, all the previous strings within tableau_rest_api are defined as Unicode types rather than str . This means any text you pass into a method should be Unicode as well. Everything gets encoded correctly as UTF-8 text at the end. This follows the recommendations from the Python documentation to use Unicode types exclusively and only encode to UTF-8 when writing.

Check out the new for how to script using Unicode strings. One thing to remember is the Unicode declaration at the top

# -*- coding: utf-8 -*-

Also, make sure to convert any output using .encode(‘utf8’) or it may break the print statement.

name Lookup on Datasources and Workbooks

Workbooks and datasources can have the same ‘pretty name’ if they are in different projects. Previously the ‘name lookup’ methods of query_datasource_luid_by_name and query_workbook_luid_by_name through a NoMatchFoundException when more than 1 match for a name came through. That wasn’t ideal, because that Exception should really only be used when there was nothing found at all. On the other hand, on a well groomed Tableau Server, the workbooks and datasources should have unique pretty names, so returning something complex like an array or an object seems like overkill in most cases.

Starting with v1.5.0, the most basic LUID lookup is now query_datasource_luid_by_name_in_project(name, p_name_or_luid=False) . If you don’t specify the p_name_or_luid parameter and multiple datasources are found, you will receive a MultipleMatchesFoundException . However, if you specific the project, the specific datasource name will be found (or a NoMatchFoundException will be raised).

There are methods with the old names, but they just call to the _in_project versions without the p_name_or_luid, which you can do yourself and is more recommended.

Logging Methods as Blocks

The Logger object now has start_log_block() and end_log_block()  methods, and the TableauRestApi object’s methods have been updated to call these methods so that it is much clearer the discrete actions that are happening in the logs.The logging is even more verbose, and many of newer classes finally have logging on nearly every called action (some set_ and get_ functions still don’t because it seems a bit unnecessary).

In fact, all of the classes now inherit from the new TableauBase class, which mostly implements the logging functionality but could implement more in the future.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s