Generating interfaces(CLI, Qt GUI, Dash web app) from a Python function.

Overview

oneFace is a Python library for automatically generating multiple interfaces(CLI, GUI, WebGUI) from a callable Python object.

Build Status codecov Documentation Install with PyPi

oneFace is an easy way to create interfaces in Python, just decorate your function and mark the type and range of the arguments:

from oneface import one, Arg

@one
def bmi(name: Arg(str),
        height: Arg(float, [100, 250]) = 160,
        weight: Arg(float, [0, 300]) = 50.0):
    BMI = weight / (height / 100) ** 2
    print(f"Hi {name}. Your BMI is: {BMI}")
    return BMI


# run cli
bmi.cli()
# or run qt_gui
bmi.qt_gui()
# or run dash web app
bmi.dash_app()

These code will generate the following interfaces:

CLI Qt Dash
CLI Qt Dash

Features

  • Generate CLI, Qt GUI, Dash Web app from a python function.
  • Automatically check the type and range of input parameters and pretty print them.
  • Easy extension of parameter types and GUI widgets.

Detail usage see the documentation and pythondig.

Installation

To install oneFace with complete dependency:

$ pip install oneface[all]

Or install with just qt or dash dependency:

$ pip install oneface[qt]  # qt
$ pip install oneface[dash]  # dash
Comments
  • Wrap CLI

    Wrap CLI

    Wrap a CLI program to a GUI/Web interface app.

    Using a .yaml as config to specify the arguments:

    # open_browser_oneface.yaml
    name: open_browser
    
    command: python -m webbrowser {is_tab} {url} 
    
    arguments:
    
      is_tab:
        type: bool
        true_content: "-t"
        false_content: ""
    
      url:
        type: str
    

    Launch the app with:

    $ python -m onface.wrap_cli run open_browser_oneface.yaml qt_gui
    

    It will get a GUI app.

    enhancement 
    opened by Nanguage 1
  • A Thanks Message

    A Thanks Message

    Hello, i am Onur, i am a CTO of a community that develop Blockchain based Decentralized Application Network. This repository have a very good idea. All contributor of this project and me should develop this project and use in the other project. Let's not stop developing.

    Onur Atakan ULUSOY - CTO of Decentra Network Community

    opened by onuratakan 1
  • Implicit Arg convert from Python builtin types

    Implicit Arg convert from Python builtin types

    Allow type annotation with python builtin types, for example:

    from oneface import one, Arg
    
    @one
    def bmi(name: str,
            height: (float, [100, 250]) = 160,
            weight: (float, [0, 300]) = 50.0):
        BMI = weight / (height / 100) ** 2
        print(f"Hi {name}. Your BMI is: {BMI}")
        return BMI
    
    # run cli
    bmi.cli()
    

    Let the annotation automatically convert to Arg when parse the parameters.

    enhancement 
    opened by Nanguage 1
  • Integrate generated qt window to a Qt app.

    Integrate generated qt window to a Qt app.

    import sys
    from oneface.qt import qt_window
    from oneface import one
    from qtpy import QtWidgets
    
    app = QtWidgets.QApplication([])
    
    
    @qt_window
    @one
    def add(a: int, b: int):
        return a + b
    
    @qt_window
    @one
    def mul(a: int, b: int):
        return a * b
    
    
    main_window = QtWidgets.QWidget()
    main_window.setWindowTitle("MyApp")
    main_window.setFixedSize(200, 100)
    layout = QtWidgets.QVBoxLayout(main_window)
    layout.addWidget(QtWidgets.QLabel("Apps:"))
    btn_open_add = QtWidgets.QPushButton("add")
    btn_open_mul = QtWidgets.QPushButton("mul")
    btn_open_add.clicked.connect(add.show)
    btn_open_mul.clicked.connect(mul.show)
    layout.addWidget(btn_open_add)
    layout.addWidget(btn_open_mul)
    main_window.show()
    
    sys.exit(app.exec())
    
    enhancement 
    opened by Nanguage 0
  • Dash: the 'plotly' result_result_type

    Dash: the 'plotly' result_result_type

    Allow render the result with ploty. The wraped function return a plotly figure object:

    from oneface import one, Arg
    import plotly.express as px
    import numpy as np
    
    @one
    def draw_random_points(n: Arg[int, [1, 10000]] = 100):
        x, y = np.random.random(n), np.random.random(n)
        fig = px.scatter(x=x, y=y)
        return fig
    
    draw_random_points.dash_app(
        result_show_type='plotly',
        debug=True)
    
    enhancement 
    opened by Nanguage 0
  • Flask integration of dash app

    Flask integration of dash app

    Embeding the generated dash app as a route of flask server.

    # demo_flask_integrate.py
    from flask import Flask
    from oneface.dash_app import flask_route
    from oneface.core import one
    
    server = Flask("test_dash_app")
    
    @flask_route(server, "/add")
    @one
    def add(a: int, b: int) -> int:
        return a + b
    
    @flask_route(server, "/mul")
    @one
    def mul(a: int, b: int) -> int:
        return a * b
    
    server.run("127.0.0.1", 8088)
    

    Run this will launch a flask server support run multiple dash app from different route.

    References:

    • https://blog.finxter.com/dash-flask/
    enhancement 
    opened by Nanguage 0
  • Define custom dash commpont to support complex input type.

    Define custom dash commpont to support complex input type.

    For example:

    from oneface import one, Arg
    from oneface.dash_app import App, InputItem
    from dash import dcc, html
    
    class Person:
        def __init__(self, name, age):
            self.name = name
            self.age = age
    
    
    def check_person_type(val, tp):
        return (
            isinstance(val, tp) and
            isinstance(val.name, str) and
            isinstance(val.age, int)
        )
    
    Arg.register_type_check(Person, check_person_type)
    Arg.register_range_check(Person, lambda val, range: range[0] <= val.age <= range[1])
    
    class PersonInputItem(InputItem):
        def get_input(self):
            if self.default:
                default_val = f"Person('{self.default.name}', {self.default.age})"
            else:
                default_val = ""
            return dcc.Input(
                placeholder="example: Person('age', 20)",
                type="text",
                value=default_val,
                style={
                    "width": "100%",
                    "height": "40px",
                    "margin": "5px",
                    "font-size": "20px",
                }
            )
    
    
    App.register_widget(Person, PersonInputItem)
    App.register_type_convert(Person, lambda s: eval(s))
    
    
    @one
    def print_person(person: Arg(Person, [0, 100]) = Person("Tom", 10)):
        print(f"{person.name} is {person.age} years old.")
    
    
    print_person.dash_app()
    
    

    This code using the serialized input Person, how to define a "Composite components" in dash to support Person input? Just like in Qt:

    image

    question 
    opened by Nanguage 0
