Interactive CLI shell for MoleculerPy microservices framework.
- π₯οΈ Interactive Shell β Command-line interface for MoleculerPy brokers
- π Call Actions β Invoke service actions with params
- π¨ Emit Events β Publish events to the cluster
- π Inspect Cluster β List actions, services, nodes, events
- β‘ Tab Completion β Autocomplete for actions, events, nodes
- π¨ Rich Output β Beautiful tables and colors (optional)
- π§ Extensible β Add custom commands easily
cd sources/moleculerpy-repl
pip install -e .
# Optional: rich for better output
pip install richpython3 examples/demo_repl.pyimport asyncio
from moleculerpy import Broker
from moleculerpy_repl import REPL
async def main():
broker = Broker("node-1", transporter="nats://localhost:4222")
await broker.start()
# Start REPL
repl = REPL(broker)
await repl.run()
asyncio.run(main())| Command | Alias | Description | Example |
|---|---|---|---|
actions |
a |
List available actions | actions |
services |
s |
List registered services | services |
nodes |
n |
List cluster nodes | nodes -d |
events |
ev |
List event subscriptions | events |
info |
i |
System information | info |
call |
c |
Call a service action | call math.add a=5 b=3 |
emit |
e |
Emit an event | emit user.created name=Bob |
broadcast |
b |
Broadcast event to all | broadcast system.shutdown |
help |
β | Show help | help call |
clear |
cls |
Clear screen | clear |
quit |
exit |
Exit REPL | quit |
# Basic parameters β payload
mol $ call math.add a=5 b=3
# Meta parameters (prefix #) β context metadata
mol $ emit user.created name=Bob #userId=123 #source=api
# Options (prefix $) β call options
mol $ call slow.action $timeout=30000 $retries=3
# JSON parameters
mol $ call user.create --json '{"name": "Bob", "age": 30}'
# Load from file
mol $ call user.create --load params.json
# Force string with @ prefix
mol $ call search query=@123 # "123" as string, not int$ python3 examples/demo_repl.py
π MoleculerPy REPL v0.1.0
Node ID: demo-node
Type 'help' for available commands.
demo $ services
Services:
Service Version State Nodes
------------------------------------------------------------
greeter 1 OK 1
math 1 OK 1
user 1 OK 1
demo $ actions
Actions:
Action Nodes State
------------------------------------------------------------
greeter.hello 1 OK
math.add 1 OK
math.multiply 1 OK
user.get 1 OK
user.list 1 OK
demo $ call math.add a=10 b=25
>> Response (0.00ms):
Result: 35
demo $ call user.list
>> Response (0.00ms):
[
{"id": "u1", "name": "John"},
{"id": "u2", "name": "Jane"}
]
demo $ emit user.created name=Charlie #userId=u4
[EVENT] user.created: {'name': 'Charlie'}
Event emitted: user.created
demo $ info
Broker Information:
----------------------------------------
Node ID: demo-node
Namespace: (none)
Version: 0.1.0
Protocol: 4
Transport:
----------------------------------------
Transporter: None
Serializer: JSON
Statistics:
----------------------------------------
Services: 3
Actions: 5
Events: 1
demo $ quit
Goodbye! π
from moleculerpy_repl import REPL, BaseCommand, CommandResult
class HelloCommand(BaseCommand):
name = "hello"
description = "Say hello"
usage = "hello [name]"
aliases = ["hi"]
async def execute(self, broker, args):
name = args.positional[0] if args.positional else "World"
return CommandResult(
success=True,
output=f"Hello, {name}!"
)
repl = REPL(broker, custom_commands=[HelloCommand])moleculerpy-repl/
βββ src/moleculerpy_repl/
β βββ __init__.py # Public API: REPL, BaseCommand, etc.
β βββ repl.py # Main REPL class (extends cmd.Cmd)
β βββ parser.py # Argument parser with prefix system
β βββ output.py # Formatter (uses rich if available)
β βββ commands/
β βββ base.py # BaseCommand, CommandResult, Registry
β βββ actions.py # `actions` command
β βββ services.py # `services` command
β βββ nodes.py # `nodes` command
β βββ events.py # `events` command
β βββ info.py # `info` command
β βββ call.py # `call` command
β βββ emit.py # `emit`, `broadcast` commands
βββ examples/
β βββ demo_repl.py # Demo with mock broker
βββ docs/
βββ PLAN.md # Implementation status
βββ ARCHITECTURE.md
βββ COMMANDS.md
- Implementation Plan β Status and roadmap
- Architecture β Design decisions
- Command Reference β Full command documentation
| Phase | Description | Status |
|---|---|---|
| Phase 1 | Core REPL module | β Complete |
| Phase 2 | Discovery commands | β Complete |
| Phase 3 | Action commands | β Complete |
| Phase 4 | Advanced commands | β³ Pending |
| Phase 5 | MoleculerPy integration | β³ Pending |
| Phase 6 | DX polish | β Partial |
MIT License β see LICENSE for details.
Inspired by moleculer-repl for Moleculer.js.