replbuilder


Namereplbuilder JSON
Version 1.2.0 PyPI version JSON
download
home_page
SummaryQuickly build a custom command REPL environment with this tool
upload_time2023-08-14 00:42:29
maintainer
docs_urlNone
author
requires_python
licenseMIT
keywords repl repl builder
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## ReplBuilder

![PyPI version](http://img.shields.io/pypi/v/replbuilder.svg)

`pip install replbuilder`

Quickly build a repl cli prompt for custom commands in python.

`argparse` is used for quick and easy parsing interface, you should be able to utilize the full power of `argparse` as your command parser.

A globally scoped context object can be optionally passed into each command, making context sharing and state possible. It also supports custom exception handlers, and aliases, and more.

This is a standalone package, it does not depend on any other packages.

For example, see project [hnterminal](https://github.com/Aperocky/hnterminal), browse, vote and comment on HN in your terminal.

## Example

see [example calculator repl](example_calculator_repl.py) for example implementation. The gist can be concluded in a few lines:

```
add_cmd = ReplCommand("add", Calculator.basic_parser(), calculator.add, "Add 2 numbers")
sub_cmd = ReplCommand("sub", Calculator.basic_parser(), calculator.sub, "Subtract second number from first")
fact_cmd = ReplCommand("factorial", Calculator.factorial_parser(), calculator.factorial, "factorial with exception handler", exception_handler=exception_handler)
say_cmd = ReplCommand("cowsay", Cow.get_cowsay_parser(), cow.cowsay, "say stuff, demo optional and context usage", use_context=True)
mood_cmd = ReplCommand("cowmood", argparse.ArgumentParser(), cow.cowmood, "Mood of the cow changes with global context object", use_context=True)
calc_commands = [add_cmd, sub_cmd, fact_cmd]
cow_commands = [say_cmd, mood_cmd]

context = ContextObj()
runner = ReplRunner("calculator", context) # context is optional, but it helps maintaining state and avoiding duplicate work.
runner.add_commands(calc_commands, namespace="Calculator") # namespace is optional
runner.add_commands(cow_commands, namespace="Cow")
runner.run()
```

run it `python example_calculator_repl.py`

Part of the repl is colorized for better visibility:

![example repl run](demo.jpg)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "replbuilder",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "repl,repl builder",
    "author": "",
    "author_email": "Rocky Li <aperocky@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/af/40/c5f50ffe45ea9330d36ebfe4155e63299dae8dab2ce202ba9f8772bf87a3/replbuilder-1.2.0.tar.gz",
    "platform": null,
    "description": "## ReplBuilder\n\n![PyPI version](http://img.shields.io/pypi/v/replbuilder.svg)\n\n`pip install replbuilder`\n\nQuickly build a repl cli prompt for custom commands in python.\n\n`argparse` is used for quick and easy parsing interface, you should be able to utilize the full power of `argparse` as your command parser.\n\nA globally scoped context object can be optionally passed into each command, making context sharing and state possible. It also supports custom exception handlers, and aliases, and more.\n\nThis is a standalone package, it does not depend on any other packages.\n\nFor example, see project [hnterminal](https://github.com/Aperocky/hnterminal), browse, vote and comment on HN in your terminal.\n\n## Example\n\nsee [example calculator repl](example_calculator_repl.py) for example implementation. The gist can be concluded in a few lines:\n\n```\nadd_cmd = ReplCommand(\"add\", Calculator.basic_parser(), calculator.add, \"Add 2 numbers\")\nsub_cmd = ReplCommand(\"sub\", Calculator.basic_parser(), calculator.sub, \"Subtract second number from first\")\nfact_cmd = ReplCommand(\"factorial\", Calculator.factorial_parser(), calculator.factorial, \"factorial with exception handler\", exception_handler=exception_handler)\nsay_cmd = ReplCommand(\"cowsay\", Cow.get_cowsay_parser(), cow.cowsay, \"say stuff, demo optional and context usage\", use_context=True)\nmood_cmd = ReplCommand(\"cowmood\", argparse.ArgumentParser(), cow.cowmood, \"Mood of the cow changes with global context object\", use_context=True)\ncalc_commands = [add_cmd, sub_cmd, fact_cmd]\ncow_commands = [say_cmd, mood_cmd]\n\ncontext = ContextObj()\nrunner = ReplRunner(\"calculator\", context) # context is optional, but it helps maintaining state and avoiding duplicate work.\nrunner.add_commands(calc_commands, namespace=\"Calculator\") # namespace is optional\nrunner.add_commands(cow_commands, namespace=\"Cow\")\nrunner.run()\n```\n\nrun it `python example_calculator_repl.py`\n\nPart of the repl is colorized for better visibility:\n\n![example repl run](demo.jpg)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Quickly build a custom command REPL environment with this tool",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "https://github.com/Aperocky/replbuilder",
        "Source": "https://github.com/Aperocky/replbuilder"
    },
    "split_keywords": [
        "repl",
        "repl builder"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0b241616c8d66e8bec2c274b304347e84c9d588f4eb92691ae9dba932ef6d012",
                "md5": "d408a152a0c77da5a58573ec52cb9222",
                "sha256": "79c84c718a0570955c02f87c692fb37cca45bfa4fc43bc9cd4b1c17b5f42e2e0"
            },
            "downloads": -1,
            "filename": "replbuilder-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d408a152a0c77da5a58573ec52cb9222",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6958,
            "upload_time": "2023-08-14T00:42:28",
            "upload_time_iso_8601": "2023-08-14T00:42:28.322442Z",
            "url": "https://files.pythonhosted.org/packages/0b/24/1616c8d66e8bec2c274b304347e84c9d588f4eb92691ae9dba932ef6d012/replbuilder-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "af40c5f50ffe45ea9330d36ebfe4155e63299dae8dab2ce202ba9f8772bf87a3",
                "md5": "8fe023f062a813c19340886106627caa",
                "sha256": "934f5fcf0c81714298a1b523f7445f871ff11118ffa50003e45e6d80c00b1ae3"
            },
            "downloads": -1,
            "filename": "replbuilder-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8fe023f062a813c19340886106627caa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6202,
            "upload_time": "2023-08-14T00:42:29",
            "upload_time_iso_8601": "2023-08-14T00:42:29.939474Z",
            "url": "https://files.pythonhosted.org/packages/af/40/c5f50ffe45ea9330d36ebfe4155e63299dae8dab2ce202ba9f8772bf87a3/replbuilder-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-14 00:42:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Aperocky",
    "github_project": "replbuilder",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "replbuilder"
}
        
Elapsed time: 0.10158s