- Notifications
You must be signed in to change notification settings - Fork42
naskio/n8n-nodes-python
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
PythonFunction module - custom node for running python code on n8n.
run python code on n8n
PythonFunction node is used to run custom Python snippets to transform data or to implement some custom functionalitythat n8n does not support yet.
This node is pre-installed inthen8n-pythondocker image.
- Use
n8n-python:latest-debianif you are planning to install heavy python packages such asnumpyorpandas. - Use
n8n-python:latestfor a more lightweight image.
Example usingdocker-compose.yml
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.
This node requires the following dependencies to be installed in your environment:
Python 3.6 or higher
python3 --version# check output version# install fire pip install fire
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.
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 the
jsonattribute.You don't need to put the item in ajsonattribute. it will be done automatically.
theitems variable is a list of items that are passed to the function. They are directly accessible in the function.
Example:
print(items)# > listreturnitems
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
it is possible to write to the browser console by writing tostdout
Example:
print('Hello World')# orimport syssys.stdout.write('Hello World')stderris used for passing data between nodes.- if exit code is 0, the node will be executed successfully and
stderrrepresents the JSON representation of theoutput of the node - if exit code is not 0, the node fails and
stderrrepresents the error message
- if exit code is 0, the node will be executed successfully and
The
jsonattribute of each item is added and removed automatically. (you can access and return the items directlywithout thejsonattribute)
Pull requests are welcome! For any bug reports, please create an issue.
About
Run Python code on n8n
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.
