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.2.tar.gz (50.7 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.2-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: moleculerpy_repl-0.14.2.tar.gz
  • Upload date:
  • Size: 50.7 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.2.tar.gz
Algorithm Hash digest
SHA256 25767d916049b8e8c4e089812c2384359269e1755030abce83e5e69dfe80a973
MD5 d0453b90ce74d37150b27c7fbd5d4572
BLAKE2b-256 34b87f0fe66ca3c407a0defd2eefe54a071a72c2c8571b1c830c7105c4bee274

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for moleculerpy_repl-0.14.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8345c493182c7ea1c30377240a4d5a6a02bbd9826037cdb7b88ba06915ee6bfc
MD5 0a0d35d78acf64e576cdb93cf10d4ccf
BLAKE2b-256 fb622d45e5173cb0c3dd1e85a3dd743f8818568cd1adf31aa3c2e1fadf3e90c8

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