Converting n8n Workflows to Python Scripts with Claude Code | Alpha | PandaiTech

Converting n8n Workflows to Python Scripts with Claude Code

How to migrate existing n8n automations into Python scripts that can be run locally by Claude Code, including documenting each workflow step.

Learning Timeline
Key Insights

Use Plan Mode for Complex Code

When asking Claude to build scripts involving multiple APIs (like Zoom, YouTube, and Notion simultaneously), always use 'Plan Mode'. This allows Claude to outline the file structure before writing code, preventing logic errors.

Modular Coding Tips

Ensure Claude builds separate Python files for each service. This simplifies maintenance; if the Zoom API changes, you only need to fix the Zoom file without affecting the code for Luma or Notion.

Pro-Tip: Reverse Workflow

Claude Code can also convert existing Python scripts into n8n import files. This is very useful if you want to move your local automation to a 24/7 n8n server.
Prompts

Workflow Documentation Prompt

Target: Claude Code
I've provided you with an n8n workflow file. Could you please read it carefully and then create a markdown file documenting exactly what this workflow does?

Python Script & Slash Command Generation Prompt

Target: Claude Code
I would like the ability for Claude code to actually run this workflow itself and execute it. Could you please create a Python script that basically does this exact workflow and then at the end create a slash command so that I can just trigger it easily here in Claude code?
Step by Step

How to Export an n8n Workflow to JSON Format

  1. Open the n8n dashboard and select the workflow you want to convert.
  2. Navigate to the top right corner of the workflow screen.
  3. Click the three-dot icon or the available menu button.
  4. Select the 'Download' option to save the workflow as a JSON file to your computer.
  5. Save the JSON file in the project folder where you will be running Claude Code.

Documenting Your Workflow Using Claude Code

  1. Open the terminal or command prompt in your project folder.
  2. Start a Claude Code session by typing the relevant command.
  3. Provide the downloaded n8n JSON file as context for Claude.
  4. Enter a prompt asking Claude to read the file and generate documentation in Markdown format.
  5. Wait for Claude to analyze every node and logic within the workflow.
  6. Review the generated .md file to understand the data validation structure and the extracted workflow steps.

Converting a Workflow into Modular Python Scripts

  1. Switch Claude Code to 'Plan Mode' to handle complex coding tasks.
  2. Ask Claude to build a Python script that replicates the exact functionality of the n8n workflow.
  3. Instruct Claude to split the code into several Python files based on integrations (e.g., separate files for Notion, Zoom, Luma, and YouTube).
  4. Ensure Claude creates a main script that connects all these modules.
  5. Follow Claude's instructions if it requests additional info like API keys or credentials during the code generation process.
  6. Ask Claude to provide a specific 'slash command' so the script can be executed directly via the Claude Code terminal.
  7. Perform step-by-step testing to ensure each API module works correctly before running the entire workflow.

More from AI-Powered Coding & App Development

View All