Skip to main content

streamlitfront

Generate streamlit frontends from python functions

To install: pip install streamlitfront

Example

Define functions in a file named render_functions.py:

def foo(a: int = 1, b: int = 2, c=3):
    """This is foo. It computes something"""
    return (a * b) + c


def bar(x, greeting="hello"):
    """bar greets its input"""
    return f"{greeting} {x}"


def confuser(a: int, x: float = 3.14):
    return (a**2) * x


funcs = [foo, bar, confuser]

Then add the following to the file (we will be modifying this part):

from streamlitfront import mk_app

if __name__ == "__main__":
    app = mk_app(funcs)
    app()

Execute streamlit run render_functions.py in terminal and ...

image

image

image

... you can play with your functions!

Configuration

The default configuration for the application is define by the convention object: dflt_convention. But you can overwrite parts or the entire configuration by setting the config parameter. The configuration is composed of three parts: app, obj and rendering.

  • app

    By default, the application name is "My Front Application", but you can set the title of the application as follow:

    from streamlitfront import mk_app
    
    
    if __name__ == "__main__":
        config = {"app": {"title": "Another application name"}}
        app = mk_app(funcs, config=config)
        app()
    

    Execute streamlit run render_functions.py in terminal and ...

    image

    ... the application name changed!

  • obj

    You can define a wrapper to transform the initial object into an output of your choice to be rendered:

    from typing import Iterable
    from streamlitfront import mk_app
    
    
    def trans(objs: Iterable):
        return list(reversed(objs))
    
    
    if __name__ == "__main__":
        config = {"obj": {"trans": trans}}
        app = mk_app(funcs, config=config)
        app()
    

    Execute streamlit run render_functions.py in terminal and ...

    image

    ... the view order has changed !

    Note that the capital letter at the beginning of the view names are gone, because the default transforming is no longer applied.

  • rendering

    You can define the way elements are rendered in the GUI. For instance, you can choose to render a text input instead of a number input for a specific parameter of a specific function:

    from front.elements import INT_INPUT_SLIDER_COMPONENT
    from streamlitfront import mk_app
    
    
    if __name__ == "__main__":
        config = {
            "rendering": {
                "Foo": {
                    "inputs": {
                        "a": {"component": INT_INPUT_SLIDER_COMPONENT, "max_value": 10}
                    }
                }
            }
        }
        app = mk_app(funcs, config=config)
        app()
    

    Execute streamlit run render_functions.py in terminal and ...

    image

    ... the input a is a slider now !

Obviously, you can combine the three types of configuration:

from typing import Iterable
from front.elements import INT_INPUT_SLIDER_COMPONENT
from streamlitfront import mk_app


def trans(objs: Iterable):
    return list(reversed(objs))


if __name__ == "__main__":
    config = {
        "app": {"title": "Another application name"},
        "obj": {"trans": trans},
        "rendering": {
            "foo": {
                "inputs": {
                    "a": {"component": INT_INPUT_SLIDER_COMPONENT, "max_value": 10}
                }
            }
        },
    }
    app = mk_app(funcs, config=config)
    app()

Execute streamlit run render_functions.py in terminal and ...

image

... all three configurations are applied !

You can also overwrite the whole configuration by setting the convention parameter. Be careful though, by overwritting the default convention, you have to make sure that all configuations are defined. Otherwise, the application would crash or behave unexpectedly.

from typing import Any, Callable, Iterable
from front.elements import (
    VIEW_CONTAINER,
    FLOAT_INPUT_SLIDER_COMPONENT,
    TEXT_INPUT_COMPONENT,
)
from streamlitfront import mk_app


def trans(objs: Iterable):
    return list(reversed(objs))


if __name__ == "__main__":
    convention = {
        "app": {"title": "Another application name"},
        "obj": {"trans": trans},
        "rendering": {
            Callable: {
                "container": VIEW_CONTAINER,
                "inputs": {
                    float: {
                        "component": FLOAT_INPUT_SLIDER_COMPONENT,
                        "max_value": 10.0,
                        "format": "%.2f",
                        "step": 0.01,
                    },
                    Any: {
                        "component": TEXT_INPUT_COMPONENT,
                    },
                },
            },
        },
    }
    app = mk_app(funcs, convention=convention)
    app()

Execute streamlit run render_functions.py in terminal and ...

image

... the convention is applied !

Old Example (using deprecated dispatch_funcs function)

Write a module like this:

# simple.py


def foo(a: int = 0, b: int = 0, c=0):
    """This is foo. It computes something"""
    return (a * b) + c


def bar(x, greeting="hello"):
    """bar greets its input"""
    return f"{greeting} {x}"


def confuser(a: int = 0, x: float = 3.14):
    return (a**2) * x


funcs = [foo, bar, confuser]

if __name__ == "__main__":
    from streamlitfront import dispatch_funcs

    app = dispatch_funcs(funcs)
    app()

    # ... and you get a browser based app that exposes foo, bar, and confuser

Execute streamlit run simple.py in terminal and ...

image

image

Metadata

Release files for streamlitfront 0.1.42

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamlitfront 0.1.42
File Size Uploaded
streamlitfront-0.1.42.tar.gz 1.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlitfront 0.1.42
File Interpreter ABI Platform
streamlitfront-0.1.42-py3-none-any.whl Python 3 none any Details

Total release size: 2.5 MB

Release files / streamlitfront-0.1.42.tar.gz

Download URL streamlitfront-0.1.42.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
1a2783a4839faeecf38bf7111b3d67815eac55e9dd2b6ea8ec0765b18533ea39
BLAKE2b-256 checksum
How to use checksums
a8fe2f4f901594e50e308adcb6a9675cecf7dc9b0c0b723b524d9bf9f2ac7b4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / streamlitfront-0.1.42-py3-none-any.whl

Download URL streamlitfront-0.1.42-py3-none-any.whl
Size 1.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
1650905ae75bbb899e93f442b3ba915212e8420cf0f90436b7bc9705e435b156
BLAKE2b-256 checksum
How to use checksums
1a6e68801478fd67b6c16b616c51864bd0a9480c60bd350acd813a757d2430d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.1.46

2 release files

0.1.45

2 release files

0.1.44

2 release files

0.1.43

2 release files

This release

0.1.42 This release

2 release files

0.1.41

2 release files

0.1.40

2 release files

0.1.39

2 release files

0.1.38

2 release files

0.1.37

2 release files

0.1.36

1 release file

0.1.35

1 release file

0.1.34

1 release file

0.1.33

1 release file

0.1.32

1 release file

0.1.31

1 release file

0.1.30

1 release file

0.1.29

1 release file

0.1.28

1 release file

0.1.27

1 release file

0.1.26

1 release file

0.1.25

1 release file

0.1.24

1 release file

0.1.23

1 release file

0.1.22

1 release file

0.1.21

1 release file

0.1.20

1 release file

0.1.19

1 release file

0.1.18

1 release file

0.1.17

1 release file

0.1.16

1 release file

0.1.15

1 release file

0.1.14

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page