ox-ui


Nameox-ui JSON
Version 0.3.9 PyPI version JSON
download
home_pagehttp://github.com/emin63/ox_ui
SummarySimple user interface tools for python
upload_time2024-07-17 21:18:49
maintainerNone
docs_urlNone
authorEmin Martinian
requires_pythonNone
licensecustom
keywords flask click ui
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Introduction
============

The ``ox_ui`` package provides tools for writing user interfaces.

For example, ``ox_ui`` lets you take a command defined using the
``click`` library and convert it to something you can run in a Flask web
server as discussed in the `Click to WTForms <#click-to-wtforms>`__
section.

Click to WTForms
================

The ``ox_ui`` package can convert a ``click`` command into a flask route
using the ``WTForms`` library. This can be convenient both so that you
have a command line interface (CLI) for your functions in addition to a
web interface and also because sometimes it is quicker and easier to
define the CLI interface and auto-generate the web interface.

Imagine you define a function called ``hello_cmd`` via something like:

.. code:: python

   @click.command()
   @click.option('--count', default=1, type=int, help='how many times to say it')
   @click.option('--text', default='hi', type=str, help='what to say')
   def hello_cmd(count, text):
       'say hello'

       result = []
       for i in range(count):
           result.append(text)

       return '\n'.join(result)

You can import ``c2f`` from ``ox_ui.core`` and use it to convert your
``hello_cmd`` into a flask route via something like:

.. code:: python

   from flask import Flask
   from ox_ui.core import c2f

   APP = Flask(__name__)

   @APP.route('/hello', methods=('GET', 'POST'))
   def hello():
       fcmd = c2f.ClickToWTF(hello_cmd)
       result = fcmd.handle_request()
       return result

Once you start your flask web server, you will then have a route that
introspects ``hello_cmd``, creates a web form using the ``WTForms``
library and handles the command.

See examples in the ``tests`` directory for more details.

Other Utilities
===============

A few additional utilites are provided in the
``ox_ui/core/decorators.py`` module including a ``watched`` decorator to
log the start/end of functions, a ``setup_flask_watch`` function which
applies the ``watched`` decorator to allow your routes using the
``before_request`` and ``teardown_request`` hooks in flask, and a
``LockFile`` context decorator for easily adding lock files to any
function or context.
            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/emin63/ox_ui",
    "name": "ox-ui",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "flask click ui",
    "author": "Emin Martinian",
    "author_email": "emin.martinian@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/95/94/e6e03eabcd35f648c49e3d4d574c470f2161d3e3ef960cfad960452e3b70/ox_ui-0.3.9.tar.gz",
    "platform": null,
    "description": "Introduction\n============\n\nThe ``ox_ui`` package provides tools for writing user interfaces.\n\nFor example, ``ox_ui`` lets you take a command defined using the\n``click`` library and convert it to something you can run in a Flask web\nserver as discussed in the `Click to WTForms <#click-to-wtforms>`__\nsection.\n\nClick to WTForms\n================\n\nThe ``ox_ui`` package can convert a ``click`` command into a flask route\nusing the ``WTForms`` library. This can be convenient both so that you\nhave a command line interface (CLI) for your functions in addition to a\nweb interface and also because sometimes it is quicker and easier to\ndefine the CLI interface and auto-generate the web interface.\n\nImagine you define a function called ``hello_cmd`` via something like:\n\n.. code:: python\n\n   @click.command()\n   @click.option('--count', default=1, type=int, help='how many times to say it')\n   @click.option('--text', default='hi', type=str, help='what to say')\n   def hello_cmd(count, text):\n       'say hello'\n\n       result = []\n       for i in range(count):\n           result.append(text)\n\n       return '\\n'.join(result)\n\nYou can import ``c2f`` from ``ox_ui.core`` and use it to convert your\n``hello_cmd`` into a flask route via something like:\n\n.. code:: python\n\n   from flask import Flask\n   from ox_ui.core import c2f\n\n   APP = Flask(__name__)\n\n   @APP.route('/hello', methods=('GET', 'POST'))\n   def hello():\n       fcmd = c2f.ClickToWTF(hello_cmd)\n       result = fcmd.handle_request()\n       return result\n\nOnce you start your flask web server, you will then have a route that\nintrospects ``hello_cmd``, creates a web form using the ``WTForms``\nlibrary and handles the command.\n\nSee examples in the ``tests`` directory for more details.\n\nOther Utilities\n===============\n\nA few additional utilites are provided in the\n``ox_ui/core/decorators.py`` module including a ``watched`` decorator to\nlog the start/end of functions, a ``setup_flask_watch`` function which\napplies the ``watched`` decorator to allow your routes using the\n``before_request`` and ``teardown_request`` hooks in flask, and a\n``LockFile`` context decorator for easily adding lock files to any\nfunction or context.",
    "bugtrack_url": null,
    "license": "custom",
    "summary": "Simple user interface tools for python",
    "version": "0.3.9",
    "project_urls": {
        "Homepage": "http://github.com/emin63/ox_ui"
    },
    "split_keywords": [
        "flask",
        "click",
        "ui"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9594e6e03eabcd35f648c49e3d4d574c470f2161d3e3ef960cfad960452e3b70",
                "md5": "98f47faa320427a11a2300cdfa487647",
                "sha256": "ec7693949e08205e549ee15b2e7e55871b8e07b51f40f1ebf09b4cb016052284"
            },
            "downloads": -1,
            "filename": "ox_ui-0.3.9.tar.gz",
            "has_sig": false,
            "md5_digest": "98f47faa320427a11a2300cdfa487647",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 21885,
            "upload_time": "2024-07-17T21:18:49",
            "upload_time_iso_8601": "2024-07-17T21:18:49.765150Z",
            "url": "https://files.pythonhosted.org/packages/95/94/e6e03eabcd35f648c49e3d4d574c470f2161d3e3ef960cfad960452e3b70/ox_ui-0.3.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-17 21:18:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "emin63",
    "github_project": "ox_ui",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "ox-ui"
}
        
Elapsed time: 4.66156s