Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Run Python code on n8n

License

NotificationsYou must be signed in to change notification settings

naskio/n8n-nodes-python

Repository files navigation

n8n.io - Workflow Automation

PythonFunction module - custom node for running python code on n8n.

run python code on n8n

Python Function

PythonFunction node is used to run custom Python snippets to transform data or to implement some custom functionalitythat n8n does not support yet.

Installation

Using n8n-python Docker Image (Recommended)

This node is pre-installed inthen8n-pythondocker image.

  • Usen8n-python:latest-debian if you are planning to install heavy python packages such asnumpy orpandas.
  • Usen8n-python:latest for a more lightweight image.

Example usingdocker-compose.yml

Adding external packages

You can mount arequirements.txt file to the container to install additional packages.

You can use theExecuteCommand node torunpip install -r requirements.txtand then8nTrigger node to trigger it after eachrestart.

Install Locally

1- Install Requirements

This node requires the following dependencies to be installed in your environment:

  • Python 3.6 or higher

     python3 --version# check output version
  • python-fire

    # install fire pip install fire

2- Add n8n-nodes-python to your n8n instance

If you’re running either by installing it globally or via PM2, make sure that you installn8n-nodes-python inside n8n.n8n will find the module and load it automatically.

If using docker, add the following line to yourDockerfile:

# Install n8n-nodes-python moduleRUNcd /usr/local/lib/node_modules/n8n&& npm install n8n-nodes-python

Read more about the installation process inthen8n documentation - Use the n8n-nodes-module in production.

Usage

This node receivesìtems and should return a list ofitems.

Example:

new_items= []foriteminitems:item['newField']='newValue'new_items.append(item)returnnew_items# should return a list

The JSON attribute of each item is added and removed automatically.You can access the values directly without thejson attribute.You don't need to put the item in ajson attribute. it will be done automatically.

Variable: items

theitems variable is a list of items that are passed to the function. They are directly accessible in the function.

Example:

print(items)# > listreturnitems

Credentials: env_vars (optional)

You can specify environment variables to be used in the python code. The environment variables are accessible throwtheenv_vars dict.

Example:

print(env_vars)print(env_vars.get('MY_VAR','default_value'))# > dict

Logging to the browser console

it is possible to write to the browser console by writing tostdout

Example:

print('Hello World')# orimport syssys.stdout.write('Hello World')

Notes

  • stderris used for passing data between nodes.

    • if exit code is 0, the node will be executed successfully andstderr represents the JSON representation of theoutput of the node
    • if exit code is not 0, the node fails andstderr represents the error message
  • Thejson attribute of each item is added and removed automatically. (you can access and return the items directlywithout thejson attribute)

Contribute

Pull requests are welcome! For any bug reports, please create an issue.

License

Apache 2.0 with Commons Clause


[8]ページ先頭

©2009-2025 Movatter.jp