|
/ Documentation /Core Features/ Code by OttoKit (Python) – Complete User Guide

Code by OttoKit (Python) – Complete User Guide

Pre-built apps handle a lot, but not everything. Sometimes you need a quick calculation, a custom text transformation, or a logic check that simply doesn’t exist as a standard action. That’s where Code by OttoKit comes in.

Code by OttoKit lets you write and run Python directly inside your workflow, no external tools, no separate environment, no switching tabs. Just write your code, and OttoKit handles the rest.

What Is Code by OttoKit?

Code by OttoKit is a built-in workflow action that runs Python scripts as part of your automation. Think of it as a Python interpreter sitting right inside your workflow. You write the code, set your inputs, and OttoKit executes it on the spot.

You can use it to:

  • Transform or reformat data from earlier steps in your workflow
  • Run calculations and return the results as usable values
  • Parse and manipulate text, dates, and numbers
  • Build conditional logic that goes beyond what standard filters can do
  • Combine data from multiple steps into a new, custom format

Supported Python Features

Core Programming Concepts

  • Variables, Loops (for, while)
  • Conditional Statements (if, elif, else)
  • Functions (including recursive functions)

Data Types

  • Numbers: int, float
  • Text: str
  • Boolean: bool
  • Collections: list, dict, tuple, set

Safe Built-in Functions

  • print(), len(), sum(), min(), max(), abs(), sorted()
  • map(), filter(), type(), and more

Pre-Installed Modules

  • requests — Make API calls
  • uuid — Generate UUIDs
  • datetime — Handle date and time
  • random — Generate random numbers

What Is Not Allowed (For Security Reasons)

To maintain a secure and reliable platform, some Python capabilities are restricted.

Blocked Modules: You cannot import or use the following:

  • System and OS Access: os, sys, subprocess, shutil, socket, platform, multiprocessing, and similar modules
  • File Handling: Reading from or writing to files is not allowed
  • Low-Level System Access: inspect, pickle, marshal, importlib, and similar modules

Attempting to use these will throw an error like:

ImportError: Import of 'os' is blocked for security reasons.

Important Note: Curly Braces { } Are Stripped

Due to platform-level parsing rules, any content inside curly braces { } is automatically removed from your code. This affects f-strings and dictionary literals written with { }.

Problematic example (will not work):

name = "Alice"
print(f"Hello, {name}")  # This will break!

Safe and Recommended Alternatives

Use these approaches instead of curly braces:

Use String Concatenation

first_name = "John"
last_name = "Doe"
print("Full Name:", first_name + " " + last_name)

Use %-Style String Formatting

name = "Alice"
age = 30
print("Name: %s, Age: %d" % (name, age))

Use dict() Instead of { } for Dictionaries

person = dict(name="Alice", age=30)
print("Name is:", person["name"])

Example Code Snippets

Here are some handy code snippets you can use directly or adapt to your use case:

Basic Math

a = 10
b = 20
print("Sum is:", a + b)

Generate a UUID

import uuid
print("UUID:", str(uuid.uuid4()))

Make an API Request

import requests
res = requests.get("https://api.github.com")
print("GitHub Status:", res.status_code)

Recursive Function (Factorial)

def factorial(n):
 return 1 if n == 0 else n * factorial(n - 1)
print("Factorial of 5:", factorial(5))

Current Date and Time

from datetime import datetime
now = datetime.now()
print("Now:", now.strftime("%Y-%m-%d %H:%M:%S"))

How to Add Code by OttoKit to Your Workflow

Follow the steps below to add and configure a Code by OttoKit action in any workflow.

Step 1: Open your workflow and click the + button on the edge between two existing steps (or at the end of your workflow) to add a new action.

image

Step 2: In the Add Action panel that appears, click Apps and search for Code by OttoKit, or select it from the list.

image

Step 3: The Code by OttoKit panel opens with three tabs at the top: Select, Configure, and Test.

image

Select Tab

The Select tab is where you choose which action to run.

  • Change App — Shows “Code By OttoKit”. Click this to swap to a different app if needed.
  • Select Event — Click the dropdown and select Run Python. This is the only available event.

Once you select Run Python, click Continue to move to the Configure tab.

image

Configure Tab

