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.14.3.tar.gz (51.0 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.14.3-py3-none-any.whl (43.5 kB view details)

Uploaded Python 3

File details

Details for the file moleculerpy_repl-0.14.3.tar.gz.

File metadata

  • Download URL: moleculerpy_repl-0.14.3.tar.gz
  • Upload date:
  • Size: 51.0 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.14.3.tar.gz
Algorithm Hash digest
SHA256 44ee235b390ffe05f6171bdccbfb6011575cbe8c376aaa94dc900bd18486d8fd
MD5 ab4c9ad41ab2ccfd5afd9696f01c0c31
BLAKE2b-256 c777c8816b531c59f003f3261ccb451294e9f10a1be67b5325274265e98dec25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for moleculerpy_repl-0.14.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a84c48d9afaa48f0897ae4fa50023a302533ebda89c15383abe37f42ef9566a9
MD5 7b4a33abe84ba30f8d9b0dc1501a929d
BLAKE2b-256 4815d92ab1a6103cc8fa52ac6f4e8eaba0f9ffccfcf8ff55d526646202019a8f

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