Buckets:

download
raw
3.87 kB
#!/usr/bin/env python3
"""
NEXUS QUICK DEMO: Zero FastAPI Coding Required
==============================================
Quick demo showing Nexus workflow-to-API automation works perfectly.
Usage:
cd packages/kailash-nexus
python examples/quick_demo.py
Then test:
curl -X POST http://localhost:8080/workflows/greeter/execute -H "Content-Type: application/json" -d '{"name": "Alice"}'
"""
import os
import sys
# Add src to Python path so we can import nexus
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from kailash.workflow.builder import WorkflowBuilder
from nexus import Nexus
def create_simple_workflow():
"""Create a simple greeting workflow."""
workflow = WorkflowBuilder()
greeting_code = """
name = parameters.get('name', 'World')
message = parameters.get('message', 'Hello')
result = {'greeting': f'{message}, {name}!', 'name': name, 'timestamp': '2025-01-15T10:00:00Z'}
"""
workflow.add_node("PythonCodeNode", "greet", {"code": greeting_code.strip()})
return workflow
def main():
"""Quick demo of Nexus capabilities."""
print("๐Ÿš€ Nexus Quick Demo - Zero FastAPI Coding Required")
print("=" * 55)
# STEP 1: Zero-config initialization
app = Nexus(api_port=8080, mcp_port=3002) # Use different ports
print("โœ… Nexus initialized (ports: API=8080, MCP=3002)")
# STEP 2: Register workflow - Single call โ†’ API + CLI + MCP
workflow = create_simple_workflow()
app.register("greeter", workflow)
print("โœ… Workflow registered โ†’ Available on API + CLI + MCP")
# STEP 3: Start platform
try:
print("\n๐ŸŒ Starting platform...")
app.start()
# Check health
health = app.health_check()
print(f"๐Ÿ“Š Status: {health.get('status', 'unknown')}")
print("\n" + "=" * 55)
print("๐ŸŽ‰ SUCCESS! Platform running with ZERO FastAPI coding!")
print("=" * 55)
print("\n๐Ÿ“ก Available Endpoints:")
print(" ๐ŸŒ API: http://localhost:8080")
print(" POST /workflows/greeter/execute")
print(" GET /workflows")
print(" GET /health")
print(" ๐Ÿค– MCP: ws://localhost:3002 (for AI agents)")
print("\n๐Ÿงช Test Command:")
print(" curl -X POST http://localhost:8080/workflows/greeter/execute \\")
print(" -H 'Content-Type: application/json' \\")
print(' -d \'{"name": "Alice", "message": "Welcome"}\'')
print("\n๐Ÿ’ก PROOF: This required:")
print(" โŒ 0 lines of FastAPI code")
print(" โŒ 0 route definitions")
print(" โŒ 0 middleware setup")
print(" โœ… Just workflow + app.register()!")
print("\nโน๏ธ Press Ctrl+C to stop...")
# Run for 30 seconds to allow testing
import time
start_time = time.time()
while time.time() - start_time < 30:
time.sleep(1)
print("\nโฐ Demo timeout reached - stopping platform...")
app.stop()
print("โœ… Platform stopped gracefully")
return True
except KeyboardInterrupt:
print("\n\n๐Ÿ›‘ Demo stopped by user")
app.stop()
print("โœ… Platform stopped gracefully")
return True
except Exception as e:
print(f"โŒ Error: {e}")
print("๐Ÿ” Possible causes:")
print(" โ€ข Ports 8080/3002 in use")
print(" โ€ข Missing dependencies")
return False
if __name__ == "__main__":
success = main()
if success:
print("\n๐Ÿ† Demo completed successfully!")
print("โœ… Nexus provides complete workflow-to-API automation")
print("โœ… Zero FastAPI coding required")
print("โœ… Multi-channel platform (API + CLI + MCP)")
else:
print("\nโŒ Demo failed - check error messages above")
exit(1)

Xet Storage Details

Size:
3.87 kB
ยท
Xet hash:
da61ce9a087f0a6b3c86dba85fd113cfd7715f361b062940d18afe565116afc3

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.