Skip to main content

Interactive CLI shell for MoleculerPy microservices framework

Project description

MoleculerPy REPL

Interactive CLI shell for MoleculerPy microservices framework.

Python 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.1.tar.gz (50.6 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.1-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: moleculerpy_repl-0.14.1.tar.gz
  • Upload date:
  • Size: 50.6 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.1.tar.gz
Algorithm Hash digest
SHA256 4e881693ecf51a2c1dc867f5a8b5f23a58b2e1e7668007197715de12caff59fb
MD5 9eb168436e1d24ba6539719136e1fee2
BLAKE2b-256 cef52038d5cf2af60f2a4011e5d6dfa6e432d2998c358e5bfaff1762d5f2190a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for moleculerpy_repl-0.14.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba3cb23513445cfbb1ae5f44942baf409e31f7a55126c914a8110454e0c486b2
MD5 533f73386f04c842deddb4205f947b7f
BLAKE2b-256 259544b2180e10d44a212294f542a460557227160be5d28adcaf37e3153f6362

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