argh


Nameargh JSON
Version 0.31.2 PyPI version JSON
download
home_page
SummaryPlain Python functions as CLI commands without boilerplate
upload_time2024-01-24 21:30:37
maintainer
docs_urlhttps://pythonhosted.org/argh/
author
requires_python>=3.8
license
keywords cli command line argparse optparse argument option
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Argh: The Effortless CLI
========================

.. image:: https://github.com/neithere/argh/actions/workflows/lint-and-test.yml/badge.svg
    :target: https://github.com/neithere/argh/actions/workflows/lint-and-test.yml

.. image:: https://img.shields.io/pypi/format/argh.svg
    :target: https://pypi.python.org/pypi/argh

.. image:: https://img.shields.io/pypi/status/argh.svg
    :target: https://pypi.python.org/pypi/argh

.. image:: https://img.shields.io/pypi/v/argh.svg
    :target: https://pypi.python.org/pypi/argh

.. image:: https://img.shields.io/pypi/pyversions/argh.svg
    :target: https://pypi.python.org/pypi/argh

.. image:: https://img.shields.io/pypi/dd/argh.svg
    :target: https://pypi.python.org/pypi/argh

.. image:: https://readthedocs.org/projects/argh/badge/?version=stable
    :target: http://argh.readthedocs.org/en/stable/

.. image:: https://readthedocs.org/projects/argh/badge/?version=latest
    :target: http://argh.readthedocs.org/en/latest/

**The power of Argparse with plain Python functions!**

Building a command-line interface?  Found yourself uttering "argh!" while
struggling with the API of `argparse`?  Don't like the complexity but need
the power?

`Argh` builds on the power of `argparse` (which comes with Python) and makes it
really easy to use.  It eliminates the complex API and lets you "dispatch"
ordinary Python functions as CLI commands.

Installation
------------

::

    $ pip install argh

Example
-------

.. code-block:: python

    import argh

    def verify_paths(paths: list[str], *, verbose: bool = False):
        """
        Verify that all given paths exist.
        """
        for path in paths:
            if verbose:
                print(f"Checking {path}...")
            assert os.path.exists(path)

    argh.dispatch_command(verify_paths)

Now you can run the script like this:

.. code-block:: bash

    $ python app.py foo.txt bar/quux.txt

    $ python app.py foo.txt bar/quux.txt --verbose
    Checking foo.txt...
    Checking bar/quux.txt...

    $ python app.py -h
    usage: app.py [-h] [-v] [paths ...]

    Verify that all given paths exist.

    positional arguments:
      paths          -

    options:
      -h, --help     show this help message and exit
      -v, --verbose  False

Please check the documentation for examples of multiple commands, modularity,
help generation, advanced type annotations inspection, decorators and more:

* `Quick Start <https://argh.readthedocs.io/en/latest/quickstart.html>`_
* `Tutorial <https://argh.readthedocs.io/en/latest/tutorial.html>`_

Why Argh?
---------

`Argh`-powered applications are *simple* but *flexible*:

:Pythonic, KISS:
    Commands are plain Python functions.  Almost no CLI-specific API to learn.

:Reusable:
    Endpoint functions can be used directly outside of CLI context.

:Static typing friendly:
    100% of the code including endpoint functions can be type-checked.
    Argh is driven primarily by type annotations.

:DRY:
    Don't Repeat Yourself.  The amount of boilerplate code is minimal.
    Among other things, `Argh` will:

    * infer command name from function name;
    * infer arguments from function signature;
    * infer argument types, actions and much more from annotations.

:Modular:
    Declaration of commands can be decoupled from assembling and dispatching.

:Layered:
    The complexity of code raises with requirements.

:Transparent:
    You can directly access `argparse.ArgumentParser` if needed.

:Subcommands:
    Easily nested commands.  Argh isolates the complexity of subparsers.

:NIH free:
    `Argh` supports *completion*, *progress bars* and everything else by being
    friendly to excellent 3rd-party libraries.  No need to reinvent the wheel.

:Compact:
    No dependencies apart from Python's standard library.

Links
-----

See also the `project page on GitHub`_, `documentation`_ and `PyPI page`_.

.. _project page on GitHub: http://github.com/neithere/argh/
.. _documentation: http://argh.readthedocs.org
.. _PyPI page: http://pypi.python.org/pypi/argh

