parsable


Nameparsable JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/fritzo/parsable
SummaryLightweight argument parsing using a decorator
upload_time2024-02-19 17:29:54
maintainer
docs_urlNone
authorFritz Obermeyer
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            Parsable
========

.. image:: https://github.com/fritzo/parsable/workflows/Python%20CI/badge.svg
   :target: https://github.com/fritzo/parsable/actions
   :alt: Build status

.. image:: https://badge.fury.io/py/parsable.svg
   :target: https://pypi.python.org/pypi/parsable
   :alt: PyPI Version
   
.. image:: https://anaconda.org/fritzo/parsable/badges/version.svg
   :target: https://anaconda.org/fritzo/parsable
   :alt: Anaconda Cloud Version

Parsable is a lightweight decorator-based command line parser library.
Parsable was written to be simpler than argparse, optparse, and argh.

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

Install from `PyPI`_ with ``pip``

.. _PyPI: http://pypi.python.org/pypi/parsable

.. code-block:: bash

    pip install parsable


Or just download `parsable.py`_ and add to your project.

.. _`parsable.py`: https://raw.github.com/fritzo/parsable/master/parsable.py

Usage
-----

Parsable uses just two pieces of syntax: a ``@parsable`` command decorator,
and a ``parsable()`` dispatch function.

1.  Import parsable.

    .. code-block:: python

        from parsable import parsable

2.  Decorate functions you want parsed.
    Parsable inspects the function to decide how to parse arguments.
    Arguments without default values are parsed as strings.
    Default arguments of any type ``T`` can be parsed as long
    as ``T(some_string)`` can do the parsing.

    .. code-block:: python  

        @parsable
        def my_function(required_arg, optional_bool=True, optional_int=1):
            '''Help messages are not just a good idea, they are required'''
            # parsable automatically converts types based on default arguments:
            assert isinstance(required_arg, str)
            assert isinstance(optional_string, bool)
            assert isinstance(optional_int, int)
            # ...

        @parsable
        def do_stuff_with_files(*filenames, inplace=True):
            '''This does something to each file'''
            # ...

3.  Dispatch at the end of the script.

    .. code-block:: python  

        if __name__ == '__main__':
            parsable()

4.  Use your new script

    .. code-block:: bash

        $ python my_script.py my_function demo optional_int=5
        ...

        # parsable replaces - with _ to make functions easier to read
        $ python my_script.py do-stuff-with-files *.py inplace=false
        ...

Advanced Usage
--------------

To show verbose information (commmand name and timing info),
set the environment variable ``PARSABLE_VERBOSE=true``.

If you use parsable for many modules in a package, you can collect them in your
``setup.py`` using ``parsable.find_entry_points()``.

.. code-block:: python

    from parsable import parsable
    from setuptools import setup
    
    setup(
        name='my_package',
        entry_points=parsable.find_entry_points('my_package'),
        ...
    )

LICENSE
-------

