Skip to main content

YAML2ST automates streamlit input widgets from a YAML.

Project description

YAML 2 STREAMLIT

Description

YAML2ST automates streamlit input widgets from an uploaded YAML or JSON file. All key value pairs will be displayed as streamlit input widgets. You can then export the data changes via YAML or share a URL that contains the YAML file.

Use: As A Package

To Install

In a python environment:

pip install YAML2ST

To Import

In a python file:

import streamlit as st
import YAML2ST as y2s

To Display YAML/JSON as Input Widgets

Use an UploadedFile type, e.g. a file from st.file_uploader(), and the Streamlit instance in the location you would like the input widgets displayed, e.g. st.sidebar, with the YAML2ST build() method:

df = y2s.build(uploadedFile, st.sidebar)
build() will return a pandas DataFrame in which you can capture and display all input widget changes.

To Export Data: Easy

To export with ease, use: the original UploadedFile, the changes made in the DataFrame, an instance of Streamlit for where you want the export features drawn, and the domain of the URL that we can add a parameter to.

y2s.export(uploadedFile, df, st.sidebar, "http://localhost:9097/")
export() will draw 2 widgets at the Streamlit instance, a download button and a code box with the share link.

To Export Data: Raw

If you do not want these widgets drawn on Streamlit, you can use exportRaw() to capture the data:

file, file_name, sharelink = exportRaw(uploadedFile, df, URL)

Use: Demo File (GitHub)

The demo file dubbed main().py is on GitHub.

To Run

streamlit run app/main.py --server.port 9097
Upload a YAML file.

YAML & Dynamics

YAML2ST Dynamics

The Streamlit input widgets are dynamically manifested using the following conditional order.

Widget Value Input
checkbox Any value that is 'True' or 'False'
number_input (integer) Any value that can be cast to an int. Step defaults to +1/-1.
number_input (decimal) Any value that can be cast to a float. Step defaults to the smallest digit in the value.
date_input Any value that is ISO-8601 standard. E.g.: "2010-02-11"
datetime_input A YAML2ST custom widget to support date and time. E.g.: "2015-06-17 14:03:40"
color_picker Any value that matches hexadecimal with #. E.g.: "#0EE2D7"
text_area Any value that contains a new line \n
multiselect Any value that is a list e.g. starts with [
text_input All other data

Example YAML

Example 1:

int: 1
YAML2ST will decide that the best way to display this will be with a Streamlit "number_input" and will draw a number_input with a title of "int" and a value of 1 on the Streamit instance provided.

Example 2:

string: "Dynamic"
YAML2ST will decide that the best way to display this will be with a Streamlit "text_input" and will draw a text_input with a title of "string" and a value of "Dynamic" on the Streamit instance provided.

YAML & YAML2ST #FORCE

Should you wish to display the value of the parameter with a specific input widget, we have made that easy with the use of #FORCE: next to the YAML parameter in the YAML file. You may also separate each #FORCE: option with | (including the space before and after the pipe). This capability extends to all of the Streamlit input widget options as your options are taken literally if not recognized by YAML2ST.

Application Level Options

Option Action
hide=True Will ignore the YAML parameter.
type=int Will force the data type.

Example YAML

Example 1:

int: 1 #FORCE: w=number_input | min_value=0 | max_value=10
The YAML parameter "int: 1" will be read by YAML2ST as a Streamlit number_input. However, it is best practice to declare the "number_input" Streamlit input widget if there will be literal input widget options such as "min_value" and "max_value".

Example 2:

list1: [ "one", "two", "three", "four" ] #FORCE: w=selectbox | index=2

Example 3:

block_shape5: [ "five", "three", "four"] #FORCE: w=selectbox | options=[ "six", "one", "two"] | index=2

Example 4:

hidden_param: "zero" #FORCE: hide=True

YAML Requirements

  1. The YAML key hierarchy must be unique.
    colors:
          color: Red
          color: Green
          color: Blue # this will override the breadcrumb "colors->color" so only "color: Blue" will exist
  2. No blank lines (comments are fine).
  3. For now, it only supports single line data.

Feature: Share With Link Feature

You may share a YAML file as a URL. During export() a special URL will be encoded. The domain of the URL, in the code, may need to be updated. YAML2URL uses a single URL parameter dubbed 'YAML2URL' to share all contents of a YAML, including comments and the Y2S #FORCE feature.

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

YAML2ST-1.0.22.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

YAML2ST-1.0.22-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file YAML2ST-1.0.22.tar.gz.

File metadata

  • Download URL: YAML2ST-1.0.22.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for YAML2ST-1.0.22.tar.gz
Algorithm Hash digest
SHA256 c9a50454994855249ea2070073771e3c4301b0146e929aa2313e48a8ee93b6ce
MD5 6d61c16e7701fdfccab481121759e594
BLAKE2b-256 63e0f6c5738436b445d79c35dcf5a6cfda1372f71398a1470b613df095ba40f4

See more details on using hashes here.

File details

Details for the file YAML2ST-1.0.22-py3-none-any.whl.

File metadata

  • Download URL: YAML2ST-1.0.22-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for YAML2ST-1.0.22-py3-none-any.whl
Algorithm Hash digest
SHA256 d7c170e655b2f4353eb8a553a84b6ed572e905961dfc768010f7402cce1333e6
MD5 7da8e60abae30d47a8c577faa48a011e
BLAKE2b-256 5c4eda314af1a8b6109eed71564b7c2996c297668f66e8b8b4352f45c57971c4

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