> ## Documentation Index
> Fetch the complete documentation index at: https://docs.markifact.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python

> Executes arbitrary Python code and returns the result

Executes arbitrary Python code and returns the result. Use only for actions not supported by existing nodes. Supports all standard and data analysis libraries (e.g., pandas, numpy, requests, seaborn, urllib, nltk, beautifulsoup4) You can also install additional packages . The last line of your code must be the value to return. To return multiple values, combine them into a single dict (e.g., \{'key1': value1, 'key2': value2}). Provide valid Python code as input. Dynamic values from other nodes are automatically injected as direct variables into the execution context, so you can reference them directly in your code without defining them (e.g., if you set 'payload' in variables, just use 'payload' directly).

|                     |               |
| ------------------- | ------------- |
| **App**             | Code          |
| **Operation ID**    | `code_python` |
| **Type**            | Action        |
| **Connection**      | None          |
| **Credits per run** | 2             |

## Inputs

| Field       | Type            | Required | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ----------- | --------------- | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `variables` | object          | No       | -       | Top-level variables injected into the execution context before your code runs.  • Keys must be valid Python identifiers (e.g., account\_ids, keywords).   • Values can be literals or placeholders like \{\{nodeId.data}}; placeholders are   resolved and type-cast to the correct Python types automatically.  Example:   \{"keywords": "\{\{googleAdsNodeId.data}}", "accounts": "\{\{accountNode.data}}"}  You can reference these directly in code (no imports or parsing needed), e.g.:   result = \{"count": len(accounts), "first\_kw": keywords\[0]}                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `packages`  | array of string | No       | -       | Additional Python packages to install in the sandbox (max 5 packages).  • Provide a list of package names • Common packages like pandas, numpy, requests are already available. Don't try to reinstall them. • Packages will be installed using pip before code execution  Example: \['countryinfo==0.1.2']                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `code`      | string          | Yes      | -       | The Python code to be executed supports all standard and data analysis libraries. Examples include: pandas, numpy, requests, seaborn, urllib, nltk, beautifulsoup4. Follow the instructions below when writing your code:     - Your code must return a result — place it as the last line so it is captured as the output.     - To return multiple values, combine them into a single dict, e.g.: \{"key1": value1, "key2": value2}     - The final value must be one of these JSON-safe types: dict, list, str, int, float, bool, or None.     - Do not print the result; only return it as the last expression.     - Do not return complex objects such as DataFrames, NumPy arrays, sets, custom classes, or functions. Convert them to plain lists or dicts first.  **Important**: Do not define or assign dynamic variables here. They are provided automatically and will already exist as direct variables in the execution context (e.g., if you defined 'payload' in variables, just use 'payload' directly in your code). |

## Output

**Type**: `Any`

Returns whatever the last line of the code evaluates to. Can be any type (str, int, list, dict, etc). If files are created, returns dict with 'result' and 'files' keys.
