You can deploy Python functions on TabPy and just call them from Tableau.
The second example in this blog post covers that. The function that classifies tumors as benign or malignant is opaque to Tableau and contains all the logic. Here is uses a gradient boosting model but it could be using any custom code.
TabPy documentation also has an example here under Deploying a function.
I hope this helps.