The Configure tab contains one required field:

  • Python Code (required) – A full-featured code editor where you write your Python script. The editor supports syntax highlighting and accepts standard Python 3 code.

To reference data from earlier steps in your workflow, type @ inside the editor. A dropdown will appear showing all available data from previous steps.

image

Note: 

  • The Python Code field is required. You cannot proceed to the Test tab without entering code.
  • Always use print() to return output. This is how results appear in the OttoKit interface and become available as data for the next steps in your workflow.

After writing your Python code, click Continue to reach the Test tab. 

Test Tab

Click Test Action to run your code and verify it works. The output from your print() statements will appear here.

image

Once the test passes, click Save to add the step to your workflow.

image

Practical Use Cases

Price Calculation

Scenario: You run a WooCommerce store. When a new order is placed, you want to calculate the total price by multiplying the product quantity by the unit price, and pass that total into an invoice generation step.

Step 1: Set Up the Trigger

  1. Create a new workflow in OttoKit.
  2. Select WooCommerce as the trigger app.
  3. Choose Order Paid as the trigger event.
  4. Connect your WordPress site and click Fetch Data to load a sample order.
  5. Click Save.

Step 2: Add the Code by OttoKit Step

  1. Click the + button below the trigger.
  2. Search for Code and select Code by OttoKit.
  3. In the code editor, enter the following:
Python
quantity = 3
unit_price = 49.99
total = quantity * unit_price
print("Total: " + str(total))
  1. In a real workflow, replace the hardcoded values by mapping the quantity and unit price fields from your WooCommerce trigger data using the data picker.
  2. Click Test to run the code and confirm the output appears correctly.
  3. Click Save.

Step 3: Use the Output in the Next Step

  1. Click + below the Code step.
  2. Add your invoice or notification action — for example, a Gmail: Send Email or a PDF generation step.
  3. In the action, open the data picker and map the output from the Code step (the printed total) into the relevant field.
  4. Click Publish Workflow.

Now every order automatically calculates the total and passes it forward into your invoice step without any manual work.

Date Formatting

Scenario: A form submission trigger returns a raw date string like 2025-05-17T00:00:00. You want to reformat it to May 17, 2025, before it appears in a confirmation email sent to the customer.

Step 1: Set Up the Trigger

  1. Create a new workflow in OttoKit.
  2. Select your form app as the trigger and choose the Form Submitted event.
  3. Connect your account and click Fetch Data to load a sample submission that includes a date field.
  4. Click Save.

Step 2: Add the Code by OttoKit Step

  1. Click + below the trigger and add Code by OttoKit.
  2. In the code editor, enter the following:
Python
from datetime import datetime
raw_date = "2025-05-17T00:00:00"
parsed = datetime.strptime(raw_date, "%Y-%m-%dT%H:%M:%S")
formatted = parsed.strftime("%B %d, %Y")
print(formatted)
  1. Replace the hardcoded raw_date value by mapping the date field from your trigger data using the data picker.
  2. Click Test and confirm the output shows May 17, 2025.
  3. Click Save.

Step 3: Use the Output in the Email

  1. Click + below the Code step.
  2. Add a Gmail: Send Email action (or your preferred email app).
  3. In the email body, open the data picker and map the formatted date output from the Code step into your message.
  4. Click Publish Workflow.

Your customers now receive emails with a clean, readable date instead of a raw timestamp.

Name Formatting

Scenario: A form collects a full name in a single field (e.g., John Smith), but your CRM requires the first name and last name in separate fields. You want to split the full name automatically before it reaches the CRM.

Step 1: Set Up the Trigger

  1. Create a new workflow in OttoKit.
  2. Select your form app as the trigger and choose the Form Submitted event.
  3. Connect your account and click Fetch Data to load a sample submission with a full name field.
  4. Click Save.

Step 2: Add the Code by OttoKit Step

  1. Click + below the trigger and add Code by OttoKit.
  2. In the code editor, enter the following:
Python
full_name = "John Smith"
parts = full_name.split(" ", 1)
first_name = parts[0]
last_name = parts[1] if len(parts) > 1 else ""
print("First: " + first_name)
print("Last: " + last_name)
  1. Replace the hardcoded full_name value by mapping the full name field from your trigger data using the data picker.
  2. Click Test and confirm that both the first and last name appear in the output.
  3. Click Save.

