A Python SDK for the n8n automation platform.
Project description
n8n-sdk-python
[ English | 繁體中文 ]
This is an unofficial Python SDK for the n8n workflow automation platform. This SDK provides convenient wrappers for interacting with the n8n API, allowing you to manage workflows, executions, credentials, and other n8n resources from your Python applications.
Table of Contents
System Requirements
Before installing n8n-sdk-python, please ensure your system meets the following requirements:
- Python 3.8 or higher
- A running n8n instance (local or remote)
- n8n API key (for authentication)
Installation
Using a Virtual Environment
Using a virtual environment can prevent dependency conflicts:
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate
Method 1: Using pip (Recommended)
The easiest way to install is using the pip package manager:
pip install n8n-sdk-python
Method 2: Installing from Source
If you need the latest development version or want to modify the code, you can install from source:
# Clone the repository
git clone https://github.com/eric050828/n8n-sdk-python.git
cd n8n-sdk-python
# Install in development mode
pip install -e .
Initial Setup
After installation, you need to perform some initial setup to use the SDK.
Get n8n API Key
- Log in to your n8n instance.
- Click on the user icon in the upper right corner and select "Settings".
- Click on the "API" tab.
- Click the "Create" button to generate a new API key.
- Copy the generated API key (please save it, as it will only be displayed once).
Set Environment Variables
You can configure the SDK through environment variables, so you don't need to hardcode sensitive information in your code:
On Linux/macOS
export N8N_BASE_URL="http://localhost:5678"
export N8N_API_KEY="your-api-key-here"
On Windows
set N8N_BASE_URL=http://localhost:5678
set N8N_API_KEY=your-api-key-here
Using a .env File
For project development, it is recommended to use a .env file to manage environment variables:
- Create a file named
.envin your project root directory. - Add the following content:
N8N_BASE_URL=http://localhost:5678
N8N_API_KEY=your-api-key-here
- Load these settings in your program:
from dotenv import load_dotenv
import os
# Load environment variables from .env file
load_dotenv()
# Now you can use os.getenv to get environment variables
base_url = os.getenv("N8N_BASE_URL")
api_key = os.getenv("N8N_API_KEY")
Please note that you need to install the python-dotenv library to use this feature: pip install python-dotenv
Quick Start
After installation, you can run the following code to verify that the SDK is working correctly:
import asyncio
from n8n_sdk_python import N8nClient
from n8n_sdk_python.models.workflows import WorkflowList
async def test_connection():
# Initialize the client
client = N8nClient(
base_url="http://localhost:5678", # Replace with your n8n instance URL
api_key="your-api-key-here" # Replace with your API key
)
try:
# Try to get the workflow list
workflows: WorkflowList = await client.list_workflows(limit=1)
print("✅ Connection successful! Number of workflows found:", len(workflows.data))
return True
except Exception as e:
print("❌ Connection failed:", str(e))
return False
if __name__ == "__main__":
result = asyncio.run(test_connection())
print("Test result:", "Success" if result else "Failure")
Troubleshooting
If you encounter problems, here are some common issues and their solutions:
Installation Issues
Problem: "ERROR: Could not find a version that satisfies the requirement n8n-sdk-python" during installation.
Solution: Check if your Python version meets the requirements (3.8+) and ensure pip is updated to the latest version:
python --version
pip install --upgrade pip
Connection Issues
Problem: "Connection refused" error when connecting to the n8n instance.
Solution:
- Confirm that the n8n instance is running.
- Check if the URL is correct, including the protocol (http/https) and port.
- Ensure no firewall is blocking the connection.
Problem: Received a 401 Unauthorized error.
Solution:
- Confirm the API key is correct.
- Check if the API key has expired or been revoked.
- Verify that the user has sufficient permissions.
Import Issues
Problem: "ModuleNotFoundError: No module named 'n8n_sdk_python'"
Solution:
- Confirm the library is correctly installed:
pip list | grep n8n-sdk-python - If using a virtual environment, confirm it is activated:
which python - Try reinstalling:
pip install --force-reinstall --no-cache-dir n8n-sdk-python
Other Issues
If you encounter other issues, you can:
- Check the log output for detailed error messages.
- Enable debug mode for more logs:
import logging
logging.basicConfig(level=logging.DEBUG)
- Submit an issue on the GitHub repository with error details and steps to reproduce.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file n8n_sdk_python-0.1.2.tar.gz.
File metadata
- Download URL: n8n_sdk_python-0.1.2.tar.gz
- Upload date:
- Size: 47.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca176a52f0bc64818d19849b208b4ed86f30de8684402beaa8bedb1840b855a7
|
|
| MD5 |
6c252e5bc61d10b517fb7d0c8ffa5109
|
|
| BLAKE2b-256 |
e5f6192d208f6d13b51956dc5a99d873317956a6cfa09f0c738a1f2fc68ce406
|
Provenance
The following attestation bundles were made for n8n_sdk_python-0.1.2.tar.gz:
Publisher:
publish-to-pypi.yml on eric050828/n8n-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
n8n_sdk_python-0.1.2.tar.gz -
Subject digest:
ca176a52f0bc64818d19849b208b4ed86f30de8684402beaa8bedb1840b855a7 - Sigstore transparency entry: 214720227
- Sigstore integration time:
-
Permalink:
eric050828/n8n-sdk-python@273d3b893c86efc1437a34ae761a420d103b2fc2 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/eric050828
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@273d3b893c86efc1437a34ae761a420d103b2fc2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file n8n_sdk_python-0.1.2-py3-none-any.whl.
File metadata
- Download URL: n8n_sdk_python-0.1.2-py3-none-any.whl
- Upload date:
- Size: 42.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a29e51d68d64a2753d486e6b900a514ffdfc43dd0b8b5cb23fc5abb2cf350900
|
|
| MD5 |
b38c05830072c0a05acf470bb21cbd73
|
|
| BLAKE2b-256 |
accd1b2e0a48a7df6d3e31a95f79778c59cdc18af02997b8fb742733eabda4c9
|
Provenance
The following attestation bundles were made for n8n_sdk_python-0.1.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on eric050828/n8n-sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
n8n_sdk_python-0.1.2-py3-none-any.whl -
Subject digest:
a29e51d68d64a2753d486e6b900a514ffdfc43dd0b8b5cb23fc5abb2cf350900 - Sigstore transparency entry: 214720228
- Sigstore integration time:
-
Permalink:
eric050828/n8n-sdk-python@273d3b893c86efc1437a34ae761a420d103b2fc2 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/eric050828
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@273d3b893c86efc1437a34ae761a420d103b2fc2 -
Trigger Event:
release
-
Statement type: