Skip to main content

Simple user interface tools for python

Project description

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 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:

@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:

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ox_ui-0.3.9.tar.gz (21.9 kB view details)

Uploaded Source

File details

Details for the file ox_ui-0.3.9.tar.gz.

File metadata

  • Download URL: ox_ui-0.3.9.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for ox_ui-0.3.9.tar.gz
Algorithm Hash digest
SHA256 ec7693949e08205e549ee15b2e7e55871b8e07b51f40f1ebf09b4cb016052284
MD5 98f47faa320427a11a2300cdfa487647
BLAKE2b-256 9594e6e03eabcd35f648c49e3d4d574c470f2161d3e3ef960cfad960452e3b70

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page