{ "info": { "author": "Sergio Garcez", "author_email": "garcez.sergio@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Arseparse\n=========\n\n|CircleCI| |codecov| |PyPI version| |PyPI format|\n\nArseparse is a simple Python utility/micro framework for writing command\nline interfaces. It provides some functionality around `argparse`_ that\ncovers some common scenarios.\n\nInstallation:\n\n::\n\n pip install arseparse\n\nBasic usage:\n\n::\n\n from arseparse import Parser, Option\n\n\n parser = Parser()\n\n\n # register a command that returns the square of an int\n parser.register('square', lambda value: value**2, [Option('value', type=int)])\n\n\n # register a command that simply returns a string\n parser.register('ping', lambda: 'pong')\n\n\n # or with a decorator\n @parser.register_dec([Option('value', type=int)])\n def cube(value):\n return value**3\n\n\n sys.exit(parser.run())\n\nYou can then point an application entrypoint to the script or execute\nthe file: ``your-entrypoint.py square 2``\n\nSo far so boring. A more common scenario is to have a config file as the\nfirst argument, parse it, create objects that the command depends on,\nand pass those alongside the parsed attributes. The ``root_options`` and\n``bootstrap`` constructor args to ``Parser`` allow us to implement this:\n\n::\n\n from arseparse import Parser, Option\n import myapp\n\n\n # these are options that come before our main command\n root_options = [Option('config', type=str, help='path to ini file')]\n\n\n # this lets us process/modify the kwargs before we execute the callable.\n # we can rely on attributes resulting from root_options to be set.\n # here config gets replaced by three objects: settings, db_session and user_svc\n def bootstrap(**kwargs):\n config_uri = kwargs.pop('config')\n settings = myapp.parse_app_config(config_uri)\n dbsession = myapp.get_sessionmaker(settings)()\n user_svc = myapp.UserService(dbsession)\n kwargs.update(dict(settings=settings, dbsession=dbsession, user_svc=user_svc))\n return kwargs\n\n\n parser = Parser(root_options, bootstrap)\n\n\n @parser.register_dec([Option('username', type=str), Option('secret', type=str)])\n def create_user(username, secret, user_svc, **kwargs):\n user_svc.create_user(username, secret)\n \n \n @parser.register_dec([Option('user_id', type=int)])\n def ban_user(user_id, user_svc, **kwargs):\n user_svc.ban_user(user_id)\n\n\n @parser.register_dec()\n def print_settings(settings, **kwargs):\n print(settings)\n\nYou can now provide the path to a config file as the first argument:\n``your-entrypoint.py config.ini ban_user 23``\n\nAnother common requirement is to be able to jump into a shell where some\nobjects have been preconfigured for us. Here\u2019s a simple recipe for that:\n\n::\n\n @parser.register_dec()\n def shell(**kwargs):\n import IPython\n IPython.embed(user_ns=kwargs)\n\n\nCalling `your-entrypoint.py config.ini shell` will drop you in an ipython shell where `dbsession`, `settings` and `user_svc` are in scope.\n\n.. _argparse: https://docs.python.org/3/library/argparse.html\n\n.. |CircleCI| image:: https://img.shields.io/circleci/project/github/sgarcez/arseparse/master.svg\n :target: https://circleci.com/gh/sgarcez/arseparse\n.. |codecov| image:: https://img.shields.io/codecov/c/github/sgarcez/arseparse.svg\n :target: https://codecov.io/gh/sgarcez/arseparse/\n.. |PyPI version| image:: https://badge.fury.io/py/arseparse.svg\n :target: https://pypi.python.org/pypi/arseparse\n.. |PyPI format| image:: https://img.shields.io/pypi/format/arseparse.svg\n :target: https://pypi.python.org/pypi/arseparse\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/sgarcez/arseparse", "keywords": "cli,argparse,command-line", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "arseparse", "package_url": "https://pypi.org/project/arseparse/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/arseparse/", "project_urls": { "Homepage": "https://github.com/sgarcez/arseparse" }, "release_url": "https://pypi.org/project/arseparse/0.1.2/", "requires_dist": null, "requires_python": "", "summary": "Command-line app helper library", "version": "0.1.2" }, "last_serial": 2689462, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "24a337309f0ed72b6f467c0f7b7129c4", "sha256": "2cba1a2527197405ac6c2a7e066a02180968715457e9eb4bc9be9c343624b166" }, "downloads": -1, "filename": "arseparse-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "24a337309f0ed72b6f467c0f7b7129c4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 2772, "upload_time": "2017-03-06T22:29:38", "url": "https://files.pythonhosted.org/packages/54/ee/3c4ff32287170ada0308395b35c3b7fe49268b4dc7bfb419dc3a5d6a4794/arseparse-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "35ef9ae56aaf7dd044e6b10af5eea983", "sha256": "b3e0bf2988e1451ee669537a5eca7d8b0449940fd8af8669e0a5cb5feab32194" }, "downloads": -1, "filename": "arseparse-0.1.tar.gz", "has_sig": false, "md5_digest": "35ef9ae56aaf7dd044e6b10af5eea983", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1698, "upload_time": "2017-03-06T22:29:39", "url": "https://files.pythonhosted.org/packages/2b/a5/d1327a65b1c964ceaed89244b9702f853f58a38dd595d780019df52812e1/arseparse-0.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "0d36074919ba0b6a4a60848c88c6d005", "sha256": "a3993a1b2d5d3ad8df63c0abcd19e0998cfa93f8d33cd06173456ad9551bcf56" }, "downloads": -1, "filename": "arseparse-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "0d36074919ba0b6a4a60848c88c6d005", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3160, "upload_time": "2017-03-07T18:08:14", "url": "https://files.pythonhosted.org/packages/7f/96/671768f9d8c1ade98984f9b7d17012d131d4fabf22ceb9a6056c237c5626/arseparse-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "95bb1016dc3ba5a9bc99c76569191f7e", "sha256": "a8fbb67dcf6161ee589d07d756ba16dc1429343ead6ae8629a5a1c6193c08840" }, "downloads": -1, "filename": "arseparse-0.1.2.tar.gz", "has_sig": false, "md5_digest": "95bb1016dc3ba5a9bc99c76569191f7e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3272, "upload_time": "2017-03-07T18:08:22", "url": "https://files.pythonhosted.org/packages/50/da/a220527f5ab6f36bf13f2ed432d9c392ec2efb4d6b6afbcee27b6dcb4fe4/arseparse-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0d36074919ba0b6a4a60848c88c6d005", "sha256": "a3993a1b2d5d3ad8df63c0abcd19e0998cfa93f8d33cd06173456ad9551bcf56" }, "downloads": -1, "filename": "arseparse-0.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "0d36074919ba0b6a4a60848c88c6d005", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3160, "upload_time": "2017-03-07T18:08:14", "url": "https://files.pythonhosted.org/packages/7f/96/671768f9d8c1ade98984f9b7d17012d131d4fabf22ceb9a6056c237c5626/arseparse-0.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "95bb1016dc3ba5a9bc99c76569191f7e", "sha256": "a8fbb67dcf6161ee589d07d756ba16dc1429343ead6ae8629a5a1c6193c08840" }, "downloads": -1, "filename": "arseparse-0.1.2.tar.gz", "has_sig": false, "md5_digest": "95bb1016dc3ba5a9bc99c76569191f7e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3272, "upload_time": "2017-03-07T18:08:22", "url": "https://files.pythonhosted.org/packages/50/da/a220527f5ab6f36bf13f2ed432d9c392ec2efb4d6b6afbcee27b6dcb4fe4/arseparse-0.1.2.tar.gz" } ] }