Python + n8n: Combining No-Code with Custom Scripts

Python + n8n: Combining No-Code with Custom Scripts

n8n's visual workflow builder is powerful, but some tasks need custom code. Here is how to combine the best of both worlds—no-code simplicity with Python's unlimited flexibility.

Why Combine Python and n8n?

n8n Strengths

  • Visual workflow design
  • Easy app integrations
  • Trigger and scheduling built-in
  • Non-developers can understand flows

Python Strengths

  • Complex data transformation
  • Advanced algorithms
  • Machine learning integration
  • Unlimited customization

Together

n8n handles orchestration and integrations; Python handles heavy processing.

Methods for Integration

Method 1: Code Node

n8n has a built-in Code node that runs JavaScript. For Python, you can:

  • Use a Python-to-JS transpiler
  • Call Python via shell commands
  • Use Pyodide (Python in browser)

Method 2: HTTP Request to Python API

Best approach for complex Python logic:

  1. Build a simple Python API (Flask/FastAPI)
  2. Host it (server, serverless, Docker)
  3. n8n calls the API via HTTP Request node
  4. Python processes and returns results

Method 3: Execute Command Node

If n8n and Python are on the same server:

  1. Use Execute Command node
  2. Call Python script directly
  3. Pass data via arguments or files
  4. Read output back into n8n

Example: Data Processing Pipeline

The Workflow

  1. n8n: Trigger on new file upload
  2. n8n: Download file from cloud storage
  3. Python API: Process file (complex transformations)
  4. n8n: Take processed data
  5. n8n: Update CRM, send notifications

Python API Example (FastAPI)


from fastapi import FastAPI
import pandas as pd

app = FastAPI()

@app.post("/process-data")
async def process_data(data: dict):
    # Convert to DataFrame
    df = pd.DataFrame(data['records'])

    # Complex processing
    df['total'] = df['quantity'] * df['price']
    summary = df.groupby('category')['total'].sum()

    return {"summary": summary.to_dict()}

n8n HTTP Request

  • Method: POST
  • URL: http://your-api/process-data
  • Body: JSON with your data

Use Cases for This Combo

  • ML predictions: n8n triggers, Python model predicts
  • Document processing: n8n orchestrates, Python parses
  • Data enrichment: n8n collects, Python transforms
  • Report generation: n8n schedules, Python generates

Deployment Options

Same Server

  • Simplest setup
  • Use Execute Command or local API
  • Good for low volume

Separate Services

  • Python API on separate server or serverless
  • Better scaling and maintenance
  • n8n connects via HTTP

Docker Compose

  • n8n and Python API in containers
  • Easy deployment and scaling
  • Network communication between containers

Need Hybrid Automation?

We build systems combining n8n and custom Python.

Get Hybrid Automation

0 comments

Leave a comment

Please note, comments need to be approved before they are published.