n8n-flow-manager 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 n8n-flow-manager contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,619 @@
1
+ Metadata-Version: 2.4
2
+ Name: n8n-flow-manager
3
+ Version: 0.1.0
4
+ Summary: A robust SDK and CLI for n8n workflow automation with DevOps capabilities
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: n8n,automation,workflow,devops,cli,async,api
8
+ Author: Mariano Gobea
9
+ Author-email: gobeamariano@gmail.com
10
+ Requires-Python: >=3.9,<4.0
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Framework :: AsyncIO
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Topic :: System :: Systems Administration
24
+ Requires-Dist: httpx (>=0.27.0,<0.28.0)
25
+ Requires-Dist: jinja2 (>=3.1.0,<4.0.0)
26
+ Requires-Dist: pydantic (>=2.5.0,<3.0.0)
27
+ Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
28
+ Requires-Dist: rich (>=13.7.0,<14.0.0)
29
+ Requires-Dist: typer[all] (>=0.12.0,<0.13.0)
30
+ Project-URL: Documentation, https://github.com/mgobea/n8n-flow-manager#readme
31
+ Project-URL: Homepage, https://github.com/mgobea/n8n-flow-manager
32
+ Project-URL: Repository, https://github.com/mgobea/n8n-flow-manager
33
+ Description-Content-Type: text/markdown
34
+
35
+ # n8n-flow-manager 🚀
36
+
37
+ **n8n-flow-manager** is a robust, production-ready Python SDK and CLI for the [n8n automation platform](https://n8n.io/). Unlike simple HTTP wrappers, this package is designed for **DevOps workflows**, providing type-safe models, async operations, workflow templating, and CI/CD integration capabilities.
38
+
39
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
40
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
41
+
42
+ ---
43
+
44
+ ## ✨ Features
45
+
46
+ ### Core Capabilities
47
+
48
+ - **⚡ Async-First Design**: Built on `httpx` for high-performance async operations
49
+ - **🛡️ Type Safety**: Complete Pydantic models for workflows, executions, and credentials
50
+ - **🔄 Smart Polling**: Execute workflows and wait for completion with intelligent status checking
51
+ - **📝 Jinja2 Templating**: Inject environment-specific variables into workflow definitions
52
+ - **🤖 Powerful CLI**: Terminal commands for backup, deploy, sync, and manage workflows
53
+ - **🔐 Secure**: API key authentication with proper error handling and retries
54
+ - **📦 Zero Config**: Works with environment variables or explicit configuration
55
+
56
+ ### What Makes It Different?
57
+
58
+ | Feature | n8n-flow-manager | Generic HTTP Clients |
59
+ |---------|------------------|---------------------|
60
+ | Type Validation | ✅ Pydantic models | ❌ Raw dicts |
61
+ | Async Support | ✅ Native asyncio | ⚠️ Sync only |
62
+ | Smart Execution | ✅ run_and_wait() | ❌ Manual polling |
63
+ | Templating | ✅ Jinja2 built-in | ❌ Not included |
64
+ | CLI Tools | ✅ Full featured | ❌ None |
65
+ | Error Handling | ✅ Custom exceptions | ⚠️ Generic errors |
66
+
67
+ ---
68
+
69
+ ## 📂 Project Structure
70
+
71
+ ```
72
+ n8n-flow-manager/
73
+ ├── src/
74
+ │ └── n8n_manager/
75
+ │ ├── __init__.py # Public API exports
76
+ │ ├── client.py # Main async client
77
+ │ ├── exceptions.py # Custom error types
78
+ │ ├── api/ # API modules by resource
79
+ │ │ ├── workflows.py # Workflow operations
80
+ │ │ ├── executions.py # Execution management
81
+ │ │ └── credentials.py # Credential handling
82
+ │ ├── models/ # Pydantic data models
83
+ │ │ ├── workflow.py # Workflow structures
84
+ │ │ ├── execution.py # Execution states
85
+ │ │ └── credential.py # Credential types
86
+ │ ├── cli/ # Command-line interface
87
+ │ │ └── main.py # Typer CLI app
88
+ │ └── utils/ # Helper utilities
89
+ │ └── templating.py # Jinja2 template engine
90
+ ├── tests/ # Pytest test suite
91
+ ├── examples/ # Usage examples
92
+ ├── pyproject.toml # Poetry configuration
93
+ └── README.md # This file
94
+ ```
95
+
96
+ ---
97
+
98
+ ## 🚀 Installation
99
+
100
+ ### Requirements
101
+
102
+ - Python 3.9 or higher
103
+ - Poetry (recommended) or pip
104
+
105
+ ### Install from Source
106
+
107
+ ```bash
108
+ # Clone the repository
109
+ git clone https://github.com/yourusername/n8n-flow-manager.git
110
+ cd n8n-flow-manager
111
+
112
+ # Install with Poetry (recommended)
113
+ poetry install --with dev
114
+ ```
115
+
116
+ ### Install CLI Globally (Use `n8n-py` anywhere)
117
+
118
+ ```bash
119
+ # Create wrapper script
120
+ mkdir -p ~/.local/bin
121
+ cat > ~/.local/bin/n8n-py << 'EOF'
122
+ #!/bin/bash
123
+ cd /path/to/n8n-flow-manager
124
+ poetry run n8n-py "$@"
125
+ EOF
126
+ chmod +x ~/.local/bin/n8n-py
127
+
128
+ # Add to PATH (if not already)
129
+ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
130
+ source ~/.zshrc
131
+
132
+ # Now use directly anywhere:
133
+ n8n-py health
134
+ n8n-py list-workflows
135
+ ```
136
+
137
+ ### Configuration
138
+
139
+ Create a `.env` file in your project root:
140
+
141
+ ```bash
142
+ N8N_API_KEY=your_api_key_here
143
+ N8N_BASE_URL=https://n8n.example.com
144
+ ```
145
+
146
+ Or export as environment variables:
147
+
148
+ ```bash
149
+ export N8N_API_KEY="your_api_key_here"
150
+ export N8N_BASE_URL="https://n8n.example.com"
151
+ ```
152
+
153
+ #### Getting Your API Key
154
+
155
+ 1. Open your n8n instance
156
+ 2. Go to **Settings** → **API**
157
+ 3. Generate a new API key
158
+ 4. Copy and save it securely
159
+
160
+ ---
161
+
162
+ ## 🛠️ Usage Guide
163
+
164
+ ### 1. Python SDK Usage
165
+
166
+ #### Basic Client Usage
167
+
168
+ ```python
169
+ import asyncio
170
+ from n8n_manager import N8NClient
171
+
172
+ async def main():
173
+ # Initialize client (reads from environment)
174
+ async with N8NClient() as client:
175
+
176
+ # List all active workflows
177
+ workflows = await client.workflows.list(active=True)
178
+ for wf in workflows:
179
+ print(f"Workflow: {wf.name} (ID: {wf.id})")
180
+
181
+ # Get specific workflow
182
+ workflow = await client.workflows.get("workflow_id")
183
+ print(f"Nodes: {len(workflow.nodes)}")
184
+
185
+ # Execute workflow and wait for result
186
+ execution = await client.executions.run_and_wait(
187
+ workflow_id="workflow_id",
188
+ timeout=60
189
+ )
190
+ print(f"Status: {execution.status}")
191
+ print(f"Success: {execution.is_successful}")
192
+
193
+ asyncio.run(main())
194
+ ```
195
+
196
+ #### Creating Workflows Programmatically
197
+
198
+ ```python
199
+ from n8n_manager import N8NClient
200
+ from n8n_manager.models.workflow import Workflow, Node
201
+
202
+ async def create_simple_workflow():
203
+ async with N8NClient() as client:
204
+ workflow = Workflow(
205
+ name="Python-Created Workflow",
206
+ active=False,
207
+ nodes=[
208
+ Node(
209
+ name="Start",
210
+ type="n8n-nodes-base.start",
211
+ position=[250, 300],
212
+ parameters={}
213
+ ),
214
+ Node(
215
+ name="Set Data",
216
+ type="n8n-nodes-base.set",
217
+ position=[450, 300],
218
+ parameters={
219
+ "values": {
220
+ "string": [
221
+ {"name": "message", "value": "Hello from Python!"}
222
+ ]
223
+ }
224
+ }
225
+ )
226
+ ],
227
+ connections={
228
+ "Start": {
229
+ "main": [[{"node": "Set Data", "type": "main", "index": 0}]]
230
+ }
231
+ }
232
+ )
233
+
234
+ created = await client.workflows.create(workflow)
235
+ print(f"Created workflow: {created.id}")
236
+ ```
237
+
238
+ #### Using Templates
239
+
240
+ ```python
241
+ from n8n_manager.utils.templating import load_workflow_from_file
242
+
243
+ # Load workflow with template variables
244
+ workflow = load_workflow_from_file(
245
+ "templates/data_sync.json",
246
+ variables={
247
+ "environment": "production",
248
+ "api_endpoint": "https://api.example.com",
249
+ "timeout": 30
250
+ }
251
+ )
252
+
253
+ async with N8NClient() as client:
254
+ deployed = await client.workflows.create(workflow)
255
+ print(f"Deployed: {deployed.name}")
256
+ ```
257
+
258
+ ### 2. CLI Usage
259
+
260
+ The CLI provides powerful commands for workflow management.
261
+
262
+ **Example Output:**
263
+
264
+ ```bash
265
+ $ n8n-py health
266
+ ✓ Connection healthy!
267
+ API URL: https://n8n.example.com/
268
+
269
+ $ n8n-py list-workflows
270
+ Workflows (33 found)
271
+ ┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━┓
272
+ ┃ ID ┃ Name ┃ Active ┃ Nodes ┃
273
+ ┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━┩
274
+ │ 1RDHBsmLkkTptybX │ Production Data Sync │ ✓ │ 6 │
275
+ │ 2V3iCBkiOAPVzrUr │ Customer Onboarding │ ✗ │ 7 │
276
+ │ 8qGqx5TW1QA7T8P9 │ Error Notifications │ ✓ │ 2 │
277
+ └──────────────────┴────────────────────────────────┴────────┴───────┘
278
+ ```
279
+
280
+ #### Commands
281
+
282
+ ```bash
283
+ # List all workflows
284
+ n8n-py list-workflows
285
+
286
+ # List only active workflows
287
+ n8n-py list-workflows --active
288
+ ```
289
+
290
+ #### Get Workflow Details
291
+
292
+ ```bash
293
+ # Display workflow info
294
+ n8n-py get-workflow <workflow_id>
295
+
296
+ # Save workflow to file
297
+ n8n-py get-workflow <workflow_id> --output workflow.json
298
+ ```
299
+
300
+ #### Deploy Workflows
301
+
302
+ ```bash
303
+ # Deploy from JSON file
304
+ n8n-py deploy workflow.json
305
+
306
+ # Deploy with template variables
307
+ n8n-py deploy template.json --var environment=prod --var timeout=30
308
+
309
+ # Deploy and activate immediately
310
+ n8n-py deploy workflow.json --activate
311
+ ```
312
+
313
+ #### Backup Workflows
314
+
315
+ ```bash
316
+ # Backup all workflows
317
+ n8n-py backup --output ./backups
318
+
319
+ # Backup only active workflows
320
+ n8n-py backup --output ./backups --active-only
321
+ ```
322
+
323
+ #### Execute Workflows
324
+
325
+ ```bash
326
+ # Execute and wait for completion
327
+ n8n-py execute <workflow_id>
328
+
329
+ # Execute without waiting
330
+ n8n-py execute <workflow_id> --no-wait
331
+
332
+ # Execute with input data
333
+ n8n-py execute <workflow_id> --input data.json
334
+ ```
335
+
336
+ #### Activate/Deactivate
337
+
338
+ ```bash
339
+ # Activate workflow
340
+ n8n-py activate <workflow_id>
341
+
342
+ # Deactivate workflow
343
+ n8n-py deactivate <workflow_id>
344
+ ```
345
+
346
+ #### Health Check
347
+
348
+ ```bash
349
+ # Verify connection to n8n
350
+ n8n-py health
351
+ ```
352
+
353
+ ---
354
+
355
+ ## 📚 Advanced Examples
356
+
357
+ ### CI/CD Integration
358
+
359
+ Use in GitHub Actions for automated deployments:
360
+
361
+ ```yaml
362
+ # .github/workflows/deploy-n8n.yml
363
+ name: Deploy n8n Workflows
364
+
365
+ on:
366
+ push:
367
+ branches: [main]
368
+
369
+ jobs:
370
+ deploy:
371
+ runs-on: ubuntu-latest
372
+ steps:
373
+ - uses: actions/checkout@v3
374
+
375
+ - name: Set up Python
376
+ uses: actions/setup-python@v4
377
+ with:
378
+ python-version: '3.11'
379
+
380
+ - name: Install n8n-flow-manager
381
+ run: pip install -e .
382
+
383
+ - name: Deploy workflows
384
+ env:
385
+ N8N_API_KEY: ${{ secrets.N8N_API_KEY }}
386
+ N8N_BASE_URL: ${{ secrets.N8N_BASE_URL }}
387
+ run: |
388
+ n8n-py deploy workflows/production.json --activate
389
+ ```
390
+
391
+ ### Environment-Specific Deployments
392
+
393
+ ```python
394
+ import asyncio
395
+ from n8n_manager import N8NClient
396
+ from n8n_manager.utils.templating import load_workflow_from_file
397
+
398
+ ENVIRONMENTS = {
399
+ "dev": {
400
+ "api_endpoint": "https://dev.api.example.com",
401
+ "webhook_path": "webhook-dev",
402
+ "timeout": 10
403
+ },
404
+ "prod": {
405
+ "api_endpoint": "https://api.example.com",
406
+ "webhook_path": "webhook",
407
+ "timeout": 30
408
+ }
409
+ }
410
+
411
+ async def deploy_to_environment(env: str):
412
+ workflow = load_workflow_from_file(
413
+ "templates/api_workflow.json",
414
+ variables=ENVIRONMENTS[env]
415
+ )
416
+
417
+ async with N8NClient() as client:
418
+ deployed = await client.workflows.create(workflow)
419
+ await client.workflows.activate(deployed.id)
420
+ print(f"Deployed to {env}: {deployed.id}")
421
+
422
+ # Deploy to production
423
+ asyncio.run(deploy_to_environment("prod"))
424
+ ```
425
+
426
+ ### Monitoring and Logging
427
+
428
+ ```python
429
+ async def monitor_executions(workflow_id: str):
430
+ async with N8NClient() as client:
431
+ executions = await client.executions.list(
432
+ workflow_id=workflow_id,
433
+ limit=50
434
+ )
435
+
436
+ for execution in executions:
437
+ if execution.is_failed:
438
+ print(f"❌ Failed: {execution.id} at {execution.started_at}")
439
+ elif execution.is_successful:
440
+ print(f"✅ Success: {execution.id}")
441
+ ```
442
+
443
+ ---
444
+
445
+ ## 🧪 Testing
446
+
447
+ Run the test suite with pytest:
448
+
449
+ ```bash
450
+ # Install dev dependencies
451
+ poetry install --with dev
452
+
453
+ # Run all tests
454
+ poetry run pytest
455
+
456
+ # Run with coverage
457
+ poetry run pytest --cov=src/n8n_manager --cov-report=html
458
+
459
+ # Run specific test file
460
+ poetry run pytest tests/test_client.py
461
+ ```
462
+
463
+ ---
464
+
465
+ ## 🔧 Development
466
+
467
+ ### Setting Up Development Environment
468
+
469
+ ```bash
470
+ # Clone repository
471
+ git clone https://github.com/yourusername/n8n-flow-manager.git
472
+ cd n8n-flow-manager
473
+
474
+ # Install with dev dependencies
475
+ poetry install --with dev
476
+
477
+ # Install pre-commit hooks
478
+ poetry run pre-commit install
479
+
480
+ # Run linting
481
+ poetry run black src/ tests/
482
+ poetry run ruff src/ tests/
483
+
484
+ # Type checking
485
+ poetry run mypy src/
486
+ ```
487
+
488
+ ### Project Roadmap
489
+
490
+ - [x] Core client with async support
491
+ - [x] Pydantic models for type safety
492
+ - [x] Workflow, execution, and credential APIs
493
+ - [x] CLI with Typer
494
+ - [x] Jinja2 templating
495
+ - [x] Smart execution polling
496
+ - [ ] Webhook management API
497
+ - [ ] Tag management
498
+ - [ ] Bulk operations
499
+ - [ ] Workflow validation before deploy
500
+ - [ ] Integration tests with mock n8n server
501
+
502
+ ---
503
+
504
+ ## 📖 API Reference
505
+
506
+ ### N8NClient
507
+
508
+ Main client for interacting with n8n API.
509
+
510
+ **Methods:**
511
+ - `workflows` - WorkflowAPI instance
512
+ - `executions` - ExecutionAPI instance
513
+ - `credentials` - CredentialAPI instance
514
+ - `health_check()` - Verify API connection
515
+
516
+ ### WorkflowAPI
517
+
518
+ **Methods:**
519
+ - `list(active=None, tags=None)` - List workflows
520
+ - `get(workflow_id)` - Get workflow by ID
521
+ - `create(workflow)` - Create new workflow
522
+ - `update(workflow_id, workflow)` - Update workflow
523
+ - `delete(workflow_id)` - Delete workflow
524
+ - `activate(workflow_id)` - Activate workflow
525
+ - `deactivate(workflow_id)` - Deactivate workflow
526
+
527
+ ### ExecutionAPI
528
+
529
+ **Methods:**
530
+ - `list(workflow_id=None, limit=100, status=None)` - List executions
531
+ - `get(execution_id)` - Get execution details
532
+ - `trigger_workflow(workflow_id, input_data=None)` - Trigger execution
533
+ - `wait_for_execution(execution_id, timeout=300)` - Wait for completion
534
+ - `run_and_wait(workflow_id, input_data=None, timeout=300)` - Trigger and wait
535
+ - `retry(execution_id)` - Retry failed execution
536
+ - `delete(execution_id)` - Delete execution
537
+
538
+ ### CredentialAPI
539
+
540
+ **Methods:**
541
+ - `list(credential_type=None)` - List credentials
542
+ - `get(credential_id)` - Get credential by ID
543
+ - `create(credential)` - Create credential
544
+ - `update(credential_id, credential)` - Update credential
545
+ - `delete(credential_id)` - Delete credential
546
+
547
+ ---
548
+
549
+ ## 🤝 Contributing
550
+
551
+ Contributions are welcome! Please follow these steps:
552
+
553
+ 1. Fork the repository
554
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
555
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
556
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
557
+ 5. Open a Pull Request
558
+
559
+ ### Contribution Guidelines
560
+
561
+ - Write tests for new features
562
+ - Follow existing code style (Black + Ruff)
563
+ - Update documentation as needed
564
+ - Add type hints to all functions
565
+ - Keep commits atomic and well-described
566
+
567
+ ---
568
+
569
+ ## 📄 License
570
+
571
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
572
+
573
+ ---
574
+
575
+ ## 🙏 Acknowledgments
576
+
577
+ - [n8n](https://n8n.io/) - The workflow automation platform
578
+ - [httpx](https://www.python-httpx.org/) - Async HTTP client
579
+ - [Pydantic](https://pydantic-docs.helpmanual.io/) - Data validation
580
+ - [Typer](https://typer.tiangolo.com/) - CLI framework
581
+ - [Rich](https://rich.readthedocs.io/) - Terminal formatting
582
+
583
+ ---
584
+
585
+ ## 📞 Support
586
+
587
+ - **Documentation**: [GitHub Wiki](https://github.com/yourusername/n8n-flow-manager/wiki)
588
+ - **Issues**: [GitHub Issues](https://github.com/yourusername/n8n-flow-manager/issues)
589
+ - **Discussions**: [GitHub Discussions](https://github.com/yourusername/n8n-flow-manager/discussions)
590
+ - **n8n Community**: [n8n Community Forum](https://community.n8n.io/)
591
+
592
+ ---
593
+
594
+ ## 🎯 Use Cases
595
+
596
+ ### DevOps & CI/CD
597
+ - Automate workflow deployments across environments
598
+ - Version control your n8n workflows in Git
599
+ - Integrate with GitLab/GitHub Actions pipelines
600
+
601
+ ### Disaster Recovery
602
+ - Scheduled backups of all workflows
603
+ - Quick restore capabilities
604
+ - Environment replication
605
+
606
+ ### Multi-Tenant Management
607
+ - Programmatically create workflows for new clients
608
+ - Template-based workflow generation
609
+ - Bulk operations across workflows
610
+
611
+ ### Monitoring & Observability
612
+ - Track execution success rates
613
+ - Monitor workflow health
614
+ - Automated alerting on failures
615
+
616
+ ---
617
+
618
+ **Made with ❤️ for the n8n community**
619
+