Parsable is dual-licensed under the MIT and GPL2 licenses.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fritzo/parsable",
    "name": "parsable",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Fritz Obermeyer",
    "author_email": "fritz.obermeyer@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/95/4c/ef23c3768b9ebf4762f13682af8c6cf667b58fc7011351a6805ca2df83c6/parsable-0.3.0.tar.gz",
    "platform": null,
    "description": "Parsable\n========\n\n.. image:: https://github.com/fritzo/parsable/workflows/Python%20CI/badge.svg\n   :target: https://github.com/fritzo/parsable/actions\n   :alt: Build status\n\n.. image:: https://badge.fury.io/py/parsable.svg\n   :target: https://pypi.python.org/pypi/parsable\n   :alt: PyPI Version\n   \n.. image:: https://anaconda.org/fritzo/parsable/badges/version.svg\n   :target: https://anaconda.org/fritzo/parsable\n   :alt: Anaconda Cloud Version\n\nParsable is a lightweight decorator-based command line parser library.\nParsable was written to be simpler than argparse, optparse, and argh.\n\nInstallation\n------------\n\nInstall from `PyPI`_ with ``pip``\n\n.. _PyPI: http://pypi.python.org/pypi/parsable\n\n.. code-block:: bash\n\n    pip install parsable\n\n\nOr just download `parsable.py`_ and add to your project.\n\n.. _`parsable.py`: https://raw.github.com/fritzo/parsable/master/parsable.py\n\nUsage\n-----\n\nParsable uses just two pieces of syntax: a ``@parsable`` command decorator,\nand a ``parsable()`` dispatch function.\n\n1.  Import parsable.\n\n    .. code-block:: python\n\n        from parsable import parsable\n\n2.  Decorate functions you want parsed.\n    Parsable inspects the function to decide how to parse arguments.\n    Arguments without default values are parsed as strings.\n    Default arguments of any type ``T`` can be parsed as long\n    as ``T(some_string)`` can do the parsing.\n\n    .. code-block:: python  \n\n        @parsable\n        def my_function(required_arg, optional_bool=True, optional_int=1):\n            '''Help messages are not just a good idea, they are required'''\n            # parsable automatically converts types based on default arguments:\n            assert isinstance(required_arg, str)\n            assert isinstance(optional_string, bool)\n            assert isinstance(optional_int, int)\n            # ...\n\n        @parsable\n        def do_stuff_with_files(*filenames, inplace=True):\n            '''This does something to each file'''\n            # ...\n\n3.  Dispatch at the end of the script.\n\n    .. code-block:: python  \n\n        if __name__ == '__main__':\n            parsable()\n\n4.  Use your new script\n\n    .. code-block:: bash\n\n        $ python my_script.py my_function demo optional_int=5\n        ...\n\n        # parsable replaces - with _ to make functions easier to read\n        $ python my_script.py do-stuff-with-files *.py inplace=false\n        ...\n\nAdvanced Usage\n--------------\n\nTo show verbose information (commmand name and timing info),\nset the environment variable ``PARSABLE_VERBOSE=true``.\n\nIf you use parsable for many modules in a package, you can collect them in your\n``setup.py`` using ``parsable.find_entry_points()``.\n\n.. code-block:: python\n\n    from parsable import parsable\n    from setuptools import setup\n    \n    setup(\n        name='my_package',\n        entry_points=parsable.find_entry_points('my_package'),\n        ...\n    )\n\nLICENSE\n-------\n\nParsable is dual-licensed under the MIT and GPL2 licenses.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Lightweight argument parsing using a decorator",
    "version": "0.3.0",
    "project_urls": {
        "Homepage": "https://github.com/fritzo/parsable"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "534eff0e988b9139e2b80992a629e58e1c6977503e2346567774b8e6a8737a7d",
                "md5": "9dbb6f3a10e003367bf6bd261c4f5e14",
                "sha256": "02558b401d35dadd6cb05b170f592d705a015c741074c5eb4f0dd5c5a3b09210"
            },
            "downloads": -1,
            "filename": "parsable-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9dbb6f3a10e003367bf6bd261c4f5e14",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4522,
            "upload_time": "2024-02-19T17:29:52",
            "upload_time_iso_8601": "2024-02-19T17:29:52.893026Z",
            "url": "https://files.pythonhosted.org/packages/53/4e/ff0e988b9139e2b80992a629e58e1c6977503e2346567774b8e6a8737a7d/parsable-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "954cef23c3768b9ebf4762f13682af8c6cf667b58fc7011351a6805ca2df83c6",
                "md5": "b26ce1cb45b914c16803e1360d14ecdc",
                "sha256": "ec1e4292c0a84d98c3ca1bf99cd79ee413b8b8efbcd82d0de907e7bd78621d59"
            },
            "downloads": -1,
            "filename": "parsable-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b26ce1cb45b914c16803e1360d14ecdc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4242,
            "upload_time": "2024-02-19T17:29:54",
            "upload_time_iso_8601": "2024-02-19T17:29:54.223463Z",
            "url": "https://files.pythonhosted.org/packages/95/4c/ef23c3768b9ebf4762f13682af8c6cf667b58fc7011351a6805ca2df83c6/parsable-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-19 17:29:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fritzo",
    "github_project": "parsable",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "parsable"
}
        
Elapsed time: 0.42556s