Step 3: Map to the CRM

  1. Click + below the Code step.
  2. Add your CRM action — for example, Create Contact.
  3. In the action, open the data picker and map the First output to the First Name field and the Last output to the Last Name field.
  4. Click Publish Workflow.

Every form submission now creates a properly formatted CRM contact with the name split correctly, no manual cleanup required.

Custom Lead Scoring

Scenario: You collect leads through a form that asks for company size, budget range, and role. You want to assign a score to each lead based on those answers, and only pass high-scoring leads (score above 7) to a priority queue or notify your sales team.

Step 1: Set Up the Trigger

  1. Create a new workflow in OttoKit.
  2. Select your form app as the trigger and choose the Form Submitted event.
  3. Connect your account and click Fetch Data to load a sample submission.
  4. Click Save.

Step 2: Add the Code by OttoKit Step

  1. Click + below the trigger and add Code by OttoKit.
  2. In the code editor, enter the following:
Python
company_size = "enterprise"
budget = "above_50k"
role = "manager"
score = 0
if company_size == "enterprise":
    score = score + 4
elif company_size == "mid-market":
    score = score + 2
if budget == "above_50k":
    score = score + 4
elif budget == "10k_to_50k":
    score = score + 2
if role == "manager" or role == "director":
    score = score + 2
print("Score: " + str(score))
  1. Replace the hardcoded values by mapping the relevant form fields from your trigger data using the data picker.
  2. Click Test and confirm the score appears in the output.
  3. Click Save.

Step 3: Add a Filter and Route High-Scoring Leads

  1. Click + below the Code step and add a Filter app.
  2. Set the condition: Score (from the Code output) Is Greater Than 7.
  3. Below the Filter, add your action — for example, a Slack: Send Message to your sales channel or a CRM action to add the lead to a priority list.
  4. Click Publish Workflow.

Leads are now scored automatically on every form submission. Only the highest-value prospects make it through to your sales team.

Text Cleanup

Scenario: A webhook or form is sending customer names and email addresses that sometimes contain extra spaces, inconsistent capitalisation, or unwanted characters. You want to clean this data before it enters your CRM.

Step 1: Set Up the Trigger

  1. Create a new workflow in OttoKit.
  2. Select your trigger app and choose the relevant event (for example, Webhook Received or Form Submitted).
  3. Connect your account and click Fetch Data to load a sample with messy text fields.
  4. Click Save.

Step 2: Add the Code by OttoKit Step

  1. Click + below the trigger and add Code by OttoKit.
  2. In the code editor, enter the following:
Python
raw_name = "  john   smith  "
raw_email = "  [email protected]  "
clean_name = raw_name.strip().title()
clean_email = raw_email.strip().lower()
print("Name: " + clean_name)
print("Email: " + clean_email)
  1. Replace the hardcoded values by mapping the name and email fields from your trigger data using the data picker.
  2. Click Test and confirm the output shows John Smith and [email protected].
  3. Click Save.

Step 3: Pass the Cleaned Data to Your CRM

  1. Click + below the Code step.
  2. Add your CRM action — for example, Create Contact or Update Contact.
  3. Open the data picker and map the cleaned name and email outputs from the Code step into the correct fields.
  4. Click Publish Workflow.

From this point on, every incoming record is automatically cleaned before it touches your CRM, no more duplicate entries from capitalisation mismatches or stray spaces.

Tips, Limits, and Best Practices

  • Always use print() to return output — This is how results are shown in the OttoKit interface and passed to the next step.
  • Avoid long-running loops or deep recursion — These can cause timeouts or memory issues.
  • Output is limited to 5,000 characters — Any output beyond this limit is automatically truncated.
  • Use safe string formatting — Always use string concatenation or %-style formatting instead of f-strings to avoid the { } stripping issue.
  • Use @ to map data from previous steps — Type @ in the code editor to pick live data from your trigger or earlier actions.
  • Test before publishing — Click Test Action before saving to catch errors before your workflow goes live.

Need Help?

If you get stuck, our support team is happy to help.

Reach out at [email protected] or visit our support page. You can also browse more guides in the OttoKit Knowledge Base.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Scroll to Top