Skip to main content

Interactive CLI shell for MoleculerPy microservices framework

Project description

MoleculerPy REPL

Interactive CLI shell for MoleculerPy microservices framework.

CI PyPI version Python versions License


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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moleculerpy_repl-0.2.0-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

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

Hashes for moleculerpy_repl-0.2.0.tar.gz
Algorithm Hash digest
SHA256 12f5c96df9bb1a529545e5cedfc3ff6486f91ef8f4475685dcbb9d3f7541f17a
MD5 e16ea986b6a191e32f90ed84d52a2b35
BLAKE2b-256 49785fed914c182f30cd0d6c5ba03f18cde45222b40f6dd50d14d3356f9a551a

See more details on using hashes here.

File details

Details for the file moleculerpy_repl-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for moleculerpy_repl-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f9e0b9767fbcaaa9a74a78dc584b0b4d5c94f34b3c4cfcb80f03a822c99cfd8
MD5 78bed670d87492dc8823e1e254e95260
BLAKE2b-256 d54ac1533dedfb5a996eaa3fbf57898a4bf3dd28ecefb254b726f3170db2b1d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page