npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

n8n-nodes-python

v0.1.4

Published

Run Python on n8n.

Downloads

237

Readme

n8n-nodes-python

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 functionality that n8n does not support yet.

Installation

Using n8n-python Docker Image (Recommended)

This node is pre-installed in the n8n-python docker image .

  • Use n8n-python:latest-debian if you are planning to install heavy python packages such as numpy or pandas.
  • Use n8n-python:latest for a more lightweight image.

Example using docker-compose.yml

Adding external packages

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

You can use the ExecuteCommand node to run pip install -r requirements.txt and the n8nTrigger node to trigger it after each restart.

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 install n8n-nodes-python inside n8n. n8n will find the module and load it automatically.

If using docker, add the following line to your Dockerfile:

# Install n8n-nodes-python module
RUN cd /usr/local/lib/node_modules/n8n && npm install n8n-nodes-python

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

Usage

This node receives ìtems and should return a list of items.

Example:

new_items = []
for item in items:
		item['newField'] = 'newValue'
		new_items.append(item)
return new_items # should return a list

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

Variable: items

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

Example:

print(items)
# > list
return items

Credentials: env_vars (optional)

You can specify environment variables to be used in the python code. The environment variables are accessible throw the env_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 to stdout

Example:

print('Hello World')
# or
import sys
sys.stdout.write('Hello World')

Notes

  • stderris used for passing data between nodes.

    • if exit code is 0, the node will be executed successfully and stderr represents the JSON representation of the output of the node
    • if exit code is not 0, the node fails and stderr represents the error message
  • The json attribute of each item is added and removed automatically. (you can access and return the items directly without the json attribute)

Contribute

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

License

Apache 2.0 with Commons Clause