Releases(0.1.9)
A comprehensive tutorial for plotting focal mechanism

Focal_Mechanisms_Demo A comprehensive tutorial for plotting focal mechanism "beach-balls" using the PyGMT package for Python. (Resulting map of this d

3 Dec 13, 2022
This GitHub Repository contains Data Analysis projects that I have completed so far! While most of th project are focused on Data Analysis, some of them are also put here to show off other skills that I have learned.

Welcome to my Data Analysis projects page! This GitHub Repository contains Data Analysis projects that I have completed so far! While most of th proje

Kyle Dini 1 Jan 31, 2022
Script to create an animated data visualisation for categorical timeseries data - GIF choropleth map with annotations.

choropleth_ldn Simple script to create a chloropleth map of London with categorical timeseries data. The script in main.py creates a gif of the most f

1 Oct 07, 2021
DataVisualization - The evolution of my arduino and python journey. New level of competence achieved

DataVisualization - The evolution of my arduino and python journey. New level of competence achieved

1 Jan 03, 2022
flask extension for integration with the awesome pydantic package

Flask-Pydantic Flask extension for integration of the awesome pydantic package with Flask. Installation python3 -m pip install Flask-Pydantic Basics v

249 Jan 06, 2023
ecoglib: visualization and statistics for high density microecog signals

ecoglib: visualization and statistics for high density microecog signals This library contains high-level analysis tools for "topos" and "chronos" asp

1 Nov 17, 2021
An interactive GUI for WhiteboxTools in a Jupyter-based environment

whiteboxgui An interactive GUI for WhiteboxTools in a Jupyter-based environment GitHub repo: https://github.com/giswqs/whiteboxgui Documentation: http

Qiusheng Wu 105 Dec 15, 2022
Plot-configurations for scientific publications, purely based on matplotlib

TUEplots Plot-configurations for scientific publications, purely based on matplotlib. Usage Please have a look at the examples in the example/ directo

Nicholas Krämer 487 Jan 08, 2023
A Jupyter - Leaflet.js bridge

ipyleaflet A Jupyter / Leaflet bridge enabling interactive maps in the Jupyter notebook. Usage Selecting a basemap for a leaflet map: Loading a geojso

Jupyter Widgets 1.3k Dec 27, 2022
A Python library for plotting hockey rinks with Matplotlib.

Hockey Rink A Python library for plotting hockey rinks with Matplotlib. Installation pip install hockey_rink Current Rinks The following shows the cus

24 Jan 02, 2023
Graphing communities on Twitch.tv in a visually intuitive way

VisualizingTwitchCommunities This project maps communities of streamers on Twitch.tv based on shared viewership. The data is collected from the Twitch

Kiran Gershenfeld 312 Jan 07, 2023
A flexible tool for creating, organizing, and sharing visualizations of live, rich data. Supports Torch and Numpy.

Visdom A flexible tool for creating, organizing, and sharing visualizations of live, rich data. Supports Python. Overview Concepts Setup Usage API To

FOSSASIA 9.4k Jan 07, 2023
Data Visualizer Web-Application

Viz-It Data Visualizer Web-Application If I ask you where most of the data wrangler looses their time ? It is Data Overview and EDA. Presenting "Viz-I

Sagnik Roy 17 Nov 20, 2022
Some useful extensions for Matplotlib.

mplx Some useful extensions for Matplotlib. Contour plots for functions with discontinuities plt.contour mplx.contour(max_jump=1.0) Matplotlib has pro

Nico Schlömer 519 Dec 30, 2022
A small collection of tools made by me, that you can use to visualize atomic orbitals in both 2D and 3D in different aspects.

Orbitals in Python A small collection of tools made by me, that you can use to visualize atomic orbitals in both 2D and 3D in different aspects, and o

Prakrisht Dahiya 1 Nov 25, 2021
A minimal Python package that produces slice plots through h5m DAGMC geometry files

A minimal Python package that produces slice plots through h5m DAGMC geometry files Installation pip install dagmc_geometry_slice_plotter Python API U

Fusion Energy 4 Dec 02, 2022
A Bokeh project developed for learning and teaching Bokeh interactive plotting!

Bokeh-Python-Visualization A Bokeh project developed for learning and teaching Bokeh interactive plotting! See my medium blog posts about making bokeh

Will Koehrsen 350 Dec 05, 2022
Python package to Create, Read, Write, Edit, and Visualize GSFLOW models

pygsflow pyGSFLOW is a python package to Create, Read, Write, Edit, and Visualize GSFLOW models API Documentation pyGSFLOW API documentation can be fo

pyGSFLOW 21 Dec 14, 2022
A Graph Learning library for Humans

A Graph Learning library for Humans These novel algorithms include but are not limited to: A graph construction and graph searching class can be found

Richard Tjörnhammar 1 Feb 08, 2022
CompleX Group Interactions (XGI) provides an ecosystem for the analysis and representation of complex systems with group interactions.

XGI CompleX Group Interactions (XGI) is a Python package for the representation, manipulation, and study of the structure, dynamics, and functions of

Complex Group Interactions 67 Dec 28, 2022