{ "info": { "author": "Vanessa Sochat", "author_email": "vsochat@stanford.edu", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Intended Audience :: Science/Research", "Operating System :: Unix", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Scientific/Engineering", "Topic :: Software Development" ], "description": "# Nushell Plugin Python\n\n[![PyPI version](https://badge.fury.io/py/nushell.svg)](https://pypi.org/project/nushell/)\n\nThis is a python module to allow for easy creation of plugins. It's\nalready fairly easy, but this can improve upon that! Each of the examples provided comes with:\n\n - the full example in a python file (without the .py extension)\n - containers with nushell to run with regular Python or (for some) a standalone binary (via pyinstaller)\n - README.md files to walk through the usage\n\nQuick start examples for a filter and sink plugin are included below, and you\nshould see the [examples](examples) folder for the complete code, makefiles, and Dockerfiles.\nPlease contribute new examples along with tweaks to the code! I developed this in\nunder a day, so we can likely make it much better, and will need to as nushell\nis developed.\n\n## Install\n\nYou can install from pip\n\n```bash\n$ pip install nushell\n```\n\nor from source here:\n\n```bash\n$ git clone https://github.com/vsoch/nushell-plugin-python\ncd nushell-plugin-python\npython setup.py install\n```\n\n## Plugin Class Arguments\n\nThe following are shared parameters for both filter and sink plugins.\n\n| Name | Description | Required or Default |\n|------|-------------|-------------------|\n| name | the name of the plugin | required |\n| usage | plugin usage | required | \n| logging | enable logging to `nu_plugin_.log` | defaults to True (enabled) |\n| add_help | add the `--help` flag | defaults to True |\n| parse_params | extract parameters from items | defaults to True |\n\n\n## Parameters\n\nParameters can be named or positional arguments that are defined for your\nplugin. You can actually have positional and named arguments with the\nsame name, and define the help string for one (and it will be used by\nthe other).\n\n### Named Parameters\n\nFor either a sink or a filter, you can pass in named arguments, meaning that your\nplugin will parse them like:\n\n```\n$ -- \n```\n\nor for a boolean (called a Switch)\n\n```\n$ --\n```\n\nHere are examples of adding all kinds of named arguments\n\n```python\n# add_named_argument(name, argType, syntaxShape=None, usage=None)\nplugin.add_named_argument(\"catch\", \"Switch\", usage=\"catch a random pokemon\")\nplugin.add_named_argument(\"list\", \"Switch\", usage=\"list pokemon names\")\nplugin.add_named_argument(\"list-sorted\", \"Switch\", usage=\"list sorted names\")\nplugin.add_named_argument(\"avatar\", \"Optional\", \"String\", \"generate avatar\")\nplugin.add_named_argument(\"pokemon\", \"Optional\", \"String\", \"get pokemon\")\n```\n\nFor an argument to be Mandatory, just change \"Optional\" to \"Mandatory\" (the \nabove plugin doesn't require anything).\n\n\n### Positional Arguments\n\nPositional arguments come after the plugin name, but don't have a flag.\nFor example:\n\n```bash\n$ \n```\n\nHere are examples of adding positional arguments. Each needs a name,\nif it's Mandatory or Optional (there is no Switch), the SyntaxShape (e.g. String, Int, Any)\nand then a usage string.\n\n```python\n# add_positional_argument(name, argType, syntaxShape=None, usage=None)\nplugin.add_positional_argument(\"number\", \"Mandatory\", \"Int\", usage=\"number to parse\")\nplugin.add_positional_argument(\"secondNumber\", \"Optional\", \"Any\", usage=\"second number to parse\")\n```\n\n## Filter Plugin\n\nA basic filter plugin will instantiate the `FilterPlugin` class, and then\nprovide a function to run for the filter.\n\n```python\n#!/usr/bin/env python3\n\nfrom nushell.filter import FilterPlugin\n\n# Your filter function will be called by the FilterPlugin, and should\n# accept the plugin and the dictionary of params\ndef runFilter(plugin, params):\n '''runFilter will be executed by the calling SinkPlugin when method is \"sink\"\n '''\n # Get the string primitive passed by the user\n value = plugin.get_string_primitive()\n\n # Calculate the length\n intLength = len(value)\n\n # Print an integer response (can also be print_string_response)\n plugin.print_int_response(intLength)\n\n\n# The main function is where you create your plugin and run it.\ndef main():\n\n # Initialize a new plugin\n plugin = FilterPlugin(name=\"len\", \n usage=\"Return the length of a string\")\n\n\n # Run the plugin by passing your filter function\n plugin.run(runFilter)\n\n\nif __name__ == '__main__':\n main()\n```\n\nNotably, your filter function should taken a plugin and parsed command line\nparameters (dictionary) as arguments. You can use the plugin to perform\nseveral needed functions to send responses back to nushell, or log to `/tmp/nushell-plugin-.log`:\n\n```python\nplugin.logger.\nplugin.get_string_primitive()\nplugin.get_int_primitive()\nplugin.print_int_response()\nplugin.print_string_response()\n```\n\n### Examples\n\n - [len](examples/len) is a basic function to return the length of a string\n - [plus](examples/plus) adds two ints, and is an example with positional arguments\n\n\n## Sink Plugin\n\nA sink plugin will instantiate the `SinkPlugin` class, and then hand off\nstdin (via a temporary file) to a sink function that you write.\nHere is a dummy example.\n\n```python\n#!/usr/bin/env python3\n\nfrom nushell.sink import SinkPlugin\n\n# Your sink function will be called by the sink Plugin, and should\n# accept the plugin and the dictionary of params\ndef sink(plugin, params):\n '''sink will be executed by the calling SinkPlugin when method is \"sink\"\n '''\n message = \"Hello\"\n excited = params.get(\"excited\", False)\n name = params.get(\"name\", \"\")\n \n # If we have a name, add to message\n message = \"%s %s\" %(message, name)\n \n # Are we excited?\n if excited:\n message += \"!\"\n\n print(message)\n\n\n# The main function is where you create your plugin and run it.\ndef main():\n\n # Initialize a new plugin\n plugin = SinkPlugin(name=\"hello\", \n usage=\"A friendly plugin\")\n\n\n # Add named arguments (notice we check for in params in sink function)\n # add_named_argument(name, argType, syntaxShape=None, usage=None)\n plugin.add_named_argument(\"excited\", \"Switch\", usage=\"add an exclamation point!\")\n plugin.add_named_argument(\"name\", \"Optional\", \"String\", usage=\"say hello to...\")\n\n # Run the plugin by passing your sink function\n plugin.run(sink)\n\n\nif __name__ == '__main__':\n main()\n```\n\n### Parameters\n\nSince you can pipe content into a sink, the piped content is parsed into a list\nand passed with params as the `_pipe` key. For example, if we do:\n\n```bash\n> ls | get name | hello --name Dinosaur\nHello Dinosaur\n```\n\nAnd then look in the output file, we see that the parsed params include a pipe\nof all the named of the listed files (that we generated above)\n\n```bash\nPARAMS {'name': 'Dinosaur', '_pipe': ['Makefile', 'README.md', 'Dockerfile', 'nu_plugin_hello', 'Dockerfile.standalone']}\n```\n\nIf you don't want to parse the pipe, set your plugin.parse_pipe to False:\n\n```python\nplugin.parse_pipe = False\nplugin.run(sink)\n```\n\nAnd the result will include the full list of entries with items and tags.\n\n```python\nPARAMS {'name': 'Dinosaur', '_pipe': [[{'tag': {'anchor': None, 'span': {'start': 0, 'end': 2}}, 'item': {'Primitive': {'String': 'Makefile'}}}, {'tag': {'anchor': None, 'span': {'start': 0, 'end': 2}}, 'item': {'Primitive': {'String': 'README.md'}}}, {'tag': {'anchor': None, 'span': {'start': 0, 'end': 2}}, 'item': {'Primitive': {'String': 'Dockerfile'}}}, {'tag': {'anchor': None, 'span': {'start': 0, 'end': 2}}, 'item': {'Primitive': {'String': 'nu_plugin_hello'}}}, {'tag': {'anchor': None, 'span': {'start': 0, 'end': 2}}, 'item': {'Primitive': {'String': 'Dockerfile.standalone'}}}]]}\n```\n\n### Examples\n\n - [pokemon](examples/pokemon) ascii pokemon on demand!\n - [hello](examples/hello) say hello using a sink!\n\n\n## Single Binary\n\nIn that you are able to compile your module with [pyinstaller](https://pyinstaller.readthedocs.io/en/stable/operating-mode.html) (e.g., see [examples/len](examples/len)) you can build your python script as a simple binary, and one that doesn't even need nushell installed as a module anymore. Why might you want to do this? It will mean that your plugin is a single file (binary) and you don't need to rely on modules elsewhere in the system. I suspect there are other ways to compile\npython into a single binary (e.g., cython) but this was the first I tried, and fairly straight forward.\nIf you find a different or better way, please contribute to this code base!\n\n**Important** I've found that modules with added data files don't do well (an example is [pokemon](examples/pokemon) here!)\nand that's why we can't uninstall pokemon or nushell. However, I think you would have luck with most text based,\nsimple modules. And of course, you don't have to do this! It's totally ok to keep your Python modules\ninstalled alongside nushell, and used when your plugin is executed.\n\n## License\n\nThis code is licensed under the MPL 2.0 [LICENSE](LICENSE).\n\n## Help and Contribution\n\nPlease contribute to the package, or post feedback and questions as issues.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://www.github.com/vsoch/nushell-plugin-python", "keywords": "nushell,plugin,nu", "license": "LICENSE", "maintainer": "Vanessa Sochat", "maintainer_email": "vsochat@stanford.edu", "name": "nushell", "package_url": "https://pypi.org/project/nushell/", "platform": "", "project_url": "https://pypi.org/project/nushell/", "project_urls": { "Homepage": "http://www.github.com/vsoch/nushell-plugin-python" }, "release_url": "https://pypi.org/project/nushell/0.0.16/", "requires_dist": null, "requires_python": "", "summary": "Python module to easily create nushell plugins", "version": "0.0.16", "yanked": false, "yanked_reason": null }, "last_serial": 6037649, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "eb8d37b4d9e3b6785a9d41f99de5900a", "sha256": "84bd7d1c20a842c2429c94da8196b2e9840fa1b83efc19f7bbf006b7144aa9c4" }, "downloads": -1, "filename": "nushell-0.0.0.tar.gz", "has_sig": false, "md5_digest": "eb8d37b4d9e3b6785a9d41f99de5900a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10022, "upload_time": "2019-10-23T19:09:02", "upload_time_iso_8601": "2019-10-23T19:09:02.925946Z", "url": "https://files.pythonhosted.org/packages/46/95/f5032b066699eba6da485b3883a558b63aa5160a4034eb4aa7ed559026d5/nushell-0.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.1": [ { "comment_text": "", "digests": { "md5": "9259b9f30664275d7956a46e67166788", "sha256": "8dc94fd9d83df2539fd33c56fa7e96d7efa9faed0bbf94695b90799759bcbe1b" }, "downloads": -1, "filename": "nushell-0.0.1-py3.7.egg", "has_sig": false, "md5_digest": "9259b9f30664275d7956a46e67166788", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 29445, "upload_time": "2019-10-24T18:30:17", "upload_time_iso_8601": "2019-10-24T18:30:17.731288Z", "url": "https://files.pythonhosted.org/packages/42/71/4a824275aa86a99e92956e75ad34ae74ad72d4051ec5f7ef3a712599ea8c/nushell-0.0.1-py3.7.egg", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "2a2f505e10c0599df0d377bd80aa11c5", "sha256": "bd535663ddb0df785216b2c1280004c6b3228cb03f098f4ca6acf8a340c3f366" }, "downloads": -1, "filename": "nushell-0.0.1.tar.gz", "has_sig": false, "md5_digest": "2a2f505e10c0599df0d377bd80aa11c5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19498, "upload_time": "2019-10-24T18:30:19", "upload_time_iso_8601": "2019-10-24T18:30:19.067429Z", "url": "https://files.pythonhosted.org/packages/6e/ec/3badfbedae86855c1a933689415548e06be7955a946cb2a32a22c116e29d/nushell-0.0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.11": [ { "comment_text": "", "digests": { "md5": "84222c9d22d3f2101e4e39754e969d71", "sha256": "5a16ea9c1f6646bc35224bc1f298b257cc559abae8b5704b7ece7b811e287ce4" }, "downloads": -1, "filename": "nushell-0.0.11.tar.gz", "has_sig": false, "md5_digest": "84222c9d22d3f2101e4e39754e969d71", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21442, "upload_time": "2019-10-24T20:16:24", "upload_time_iso_8601": "2019-10-24T20:16:24.477739Z", "url": "https://files.pythonhosted.org/packages/17/56/ee445f2e2d8e1e66e2a30a3719d34c661510bd26acfd107b15e4bd9b8a21/nushell-0.0.11.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.12": [ { "comment_text": "", "digests": { "md5": "84f9d6cb446e2def285dc10d33bd6e92", "sha256": "816f52eccf5a5cf9271dae05b87376afd9c7d64bf6ee002efbccff4f1fed1182" }, "downloads": -1, "filename": "nushell-0.0.12-py3.7.egg", "has_sig": false, "md5_digest": "84f9d6cb446e2def285dc10d33bd6e92", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 33723, "upload_time": "2019-10-25T15:12:41", "upload_time_iso_8601": "2019-10-25T15:12:41.384319Z", "url": "https://files.pythonhosted.org/packages/c7/73/553c3b5f9529f3549bf49b012ffc4b0665bdd7197615eecd158f8da1545a/nushell-0.0.12-py3.7.egg", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "ce82fd8ddf7ec54c61b532cd35307130", "sha256": "dd67b05096a61610e82b958fd04237bcc1beb54abe5f7d3c826a4682636792ca" }, "downloads": -1, "filename": "nushell-0.0.12.tar.gz", "has_sig": false, "md5_digest": "ce82fd8ddf7ec54c61b532cd35307130", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23322, "upload_time": "2019-10-25T15:12:42", "upload_time_iso_8601": "2019-10-25T15:12:42.706890Z", "url": "https://files.pythonhosted.org/packages/e3/be/7046afa9ba2eedac190fc86f26babfb47cfca4a1e84da2a309d7faa4e1cb/nushell-0.0.12.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.13": [ { "comment_text": "", "digests": { "md5": "71ee768f8da9c657fcb94f88ff8b12e0", "sha256": "c66fa88e6153ba173f32fa9eec86eae47aa1b46f79fc21d3d239770eba3b5af6" }, "downloads": -1, "filename": "nushell-0.0.13.tar.gz", "has_sig": false, "md5_digest": "71ee768f8da9c657fcb94f88ff8b12e0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25968, "upload_time": "2019-10-25T18:47:44", "upload_time_iso_8601": "2019-10-25T18:47:44.166307Z", "url": "https://files.pythonhosted.org/packages/6e/e5/cdd615b3083dd620acb9710e390aecb202b9c80ea7123953bd57dfc6bd09/nushell-0.0.13.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.14": [ { "comment_text": "", "digests": { "md5": "22eff317b21886df6049e2fac8e06b7d", "sha256": "39fb74ca315368da8c8edff6f6814c3f81db863f6b09784f04f63d733b8e17b3" }, "downloads": -1, "filename": "nushell-0.0.14.tar.gz", "has_sig": false, "md5_digest": "22eff317b21886df6049e2fac8e06b7d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 26166, "upload_time": "2019-10-25T19:29:13", "upload_time_iso_8601": "2019-10-25T19:29:13.223234Z", "url": "https://files.pythonhosted.org/packages/ce/b6/3c96113ef9c42ff352228c17a8c216c89c4aa5d40f6032e95050c8981f0f/nushell-0.0.14.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.15": [ { "comment_text": "", "digests": { "md5": "bbf354f16c3066620e0d26143890b2fb", "sha256": "bad6b67a5273ae125cf6ec91acd8a0c95bd75fa083b60ad4047ac34afeb7504e" }, "downloads": -1, "filename": "nushell-0.0.15-py3.7.egg", "has_sig": false, "md5_digest": "bbf354f16c3066620e0d26143890b2fb", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 35810, "upload_time": "2019-10-25T21:20:08", "upload_time_iso_8601": "2019-10-25T21:20:08.870798Z", "url": "https://files.pythonhosted.org/packages/64/ce/eb0a6d0dd765c76894a4b7a5efa0b725a918808314f50875c5c9474a141d/nushell-0.0.15-py3.7.egg", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "64af5553f2fd3e875717db255bf3a743", "sha256": "1ca9264379987b56b9f93f7ed4880e203008bbf8334e5254171b28488b949d98" }, "downloads": -1, "filename": "nushell-0.0.15.tar.gz", "has_sig": false, "md5_digest": "64af5553f2fd3e875717db255bf3a743", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 26257, "upload_time": "2019-10-25T21:20:10", "upload_time_iso_8601": "2019-10-25T21:20:10.576917Z", "url": "https://files.pythonhosted.org/packages/cc/1a/9e21742dd1a63eebd363e7644c109929d9040cb908be11cc5fd7a3fce6d9/nushell-0.0.15.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.16": [ { "comment_text": "", "digests": { "md5": "05c047dfd4dae09fdf42e233122ddec0", "sha256": "5e2cd49287f2c62e4253661204c67674b7619ddea92c512a5259b8ee5d281c44" }, "downloads": -1, "filename": "nushell-0.0.16-py3.7.egg", "has_sig": false, "md5_digest": "05c047dfd4dae09fdf42e233122ddec0", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 46008, "upload_time": "2019-10-27T17:01:54", "upload_time_iso_8601": "2019-10-27T17:01:54.361001Z", "url": "https://files.pythonhosted.org/packages/5d/d5/c89452518977ba08a421a547560a88c98f6cf62d03c3ea5b6294899bd23e/nushell-0.0.16-py3.7.egg", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "781c4a298c59d2574d82a10ff1950dfc", "sha256": "3f355a7426dbec7007d77ba970e0908350cac4c7d1f6d25d42a0524317b7be89" }, "downloads": -1, "filename": "nushell-0.0.16.tar.gz", "has_sig": false, "md5_digest": "781c4a298c59d2574d82a10ff1950dfc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 34913, "upload_time": "2019-10-27T17:01:56", "upload_time_iso_8601": "2019-10-27T17:01:56.272597Z", "url": "https://files.pythonhosted.org/packages/ed/ee/fb4bdeda6a5a96c1edc9d57e097f3b3a2d6f1929ca90ec525cbcd1bb0189/nushell-0.0.16.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "05c047dfd4dae09fdf42e233122ddec0", "sha256": "5e2cd49287f2c62e4253661204c67674b7619ddea92c512a5259b8ee5d281c44" }, "downloads": -1, "filename": "nushell-0.0.16-py3.7.egg", "has_sig": false, "md5_digest": "05c047dfd4dae09fdf42e233122ddec0", "packagetype": "bdist_egg", "python_version": "3.7", "requires_python": null, "size": 46008, "upload_time": "2019-10-27T17:01:54", "upload_time_iso_8601": "2019-10-27T17:01:54.361001Z", "url": "https://files.pythonhosted.org/packages/5d/d5/c89452518977ba08a421a547560a88c98f6cf62d03c3ea5b6294899bd23e/nushell-0.0.16-py3.7.egg", "yanked": false, "yanked_reason": null }, { "comment_text": "", "digests": { "md5": "781c4a298c59d2574d82a10ff1950dfc", "sha256": "3f355a7426dbec7007d77ba970e0908350cac4c7d1f6d25d42a0524317b7be89" }, "downloads": -1, "filename": "nushell-0.0.16.tar.gz", "has_sig": false, "md5_digest": "781c4a298c59d2574d82a10ff1950dfc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 34913, "upload_time": "2019-10-27T17:01:56", "upload_time_iso_8601": "2019-10-27T17:01:56.272597Z", "url": "https://files.pythonhosted.org/packages/ed/ee/fb4bdeda6a5a96c1edc9d57e097f3b3a2d6f1929ca90ec525cbcd1bb0189/nushell-0.0.16.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }