[deprecated] How to run Python scripts in Tines using the Tines Toolkit

Tines now supports running Python scripts in your stories. This guide enables you to integrate Python code into your workflows without needing an external API endpoint.

The event data, input and output of your script, is stored in a separate tenant managed by Tines. We recommend not passing sensitive data through the event and testing your script thoroughly before integrating it into your workflows.

Important Note: The Tines Toolkit is a Cloud based service entirely separate from your tenant. To use it, you must be able to send HTTP Requests out to https://toolkit.tines.com

Getting started with Python scripts 

To start running scripts:

  1. Go into templates and search for the 'Execute Python Script' group action template

  2. Pull this onto your storyboard

  3. Populate the necessary script parameters

The template action expects two objects: input and script. The input object is the first object which contains key-value fields that will send to your code as parameters. The script object is the second object which contains the code to execute.

Try it out:

Copy and paste the below into your storyboard to see a simple example.

{"standardLibVersion":"32","actionRuntimeVersion":"4","agents":[{"disabled":false,"name":"Execute Python Script","description":"Runs a Python script, passing in input from received events.","options":"{\"input\":{\"message\":\"<<generate_data.message>>\"},\"script\":\"import re\\n\\ndef main(input):\\n    message = input['message']\\n    # Remove credit card numbers\\n    message = re.sub(r\\\"\\\\b(?:\\\\d[ -]*?){13,16}\\\\b\\\", \\\"[CREDIT CARD]\\\", message)\\n    \\n    # Remove social security numbers\\n    message = re.sub(r\\\"\\\\b\\\\d{3}-?\\\\d{2}-?\\\\d{4}\\\\b\\\", \\\"[SSN]\\\", message)\\n    \\n    # Remove email addresses\\n    message = re.sub(r\\\"\\\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\\\.[A-Za-z]{2,}\\\\b\\\", \\\"[EMAIL]\\\", message)\\n    \\n    return message\"}","position":{"x":1560,"y":1785},"type":"group","group":{"name":"","description":null,"actions":[{"type":"httpRequest","name":"Execute script using Toolkit","description":"This is an API endpoint that expects a POST request with a JSON object in the following format:\n\n{\n  \"input\": {\n    \"key\": \"value\"\n  },\n  \"script\": \"def main(input):\n                      your python script\"\n}\n\n\nThe input object contains key value fields, these will be send to your python code as parameters.\n\nThe script field in the input object is expected to contain a string that represents a Python script, which defines a function called main with a single parameter called input. The input parameter is expected to be a dictionary object.\n\nWhen the endpoint receives a valid POST request, it executes the provided Python script with the given input and returns a JSON object with the returning value.","disabled":false,"options":"{\"url\":\"https://toolkit.tines.com/api/public/execute-code\",\"content_type\":\"application_json\",\"method\":\"post\",\"payload\":{\"input\":\"=input.input\",\"script\":\"<<input.script>>\",\"requirements\":\"<<input.requirements>>\"},\"timeout\":\"60\",\"log_error_on_status\":[\"400-499\",\"500-503\",\"505-599\"]}","position":{"x":750,"y":-765},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null},{"type":"groupInput","name":"Input","description":null,"disabled":false,"options":"{\"options\":[{\"name\":\"Input\",\"type\":\"OBJECT\",\"description\":\"The input data which will be passed into your script.\"},{\"name\":\"Script\",\"type\":\"TEXT\",\"description\":\"The source code of your script. The logic of the script should be in a function called 'main'.\"},{\"name\":\"Requirements\",\"type\":\"TEXT\",\"required\":false,\"description\":\"Dependencies required to run the Python script in the same format of a requirements.txt file. Can be removed if the script doesn't require any dependencies.\"}]}","position":{"x":750,"y":-915},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null},{"type":"groupOutput","name":"Output","description":null,"disabled":false,"options":"{\"payload\":{\"output\":\"=IF(LOCAL.execute_result, LOCAL.execute_result, check_for_result.body.output)\",\"logs\":\"<<IF(LOCAL.execute_logs, LOCAL.execute_logs, check_for_result.body.logs)>>\"},\"local\":{\"execute_result\":\"=execute_script_using_toolkit.body.output\",\"execute_logs\":\"=execute_script_using_toolkit.body.logs\"}}","position":{"x":750,"y":-525},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null},{"type":"trigger","name":"Ran Successfully","description":null,"disabled":false,"options":"{\"rules\":[{\"type\":\"field==value\",\"value\":\"200\",\"path\":\"<< execute_script_using_toolkit.status>>\"}]}","position":{"x":750,"y":-645},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null},{"type":"groupOutput","name":"Error Output","description":null,"disabled":false,"options":"{\"payload\":{\"error\":\"=IF(execute_script_using_toolkit.body.error = NULL, check_for_result.body.error, execute_script_using_toolkit.body.error)\"}}","position":{"x":1260,"y":-255},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null},{"type":"trigger","name":"Error","description":null,"disabled":false,"options":"{\"rules\":[{\"type\":\"formula\",\"value\":\"<<NULL>>\",\"path\":\"=execute_script_using_toolkit.body.error != NULL || check_for_result.body.error != NULL\"}]}","position":{"x":1260,"y":-375},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null},{"type":"trigger","name":"Timed Out","description":null,"disabled":false,"options":"{\"rules\":[{\"type\":\"field==value\",\"value\":\"504\",\"path\":\"<<execute_script_using_toolkit.status>>\"}]}","position":{"x":1005,"y":-525},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null},{"type":"eventTransformation","name":"Wait 10 Seconds","description":null,"disabled":false,"options":"{\"mode\":\"delay\",\"seconds\":\"10\"}","position":{"x":1005,"y":-255},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null},{"type":"eventTransformation","name":"Only try 5 times","description":null,"disabled":false,"options":"{\"mode\":\"deduplicate\",\"path\":\"<<META.story_run.id>>\",\"tolerance\":\"5\",\"period\":\"600\"}","position":{"x":1005,"y":-375},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null},{"type":"trigger","name":"Response found","description":null,"disabled":false,"options":"{\"rules\":[{\"type\":\"field==value\",\"value\":\"200\",\"path\":\"<<check_for_result.status>>\"}]}","position":{"x":1005,"y":15},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null},{"type":"httpRequest","name":"Check for Result","description":null,"disabled":false,"options":"{\"url\":\"<<execute_script_using_toolkit.body.response_url>>\",\"content_type\":\"application_json\",\"method\":\"get\"}","position":{"x":1005,"y":-105},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null}],"links":[{"sourceIdentifier":1,"receiverIdentifier":0},{"sourceIdentifier":3,"receiverIdentifier":2},{"sourceIdentifier":6,"receiverIdentifier":8},{"sourceIdentifier":8,"receiverIdentifier":7},{"sourceIdentifier":7,"receiverIdentifier":10},{"sourceIdentifier":10,"receiverIdentifier":9},{"sourceIdentifier":9,"receiverIdentifier":2},{"sourceIdentifier":0,"receiverIdentifier":3},{"sourceIdentifier":3,"receiverIdentifier":6,"secondary":true},{"sourceIdentifier":6,"receiverIdentifier":5,"secondary":true},{"sourceIdentifier":5,"receiverIdentifier":4},{"sourceIdentifier":9,"receiverIdentifier":5,"secondary":true},{"sourceIdentifier":5,"receiverIdentifier":8,"secondary":true}],"annotations":[]},"timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null,"recordType":null,"recordWriters":[],"form":null,"cardIconName":null,"cardIconImageContents":"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxv\nbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8v\nd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgoKPHN2ZwogICB2ZXJzaW9uPSIxLjAi\nCiAgIGlkPSJzdmcyIgogICBzb2RpcG9kaTp2ZXJzaW9uPSIwLjMyIgogICBp\nbmtzY2FwZTp2ZXJzaW9uPSIxLjIuMSAoOWM2ZDQxZTQxMCwgMjAyMi0wNy0x\nNCkiCiAgIHNvZGlwb2Rp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LjY4MDIyLC0xNi40NzU3NzYgMCwtMjcuMjUgLTEuOTI1\nNzgsLTcuNzU3NDQxIC01LjYwMzg3LC0xMy41OTM3NSAtMTMuNDA2MjQxLC0x\nMy41OTM3NSB6IG0gLTE1LjA2MjUsNjQuNjU2MjUgYyAyLjc3OTQ3OCwzZS02\nIDUuMDMxMjUsMi4yNzc0MTcgNS4wMzEyNSw1LjA5Mzc0NyAtMmUtNiwyLjgy\nNjM1NCAtMi4yNTE3NzUsNS4xMjUwMDQgLTUuMDMxMjUsNS4xMjUwMDQgLTIu\nNzY5NTUsMCAtNS4wMzEyNSwtMi4yOTg2NSAtNS4wMzEyNSwtNS4xMjUwMDQg\nMmUtNiwtMi44MTYzMyAyLjI2MTY5NywtNS4wOTM3NDcgNS4wMzEyNSwtNS4w\nOTM3NDcgeiIKICAgICBpZD0icGF0aDE5NTAiIC8+CiAgPGVsbGlwc2UKICAg\nICBzdHlsZT0ib3BhY2l0eTowLjQ0MzgyO2ZpbGw6dXJsKCNyYWRpYWxHcmFk\naWVudDE0ODApO2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0\ncm9rZTpub25lO3N0cm9rZS13aWR0aDoxNS40MTc0O3N0cm9rZS1taXRlcmxp\nbWl0OjQ7c3Ryb2tlLWRhc2hhcnJheTpub25lO3N0cm9rZS1vcGFjaXR5OjEi\nCiAgICAgaWQ9InBhdGgxODk0IgogICAgIGN4PSI1NS44MTY3NjEiCiAgICAg\nY3k9IjEyNy43MDA3OSIKICAgICByeD0iMzUuOTMwOTc3IgogICAgIHJ5PSI2\nLjk2NzMxMTkiIC8+Cjwvc3ZnPgo=\n","cardIconImageFilename":"Python-logo-notext.svg","createdFromTemplateGuid":null,"createdFromTemplateVersion":null,"originStoryIdentifier":"cloud:d521f765a49c72507257a2620612ee96:7c746bd2b6e1c267b1fcba09aefe9d86"},{"disabled":false,"name":"generate data","description":null,"options":"{\"mode\":\"message_only\",\"loop\":false,\"payload\":{\"message\":\"Please do not share your credit card number (1234-5678-9012-3456) or your social security number (123-45-6789). You can contact us at example@example.com.\"}}","position":{"x":1560,"y":1695},"type":"eventTransformation","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null,"recordType":null,"recordWriters":[],"form":null,"cardIconName":null,"createdFromTemplateGuid":null,"createdFromTemplateVersion":null,"originStoryIdentifier":"cloud:9a1b89cf9149a49b190c4b34e90866a0:ee398ae9f7dd021c860cbb54d85e0cd9"},{"disabled":false,"name":"result","description":null,"options":"{\"mode\":\"message_only\",\"loop\":false,\"payload\":{\"output\":\"=execute_python_script.output\"}}","position":{"x":1560,"y":1875},"type":"eventTransformation","timeSavedUnit":"minutes","timeSavedValue":0,"monitorAllEvents":false,"monitorFailures":false,"monitorNoEventsEmitted":null,"recordType":null,"recordWriters":[],"form":null,"cardIconName":null,"createdFromTemplateGuid":null,"createdFromTemplateVersion":null,"originStoryIdentifier":"cloud:9a1b89cf9149a49b190c4b34e90866a0:ee398ae9f7dd021c860cbb54d85e0cd9"}],"links":[{"sourceIdentifier":1,"receiverIdentifier":0},{"sourceIdentifier":0,"receiverIdentifier":2}],"diagramNotes":[]}

Let's dig into a practical example 

The Python script below takes in a dictionary object with a message key and replaces any credit card numbers, social security numbers, and email addresses in the message with placeholders.

import re

def main(input):
    message = input['message']
    # Remove credit card numbers
    message = re.sub(r"\\b(?:\\d[ -]*?){13,16}\\b", "[CREDIT CARD]", message)
    
    # Remove social security numbers
    message = re.sub(r"\\b\\d{3}-?\\d{2}-?\\d{4}\\b", "[SSN]", message)
    
    # Remove email addresses
    message = re.sub(r"\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}\\b", "[EMAIL]", message)
    
    return message

Running the script 

To run this script using the template action, populate the script field with the given script and input field with an object that has a message key. The value for message should be the text you want to process.

After running the script, the processed text will be returned with any credit card numbers, social security numbers, and email addresses replaced with placeholders.

Limitations and considerations 

There are three limitations to keep in mind.

  1. Rate limiting. For script runs originating from your Tines tenant, the rate limit is 10 per minute. For anonymous requests, the limit is set to 5 per hour.

  2. Timeout. The feature employs a 10-second timeout window.

  3. Programming languages. This feature is limited to Python scripts. It does not run other programming languages.

Before deploying code, confirm it meets the the following:

  • [ ] Executes within 10-seconds

  • [ ] Accounts for rate limiting

  • [ ] Written in Python

Running scripts with dependencies 

In addition to the 'Execute Python Script' template, there is an 'Execute Python Script With Dependencies' group template. This template accepts one additional input, Requirements. The Requirements input accepts a list of Python dependencies that are needed to execute your script. This input should follow the same formatting as a requirements.txt file, a common convention in Python dependency management.

This is a great way for highly technical users to run scripts in Tines.

Was this helpful?