> For the complete documentation index, see [llms.txt](https://docs.brigge.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.brigge.ai/documentation/brigge-for-transformers/pipelines/pipeline-nodes/custom-script-node.md).

# Custom script node

## Overview

Brigge pulls data from a source system and pushes it to a destination system, using [field mappings](/documentation/brigge-for-transformers/pipelines/pipeline-nodes/map-node.md) to determine relationships between source and target fields. For cases where source data doesn't fit the destination structure cleanly, a [data transformation library](/documentation/brigge-for-transformers/pipelines/data-transformations.md) is available, so you can manipulate source values before they are pushed to the target system.

However, some data manipulation requirements go beyond the remit of standard transformations. In this case, you can use the *Custom script* node to write and then apply a script.&#x20;

The *Custom script* node includes an editor panel, where you can develop the required script. If you have coding experience, you can write the script directly - alternatively, tell Briggette what you need in plain English, and let AI write the script for you.&#x20;

Once you save the node, the script runs at the point you placed it in the pipeline.

## Script languages

Custom scripts can be coded in the following languages:

* Python
* PHP

## Adding a custom script

Having placed a *Custom script* node on the canvas, click it to access configuration options:

<div data-with-frame="true"><figure><img src="https://2172380191-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8IqdqwZowcxtFpZfLa6k%2Fuploads%2FXrw7fcAFWTxspN1UUsNz%2FNode%20-%20custom%20script.svg?alt=media&amp;token=cd373e67-85f3-4ad0-b343-616bb01c9d4e" alt=""><figcaption></figcaption></figure></div>

Script creation options and features are summarised below:

{% stepper %}
{% step %}
**Select script language and version**

Select your preferred [script language](#script-language-examples) and version using dropdown fields.
{% endstep %}

{% step %}
**Load example**

If you are writing your own script, it can be useful to load a [predefined example](#script-language-examples) to see how data should be passed in and out.  &#x20;
{% endstep %}

{% step %}
**Ask AI for assistance**

If you need help to develop the script - either from first principles or having made a start yourself - click `generate with AI` and enter your requirements. The script is generated and added to the editor. &#x20;
{% endstep %}

{% step %}
**Full screen editor**

Use this option to open the script editor in a full window, with an [integrated testing panel](#testing-a-custom-script).&#x20;
{% endstep %}
{% endstepper %}

## Testing a custom script

When the custom script editor is open in full-screen mode, test options are available in the right panel so you can test the current script. In this way, you can make changes to your script and test the outcome immediately:

<div data-with-frame="true"><figure><img src="https://2172380191-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8IqdqwZowcxtFpZfLa6k%2Fuploads%2FuPrC9SCXfJG7X3lAObi8%2FCustom%20script%20-%20full%20screen.svg?alt=media&amp;token=e00d7b1d-2566-4a3d-9544-1e9b495a2920" alt=""><figcaption></figcaption></figure></div>

From here:

{% stepper %}
{% step %}
**View and update your script**

On the left, make changes to your script in the script editor.&#x20;
{% endstep %}

{% step %}
**Add a test payload**

On the right, paste a test payload into the payload section. Ensure that this payload is the same structure as the script node will receive when the pipeline runs, and that it includes enough data to check the script works as expected.&#x20;
{% endstep %}

{% step %}
**Execute the test**

Click the `test script` button to run the current script against your test payload.&#x20;
{% endstep %}

{% step %}
**Check test output**

Review the execution result section. For a successful response, you'll see the processed version of your test payload. In the event of an error, you'll see error details.
{% endstep %}
{% endstepper %}

## Script language examples

### Python template

{% code overflow="wrap" lineNumbers="true" %}

```python
import sys
import json
import os

# Brigge passes your payload in one of two ways depending on its size.
# For payloads over 2MB, Brigge writes the data to a file called payload.txt.
# For smaller payloads, the data is passed in directly via stdin.
# The block below handles both cases automatically — do not remove it.
if os.path.exists("payload.txt"):
    with open("payload.txt", "r") as f:
        payload = f.read()
else:
    payload = sys.stdin.readline()

# This converts the raw payload into a Python object you can work with.
# Do not remove this line.
parsed = json.loads(payload)

# Add your logic here.

# This sends the result back into the pipeline as JSON.
# Always end your script with this line — do not remove it.
print(json.dumps(parsed, indent=4))
```

{% endcode %}

### PHP template

{% code overflow="wrap" lineNumbers="true" %}

```php
<?php

// Brigge passes your payload in one of two ways depending on its size.
// For payloads over 2MB, Brigge writes the data to a file called payload.txt.
// For smaller payloads, the data is passed in directly via stdin.
// The block below handles both cases automatically — do not remove it.
if (file_exists("payload.txt")) {
    $payload = file_get_contents("payload.txt");
} else {
    $payload = file_get_contents("php://stdin");
}

// Add your logic here.

// This sends the result back into the pipeline.
// Brigge expects the output to be base64 encoded — do not remove this line.
file_put_contents("php://stdout", base64_encode($payload));

?>
```

{% endcode %}
