Package Information
Documentation
n8n-nodes-python-runtime
This is an n8n community node that enables direct execution of Python scripts using the system's Python runtime within n8n workflows. This node was created for personal use to allow direct access to locally installed Python libraries and environments.
⚠️ Security Warning: This node executes Python code directly on the system. Use with extreme caution and only in trusted environments. Not recommended for production use without proper security measures.
n8n is a fair-code licensed workflow automation platform.
Installation
Operations
Compatibility
Usage
Docker Setup
Resources
Installation
- Install n8n (if you haven't already):
npm install n8n -g
- Install this node:
npm install n8n-nodes-python-runtime
- Configure your n8n installation to use custom nodes by adding to your
n8n-config.json
:
{
"nodes.include": ["n8n-nodes-python-runtime"]
}
Operations
This node supports two main operations:
- Execute Script: Run Python code directly from the n8n workflow
- Run File: Execute a Python script file from the filesystem
Additional configuration options:
- Python Path: Specify the Python executable to use
- Command Arguments: Pass additional arguments to the Python script
Compatibility
- Requires n8n version 1.0.0 or later
- Requires Python to be installed on the system
- Tested with Python 3.x
Usage
Execute Script Example
- Add the Python Runtime node to your workflow
- Select "Execute Script" operation
- Enter your Python code in the "Python Code" field:
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3]})
print(df.to_json())
Run File Example
- Add the Python Runtime node to your workflow
- Select "Run File" operation
- Specify the path to your Python script
- Optionally add command line arguments
Docker Setup
To use this node in a Docker environment, you'll need to create a custom n8n image that includes Python and any required Python packages. Here's an example Dockerfile:
# Use the official n8n image as the base
FROM n8nio/n8n:latest
# Switch to root to install dependencies
USER root
# Install Python and pip using Alpine's package manager
RUN apk add --no-cache python3 py3-pip
# Create a virtual environment
RUN python3 -m venv /opt/venv
# Activate the virtual environment and install dependencies
COPY requirements.txt /tmp/requirements.txt
RUN . /opt/venv/bin/activate && pip install --no-cache-dir -r /tmp/requirements.txt
# Make the virtual environment the default for Python
ENV PATH="/opt/venv/bin:$PATH"
# Switch back to the default non-root user
USER node
Security Considerations
This node executes Python code directly on the system, which can be dangerous if misused. Consider these security implications:
- The node has access to the system's filesystem
- It can execute any Python code, including system commands
- It has access to any installed Python packages
- It runs with the same permissions as the n8n process
For these reasons, it's recommended to:
- Use only in trusted environments
- Run n8n in a container with appropriate restrictions
- Limit filesystem access when using Docker
- Be cautious with input validation if accepting external inputs