defopt


Namedefopt JSON
Version 6.4.0 PyPI version JSON
download
home_pagehttps://github.com/anntzer/defopt
SummaryEffortless argument parser
upload_time2022-07-19 17:16:40
maintainer
docs_urlNone
authorAntony Lee
requires_python>=3.5
licenseMIT
keywords argument parser parsing optparse argparse getopt docopt sphinx
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            defopt
======

| |GitHub| |PyPI| |conda-forge|
| |Read the Docs| |Build|

.. |GitHub|
   image:: https://img.shields.io/badge/github-anntzer%2Fdefopt-brightgreen
   :target: `GitHub repository`_
.. |PyPI|
   image:: https://img.shields.io/pypi/v/defopt.svg?color=brightgreen
   :target: https://pypi.python.org/pypi/defopt
.. |conda-forge|
   image:: https://img.shields.io/conda/v/conda-forge/defopt.svg?label=conda-forge&color=brightgreen
   :target: https://anaconda.org/conda-forge/defopt
.. |Read the Docs|
   image:: https://img.shields.io/readthedocs/defopt
   :target: `Read the Docs`_
.. |Build|
   image:: https://img.shields.io/github/workflow/status/anntzer/defopt/build
   :target: https://github.com/anntzer/defopt/actions

defopt is a lightweight, no-effort argument parser.

defopt will:

- Allow functions to be run from code and the command line without modification.
- Reward you for documenting your functions.
- Save you from writing, testing and maintaining argument parsing code.

defopt will not:

- Modify your functions in any way.
- Allow you to build highly complex or customized command line tools.

If you want total control over how your command line looks or behaves, try
docopt_, click_ or argh_. If you just want to write Python code and leave the
command line interface up to someone else, defopt is for you.

Usage
-----

Once you have written and documented_ your function, simply pass it to
`defopt.run()` and you're done.

.. code-block:: python

    import defopt

    # Use type hints:
    def main(greeting: str, *, count: int = 1):
        """
        Display a friendly greeting.

        :param greeting: Greeting to display
        :param count: Number of times to display the greeting
        """
        for _ in range(count):
            print(greeting)

    # ... or document parameter types in the docstring:
    def main(greeting, *, count=1):
        """
        Display a friendly greeting.

        :param str greeting: Greeting to display
        :param int count: Number of times to display the greeting
        """
        for _ in range(count):
            print(greeting)

    if __name__ == '__main__':
        defopt.run(main)

Descriptions of the parameters and the function itself are used to build an
informative help message.

::

    $ python test.py -h
    usage: test.py [-h] [-c COUNT] greeting

    Display a friendly greeting.

    positional arguments:
      greeting              Greeting to display

    optional arguments:
      -h, --help            show this help message and exit
      -c COUNT, --count COUNT
                            Number of times to display the greeting
                            (default: 1)

Your function can now be called identically from Python and the command line.

::

    >>> from test import main
    >>> main('hello!', count=2)
    hello!
    hello!

::

    $ python test.py hello! --count 2
    hello!
    hello!

Philosopy
---------

defopt was developed with the following guiding principles in mind:

#. **The interface can be fully understood in seconds.** If it took any longer,
   your time would be better spent learning a more flexible tool.

#. **Anything you learn applies to the existing ecosystem.** The exact same
   docstrings used by defopt are also used by Sphinx's autodoc_ extension to
   generate documentation, and by your IDE to do type checking. Chances are you
   already know everything you need to know to use defopt.

#. **Everything is handled for you.** If you're using defopt, it's because you
   don't want to write any argument parsing code *at all*. You can trust it to
   build a logically consistent command line interface to your functions
   with no configuration required.

#. **Your Python functions are never modified.** Type conversions are only ever
   applied to data originating from the command line. When used in code,
   duck-typing still works exactly as you expect with no surprises.

Development
-----------

For source code, examples, questions, feature requests and bug reports, visit
the `GitHub repository`_.

Documentation
-------------

Documentation is hosted on `Read the Docs`_.

.. _GitHub repository: https://github.com/anntzer/defopt
.. _Read the Docs: https://defopt.readthedocs.io/en/latest/
.. _autodoc: http://www.sphinx-doc.org/en/stable/ext/autodoc.html
.. _docopt: http://docopt.org/
.. _click: http://click.palletsprojects.com/
.. _argh: https://argh.readthedocs.io/en/latest/
.. _documented: https://defopt.readthedocs.io/en/latest/features.html#docstring-styles

