Use Python Code in Zapier Zaps
Using Python code in Zapier lets you customize automations, transform data, and run logic that is not available in standard app actions. This guide explains how to add the Code by Zapier app, configure Python steps, and safely work with data from other steps in your workflows.
The information in this tutorial is based on the official help documentation so you can confidently build and troubleshoot Python-based automations.
What is the Code by Zapier Python Action?
The Code by Zapier app includes a Python action that runs a small piece of server-side Python within a Zap. The code executes when the Zap runs and can send data to later steps.
Typical use cases include:
- Formatting and cleaning text or numbers
- Performing calculations across multiple fields
- Creating custom conditional logic
- Assembling or restructuring JSON objects
The Python step is best for lightweight code. It is not a replacement for a full application server, but it is powerful for inline automation logic.
How to Add Python Code to a Zapier Zap
Follow these steps to insert a Python action in your Zapier workflow:
-
Open your Zap in the editor.
-
Click + to add a new step.
-
Search for Code by Zapier and select it.
-
Choose the Run Python action event.
-
Click Continue to open the code editor.
After adding the Python action, you can configure input data, write your code, and set up the output that later steps will use.
Configure Input Data for Python in Zapier
In the Code by Zapier Python step, you can pass values from earlier steps into your script as input data. This makes your code dynamic and connected to the rest of your automation.
Set Up Input Data Fields in Zapier
To add input data:
-
In the Python action, find the Input Data section.
-
Click + to add a new key-value pair.
-
Enter a name for the key (for example,
email,amount, oritems). -
Insert data from previous Zapier steps into the value field using the dropdown.
Each key becomes a variable in a dictionary named input_data inside your Python code.
Access Input Data in Zapier Python Code
Inside the code block, you work with a dictionary named input_data. For example:
# Access simple text fields
name = input_data["name"]
# Use get() if a value might be missing
email = input_data.get("email", "")
# Convert a numeric string to a number
amount = float(input_data.get("amount", 0))
All values arrive as strings by default. If you need numbers, booleans, or lists, convert them in your Zapier code using standard Python methods.
Write and Run Python Code in Zapier
The core of the Code by Zapier action is the Python editor. The editor provides a small environment where your script can run when the Zap triggers.
Basic Structure of Zapier Python Scripts
Every Python script in Zapier should follow this pattern:
-
Read from
input_data -
Perform calculations or transformations
-
Build a dictionary called
output -
Return
outputat the end
Example:
name = input_data.get("name", "")
# Do some processing
uppercase_name = name.upper()
# The output dictionary is what becomes available to later steps
output = {"uppercase_name": uppercase_name}
Whatever you assign to output appears as fields you can map in later Zapier steps.
Preview and Test Python Steps in Zapier
To test your script:
-
Make sure previous steps have sample data.
-
Open the Python action and click Test or Test Step.
-
Review the output fields shown in the test panel.
If the script runs successfully, you can use those output fields in later tasks within the same Zap.
Return Data from Python to Other Zapier Steps
The Code by Zapier Python action sends data forward as a JSON-like object. This is controlled by the output variable.
Creating the Output Dictionary in Zapier
Build your final result in a dictionary named output:
first = input_data.get("first", "")
last = input_data.get("last", "")
full_name = f"{first} {last}".strip()
output = {
"full_name": full_name,
"first_name_length": len(first),
"last_name_length": len(last)
}
Each key becomes a separate field, visible in later steps of your Zapier automation. You can then map those fields into emails, spreadsheets, or other apps.
Working with Lists and Objects in Zapier Outputs
The Python code can also return arrays or nested objects. For example:
items_raw = input_data.get("items", "")
items = [i.strip() for i in items_raw.split(",") if i.strip()]
output = {
"item_count": len(items),
"items": items
}
Zapier will expose item_count as a field and may let you use the items array in supported actions, depending on whether the following step supports line items or lists.
Limitations of Python Code in Zapier
There are specific constraints around how Code by Zapier runs Python:
-
Execution time: Scripts must complete quickly. Long-running code may time out.
-
Environment: Only standard Python libraries are available. Third-party packages cannot be imported.
-
Network access: Outbound HTTP requests may be restricted; the Python step is intended primarily for local data processing.
-
Resource limits: Memory and CPU are limited, so keep scripts concise.
Because of these limits, use the Code by Zapier Python feature for focused logic, not for large-scale data processing.
Error Handling in Zapier Python Steps
Errors in your Python script can cause the Zap run to fail. To avoid this, handle possible issues inside the code.
Use Try/Except in Zapier Code
Wrap risky operations in try/except blocks:
result = None
error_message = ""
try:
value = float(input_data.get("amount", 0))
result = value * 1.2
except Exception as e:
error_message = str(e)
output = {
"result": result,
"error": error_message
}
This approach prevents hard failures and lets later Zapier steps inspect the error field to decide what to do next.
Validate Inputs Before Processing in Zapier
Always check that required inputs are present:
name = input_data.get("name")
if not name:
output = {"error": "Missing name"}
else:
output = {"greeting": f"Hello, {name}!"}
Input validation can significantly reduce run-time errors in your automations.
Best Practices for Python in Zapier
When you design Python steps in Zapier, follow these guidelines for maintainable and reliable automations:
-
Keep scripts small: Break complex logic into multiple steps if needed.
-
Comment your code: Explain what key parts of the script do.
-
Use clear field names: Name
input_datakeys andoutputfields descriptively. -
Test often: Use sample runs in the Zap editor whenever you change your code.
Following these practices will make your Code by Zapier steps easier to debug and reuse.
Where to Learn More About Zapier and Python
You can explore more automation strategies and advanced usage of Zapier by reviewing specialized workflow resources. For broader automation and optimization guidance, you may also find useful articles at Consultevo.
For the official reference on using Python code within Zaps, including current limitations and examples, see the original help article at Use Python code in Zaps.
With these steps and recommendations, you can confidently integrate Python into your Zapier workflows to create flexible, custom automations.
Need Help With Zapier?
Work with ConsultEvo — a
Zapier Certified Solution Partner
helping teams build reliable, scalable automations that actually move the business forward.
