HelpCreateUse code and webhooks in Zaps

Use Python code in Zaps

Last updated:

Code steps allow Zaps to run small snippets of Python or JavaScript. This tutorial is for Python code steps, but you can also learn how to use JavaScript code in your Zaps.

Code steps can be used as both triggers and actions.


Python is an advanced programming language. If you're not familiar with Python, it's recommended to ask a developer for help. Zapier does not offer email support for code steps. If you encounter a problem, we recommend asking questions on StackOverflow and tagging them with "Zapier".

For tips and inspiration, check out Python code examples.

1. Add a code trigger

  • In the Zap editor, click the Trigger step.
  • Search for and select Code by Zapier.
  • Click the Trigger Event dropdown menu and select Run Python.
  • Click Continue.

2. Set up your code step

  • In the Code field, enter your Python code.
  • Click Continue.

3. Test your code trigger

  • Click Test trigger.

If your code is valid, the step will show it was successful and display the data. Once the trigger is set up, you can continue to add your action step.

4. Add a code action

The Code action step allows you to write code that will interact with data coming from the trigger, or a previous action step.

  • In the Zap editor, click the + icon to add a new step.
  • Search for and select Code by Zapier.
  • Click the Action Event dropdown menu and select Run Python.
  • Click Continue.

5. Set up your code action

  • In the Code field, enter your Python code.
    • You can also define data fields to be provided to the code as strings with the Input Data fields. Provide a key and a value for each field.
  • Click Continue.

6. Test your code action

  • Click Test & Review.
  • If your code is valid, the step will show it was successful and display the data sent.

The Python environment

The environment is vanilla Python 3.7.2 (2.7.10 for Zaps created before January 24, 2019). Your script is sandboxed and can only run for a limited amount of time and within a limited amount of memory—the exact limits depend on your Zapier plan.


Dates and times in Code actions use the UTC timezone, even if a different one is set for the account or the Zap.

Input data for Code steps

In your code step, you have access to the input_data dictionary variable where all values will be strings. Since the amount of data that might feed into your script might be large or highly dynamic, you'll need to define an input_data mapping via Zapier’s GUI by providing a key and value.

The fields `item`, `name` and `currency` defined on the `input_data` dictionary, based on trigger data.


It's not possible to map input_data in Code by Zapier triggers.

Output data from code steps

Code steps return a single output variable, which is a dictionary or list of dictionaries that will be the result of this step.

  • You can explicitly return early.
  • The output must be JSON serializable.
  • Setting the output to a list of dictionaries will run the subsequent steps multiple times, once for each item in the list.

If you use Code by Zapier as the Zap's trigger and an empty array is returned, nothing will happen. The behavior will be similar to a polling trigger that did not get any results in the HTTP response. This functionality is exclusive to triggers.

Utilities in Code steps

There are a few utilities available in Code steps:

  • requests: an easy-to-use HTTP client.
  • StoreClient : a built-in utility for storing and retrieving data between Zap runs.
  • print: this utility allows you to debug your function. You'll need to test your Zap to see the values. The logs are returned in a runtime_meta added automatically to the output.

Testing and debugging Code steps

Running your Zap via the dashboard is the canonical way to confirm the behavior you expect. Your Zap History will have all relevant details around the Code step's input_data, output and logs. The test step in the editor can be used for a tighter feedback loop.

Limitations with Code steps

  • The Free plan can run scripts of up to 1 second and 128 MB of RAM. Paid plans can run scripts of up to 10 seconds and 256 MB of RAM. Your Zap will error if it exceeds these limits.
  • You cannot require external libraries or install libraries commonly referred to as "pip modules". Only the standard Python library and requests are available in the Code app and requests is already included in the namespace.
  • Code Steps are limited to 75 runs every 10 seconds.

How floats and integers are handled

The Zapier web UI does not distinguish between integers and float values—they are all presented as numbers. For example, if your Python code step returns a value like this:

return {'result': 1.0}

This may appear as 1, rather than 1.0, in your Zap history and test results. This is an artifact of the Zapier UI. You can use int(aNumber) or float(aNumber) in your Python code step to convert the value to the data type you require.

Need more help?

Contact Support

Tell us about your problem, and we’ll find you a solution or you can email support.
Get Help

Hire an Expert

We have a directory of professionals across the globe who are ready to help.
Find a Zapier Expert

Zapier Community

Connect with other Zapier users and industry professionals to get help crafting the perfect workflow.
Check out the community

Zapier University

Video courses designed to help you become a better Zapier user, whether you’re a beginner or more experienced.
View courses