Interactive CLI shell for MoleculerPy microservices framework
Project description
MoleculerPy REPL
Interactive CLI shell for MoleculerPy microservices framework.
Features
- ๐ฅ๏ธ 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
Quick Start
Installation
cd sources/moleculerpy-repl
pip install -e .
# Optional: rich for better output
pip install rich
Usage with Mock Broker
python3 examples/demo_repl.py
Usage with MoleculerPy
import 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())
Commands
| 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 |
Parameter Syntax
# 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
Example Session
$ 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! ๐
Custom Commands
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])
Architecture
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
Documentation
- Implementation Plan โ Status and roadmap
- Architecture โ Design decisions
- Command Reference โ Full command documentation
Development Status
| 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 |
License
MIT License โ see LICENSE for details.
Acknowledgments
Inspired by moleculer-repl for Moleculer.js.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
moleculerpy_repl-0.2.0.tar.gz
(50.9 kB
view details)
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 moleculerpy_repl-0.2.0.tar.gz.
File metadata
- Download URL: moleculerpy_repl-0.2.0.tar.gz
- Upload date:
- Size: 50.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12f5c96df9bb1a529545e5cedfc3ff6486f91ef8f4475685dcbb9d3f7541f17a
|
|
| MD5 |
e16ea986b6a191e32f90ed84d52a2b35
|
|
| BLAKE2b-256 |
49785fed914c182f30cd0d6c5ba03f18cde45222b40f6dd50d14d3356f9a551a
|
File details
Details for the file moleculerpy_repl-0.2.0-py3-none-any.whl.
File metadata
- Download URL: moleculerpy_repl-0.2.0-py3-none-any.whl
- Upload date:
- Size: 43.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f9e0b9767fbcaaa9a74a78dc584b0b4d5c94f34b3c4cfcb80f03a822c99cfd8
|
|
| MD5 |
78bed670d87492dc8823e1e254e95260
|
|
| BLAKE2b-256 |
d54ac1533dedfb5a996eaa3fbf57898a4bf3dd28ecefb254b726f3170db2b1d5
|