.. This document is included in docs/index.rst; table of contents appears here.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/anntzer/defopt",
    "name": "defopt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "argument parser parsing optparse argparse getopt docopt sphinx",
    "author": "Antony Lee",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/cc/3f/3baf4e6fed12dac76c0ccb4716fd4235ef0aa5b48f66aab6f970afc7b44e/defopt-6.4.0.tar.gz",
    "platform": null,
    "description": "defopt\n======\n\n| |GitHub| |PyPI| |conda-forge|\n| |Read the Docs| |Build|\n\n.. |GitHub|\n   image:: https://img.shields.io/badge/github-anntzer%2Fdefopt-brightgreen\n   :target: `GitHub repository`_\n.. |PyPI|\n   image:: https://img.shields.io/pypi/v/defopt.svg?color=brightgreen\n   :target: https://pypi.python.org/pypi/defopt\n.. |conda-forge|\n   image:: https://img.shields.io/conda/v/conda-forge/defopt.svg?label=conda-forge&color=brightgreen\n   :target: https://anaconda.org/conda-forge/defopt\n.. |Read the Docs|\n   image:: https://img.shields.io/readthedocs/defopt\n   :target: `Read the Docs`_\n.. |Build|\n   image:: https://img.shields.io/github/workflow/status/anntzer/defopt/build\n   :target: https://github.com/anntzer/defopt/actions\n\ndefopt is a lightweight, no-effort argument parser.\n\ndefopt will:\n\n- Allow functions to be run from code and the command line without modification.\n- Reward you for documenting your functions.\n- Save you from writing, testing and maintaining argument parsing code.\n\ndefopt will not:\n\n- Modify your functions in any way.\n- Allow you to build highly complex or customized command line tools.\n\nIf you want total control over how your command line looks or behaves, try\ndocopt_, click_ or argh_. If you just want to write Python code and leave the\ncommand line interface up to someone else, defopt is for you.\n\nUsage\n-----\n\nOnce you have written and documented_ your function, simply pass it to\n`defopt.run()` and you're done.\n\n.. code-block:: python\n\n    import defopt\n\n    # Use type hints:\n    def main(greeting: str, *, count: int = 1):\n        \"\"\"\n        Display a friendly greeting.\n\n        :param greeting: Greeting to display\n        :param count: Number of times to display the greeting\n        \"\"\"\n        for _ in range(count):\n            print(greeting)\n\n    # ... or document parameter types in the docstring:\n    def main(greeting, *, count=1):\n        \"\"\"\n        Display a friendly greeting.\n\n        :param str greeting: Greeting to display\n        :param int count: Number of times to display the greeting\n        \"\"\"\n        for _ in range(count):\n            print(greeting)\n\n    if __name__ == '__main__':\n        defopt.run(main)\n\nDescriptions of the parameters and the function itself are used to build an\ninformative help message.\n\n::\n\n    $ python test.py -h\n    usage: test.py [-h] [-c COUNT] greeting\n\n    Display a friendly greeting.\n\n    positional arguments:\n      greeting              Greeting to display\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      -c COUNT, --count COUNT\n                            Number of times to display the greeting\n                            (default: 1)\n\nYour function can now be called identically from Python and the command line.\n\n::\n\n    >>> from test import main\n    >>> main('hello!', count=2)\n    hello!\n    hello!\n\n::\n\n    $ python test.py hello! --count 2\n    hello!\n    hello!\n\nPhilosopy\n---------\n\ndefopt was developed with the following guiding principles in mind:\n\n#. **The interface can be fully understood in seconds.** If it took any longer,\n   your time would be better spent learning a more flexible tool.\n\n#. **Anything you learn applies to the existing ecosystem.** The exact same\n   docstrings used by defopt are also used by Sphinx's autodoc_ extension to\n   generate documentation, and by your IDE to do type checking. Chances are you\n   already know everything you need to know to use defopt.\n\n#. **Everything is handled for you.** If you're using defopt, it's because you\n   don't want to write any argument parsing code *at all*. You can trust it to\n   build a logically consistent command line interface to your functions\n   with no configuration required.\n\n#. **Your Python functions are never modified.** Type conversions are only ever\n   applied to data originating from the command line. When used in code,\n   duck-typing still works exactly as you expect with no surprises.\n\nDevelopment\n-----------\n\nFor source code, examples, questions, feature requests and bug reports, visit\nthe `GitHub repository`_.\n\nDocumentation\n-------------\n\nDocumentation is hosted on `Read the Docs`_.\n\n.. _GitHub repository: https://github.com/anntzer/defopt\n.. _Read the Docs: https://defopt.readthedocs.io/en/latest/\n.. _autodoc: http://www.sphinx-doc.org/en/stable/ext/autodoc.html\n.. _docopt: http://docopt.org/\n.. _click: http://click.palletsprojects.com/\n.. _argh: https://argh.readthedocs.io/en/latest/\n.. _documented: https://defopt.readthedocs.io/en/latest/features.html#docstring-styles\n\n.. This document is included in docs/index.rst; table of contents appears here.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Effortless argument parser",
    "version": "6.4.0",
    "split_keywords": [
        "argument",
        "parser",
        "parsing",
        "optparse",
        "argparse",
        "getopt",
        "docopt",
        "sphinx"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cc3f3baf4e6fed12dac76c0ccb4716fd4235ef0aa5b48f66aab6f970afc7b44e",
                "md5": "30905cb7a99af7272e7ebfdd5cd15ad4",
                "sha256": "359a56137b4b7dcbc051d2157e6591a09c35c4297cfc00f1ef8dbcd192d19a34"
            },
            "downloads": -1,
            "filename": "defopt-6.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "30905cb7a99af7272e7ebfdd5cd15ad4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 42257,
            "upload_time": "2022-07-19T17:16:40",
            "upload_time_iso_8601": "2022-07-19T17:16:40.093199Z",
            "url": "https://files.pythonhosted.org/packages/cc/3f/3baf4e6fed12dac76c0ccb4716fd4235ef0aa5b48f66aab6f970afc7b44e/defopt-6.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-07-19 17:16:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "anntzer",
    "github_project": "defopt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "defopt"
}
        
Elapsed time: 0.08575s