Flow.Documentation

Building block: Python code

5 steps± 4 minVideoVerified 22 Oct 2026
  1. Step 1 · Open your development environment
  2. Step 2 · Create a Python building block
  3. Step 3 · Test the code
  4. Step 4 · Publish a version
  5. Step 5 · Give it to an agent

Sometimes what you need does not fit a standard step: your own calculation, an unusual conversion. Then you write a Python building block: a function run(input, ctx) that returns a JSON value. It runs isolated, with a time and memory limit and no network by default. You test it with sample input and publish a fixed version.

Watch the whole guide as a video5 steps in one film
Step 1 / 5

Open your development environment

In the portal, under Environments, click Development, and there Open. Flow opens in a new tab and you are signed in straight away.

  1. Click Development
Open your development environment · Click Development
  1. Click Open ↗
Open your development environment · Click Open ↗
Step 2 / 5

Create a Python building block

Click + next to General and choose Python code. In the middle is the code: an example that adds up the lines of an order. print() goes to the logs. On the right are the inputs, the test, the versions and the settings. Under Settings give it a name and a description.

  1. Click Add to General
Create a Python building block · Click Add to General
  1. Click Python code
Create a Python building block · Click Python code
Create a Python building block · The code with def run(input, ctx).
  1. Click Settings
Create a Python building block · Click Settings
  1. In Name, type Calculate order amount
  2. In Description, type Adds up the lines of an order: quantity times price.
Create a Python building block · In Name, type Calculate order amount; In Description, type Adds up the lines of an order: quantity times price.
  1. Click Save
Create a Python building block · Click Save
Step 3 / 5

Test the code

Under Test, give sample input and click ▶ Run test. The code really runs, in the isolated executor. You see the result and the print() output; on an error Flow points at the line in the code.

  1. Click Test
Test the code · Click Test
  1. Click Code
Test the code · Click Code
  1. In Test input, type {"items": [{"quantity": 2, "price": 12.5}, {"quantity": 1, "price": 49.95}]}
Test the code · In Test input, type {"items": [{"quantity": 2, "price": 12.5}, {"quantity": 1, "price": 49.95}]}
  1. Click ▶ Run test
Test the code · Click ▶ Run test
Test the code · The print() output: ‘2 lines calculated’.
Test the code · The result: 2 lines, total 74.95.
Step 4 / 5

Publish a version

With a passing test on the saved draft you can publish. Workflows (the Building block step) and agents only use published versions.

  1. Click Publish
Publish a version · Click Publish
Publish a version · Published v1.
Step 5 / 5

Give it to an agent

Open an agent and tick the building block under Brain → Tools. Python code counts as Changes: as long as the agent may not change anything, it is off. If it only calculates, set it to Reads with the button next to it.

  1. Click Agents
Give it to an agent · Click Agents
  1. Click the agent ‘Quote helper’
Give it to an agent · Click the agent ‘Quote helper’
  1. Click Calculate order amount
Give it to an agent · Click Calculate order amount
  1. Click Save
Give it to an agent · Click Save
Give it to an agent · The building block is on as one of the agent's tools.

This guide was carried out step by step on 22 Oct 2026 by an automated test on Flow (version 3e563176).