Author
------

Developed by Andrey Mikhaylenko since 2010.

See `contributors <https://argh.readthedocs.io/en/latest/contributors.html>`_
for a list of contributors to this library.

Contribute
----------

The fastest way to improve this project is to submit tested and documented
patches or detailed bug reports.

Donate
------

You can `donate via Liberapay`_.  This may speed up development or simply
make the original author happy :)

.. _donate via Liberapay: https://liberapay.com/neithere/donate

Licensing
---------

Argh is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Argh is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with Argh.  If not, see <http://gnu.org/licenses/>.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "argh",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/argh/",
    "requires_python": ">=3.8",
    "maintainer_email": "Andy Mikhaylenko <neithere@gmail.com>",
    "keywords": "cli,command line,argparse,optparse,argument,option",
    "author": "",
    "author_email": "Andy Mikhaylenko <neithere@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/4e/ae/3c1896d2e8c7f74270686f339aa4a07dd8d4ffddde96488fcb1a726eb072/argh-0.31.2.tar.gz",
    "platform": null,
    "description": "Argh: The Effortless CLI\n========================\n\n.. image:: https://github.com/neithere/argh/actions/workflows/lint-and-test.yml/badge.svg\n    :target: https://github.com/neithere/argh/actions/workflows/lint-and-test.yml\n\n.. image:: https://img.shields.io/pypi/format/argh.svg\n    :target: https://pypi.python.org/pypi/argh\n\n.. image:: https://img.shields.io/pypi/status/argh.svg\n    :target: https://pypi.python.org/pypi/argh\n\n.. image:: https://img.shields.io/pypi/v/argh.svg\n    :target: https://pypi.python.org/pypi/argh\n\n.. image:: https://img.shields.io/pypi/pyversions/argh.svg\n    :target: https://pypi.python.org/pypi/argh\n\n.. image:: https://img.shields.io/pypi/dd/argh.svg\n    :target: https://pypi.python.org/pypi/argh\n\n.. image:: https://readthedocs.org/projects/argh/badge/?version=stable\n    :target: http://argh.readthedocs.org/en/stable/\n\n.. image:: https://readthedocs.org/projects/argh/badge/?version=latest\n    :target: http://argh.readthedocs.org/en/latest/\n\n**The power of Argparse with plain Python functions!**\n\nBuilding a command-line interface?  Found yourself uttering \"argh!\" while\nstruggling with the API of `argparse`?  Don't like the complexity but need\nthe power?\n\n`Argh` builds on the power of `argparse` (which comes with Python) and makes it\nreally easy to use.  It eliminates the complex API and lets you \"dispatch\"\nordinary Python functions as CLI commands.\n\nInstallation\n------------\n\n::\n\n    $ pip install argh\n\nExample\n-------\n\n.. code-block:: python\n\n    import argh\n\n    def verify_paths(paths: list[str], *, verbose: bool = False):\n        \"\"\"\n        Verify that all given paths exist.\n        \"\"\"\n        for path in paths:\n            if verbose:\n                print(f\"Checking {path}...\")\n            assert os.path.exists(path)\n\n    argh.dispatch_command(verify_paths)\n\nNow you can run the script like this:\n\n.. code-block:: bash\n\n    $ python app.py foo.txt bar/quux.txt\n\n    $ python app.py foo.txt bar/quux.txt --verbose\n    Checking foo.txt...\n    Checking bar/quux.txt...\n\n    $ python app.py -h\n    usage: app.py [-h] [-v] [paths ...]\n\n    Verify that all given paths exist.\n\n    positional arguments:\n      paths          -\n\n    options:\n      -h, --help     show this help message and exit\n      -v, --verbose  False\n\nPlease check the documentation for examples of multiple commands, modularity,\nhelp generation, advanced type annotations inspection, decorators and more:\n\n* `Quick Start <https://argh.readthedocs.io/en/latest/quickstart.html>`_\n* `Tutorial <https://argh.readthedocs.io/en/latest/tutorial.html>`_\n\nWhy Argh?\n---------\n\n`Argh`-powered applications are *simple* but *flexible*:\n\n:Pythonic, KISS:\n    Commands are plain Python functions.  Almost no CLI-specific API to learn.\n\n:Reusable:\n    Endpoint functions can be used directly outside of CLI context.\n\n:Static typing friendly:\n    100% of the code including endpoint functions can be type-checked.\n    Argh is driven primarily by type annotations.\n\n:DRY:\n    Don't Repeat Yourself.  The amount of boilerplate code is minimal.\n    Among other things, `Argh` will:\n\n    * infer command name from function name;\n    * infer arguments from function signature;\n    * infer argument types, actions and much more from annotations.\n\n:Modular:\n    Declaration of commands can be decoupled from assembling and dispatching.\n\n:Layered:\n    The complexity of code raises with requirements.\n\n:Transparent:\n    You can directly access `argparse.ArgumentParser` if needed.\n\n:Subcommands:\n    Easily nested commands.  Argh isolates the complexity of subparsers.\n\n:NIH free:\n    `Argh` supports *completion*, *progress bars* and everything else by being\n    friendly to excellent 3rd-party libraries.  No need to reinvent the wheel.\n\n:Compact:\n    No dependencies apart from Python's standard library.\n\nLinks\n-----\n\nSee also the `project page on GitHub`_, `documentation`_ and `PyPI page`_.\n\n.. _project page on GitHub: http://github.com/neithere/argh/\n.. _documentation: http://argh.readthedocs.org\n.. _PyPI page: http://pypi.python.org/pypi/argh\n\nAuthor\n------\n\nDeveloped by Andrey Mikhaylenko since 2010.\n\nSee `contributors <https://argh.readthedocs.io/en/latest/contributors.html>`_\nfor a list of contributors to this library.\n\nContribute\n----------\n\nThe fastest way to improve this project is to submit tested and documented\npatches or detailed bug reports.\n\nDonate\n------\n\nYou can `donate via Liberapay`_.  This may speed up development or simply\nmake the original author happy :)\n\n.. _donate via Liberapay: https://liberapay.com/neithere/donate\n\nLicensing\n---------\n\nArgh is free software: you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as published\nby the Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nArgh is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU Lesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public License\nalong with Argh.  If not, see <http://gnu.org/licenses/>.\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Plain Python functions as CLI commands without boilerplate",
    "version": "0.31.2",
    "project_urls": {
        "Discussions": "https://github.com/neithere/argh/discussions",
        "Documentation": "https://argh.readthedocs.io/en/latest",
        "Homepage": "https://github.com/neithere/argh",
        "Issue Tracker": "https://github.com/neithere/argh/issues",
        "Releases": "https://github.com/neithere/argh/releases"
    },
    "split_keywords": [
        "cli",
        "command line",
        "argparse",
        "optparse",
        "argument",
        "option"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2f79c619ba76e97e4932f110f8eb133e823057b1aef82c3dd6b9c6bcb6703dd8",
                "md5": "295c9794ef7fc2b87baf85ac732a242f",
                "sha256": "81a9ab43dacfc0d8e08794a140cda7927908417c8f89a969e6554cfc2e872e14"
            },
            "downloads": -1,
            "filename": "argh-0.31.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "295c9794ef7fc2b87baf85ac732a242f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 44810,
            "upload_time": "2024-01-24T21:30:35",
            "upload_time_iso_8601": "2024-01-24T21:30:35.190710Z",
            "url": "https://files.pythonhosted.org/packages/2f/79/c619ba76e97e4932f110f8eb133e823057b1aef82c3dd6b9c6bcb6703dd8/argh-0.31.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4eae3c1896d2e8c7f74270686f339aa4a07dd8d4ffddde96488fcb1a726eb072",
                "md5": "af222a1097dac25f1e2958222f0a116c",
                "sha256": "db1c34885804f7d4646c385dc2fb19b45298561322f4c15eae1b133993f9e323"
            },
            "downloads": -1,
            "filename": "argh-0.31.2.tar.gz",
            "has_sig": false,
            "md5_digest": "af222a1097dac25f1e2958222f0a116c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 57200,
            "upload_time": "2024-01-24T21:30:37",
            "upload_time_iso_8601": "2024-01-24T21:30:37.392234Z",
            "url": "https://files.pythonhosted.org/packages/4e/ae/3c1896d2e8c7f74270686f339aa4a07dd8d4ffddde96488fcb1a726eb072/argh-0.31.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-24 21:30:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "neithere",
    "github_project": "argh",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "argh"
}
        
Elapsed time: 0.18561s