# streamlitfront
Generate streamlit frontends from python functions
To install: ```pip install streamlitfront```
# Example
Define functions in a file named ``render_functions.py``:
```python
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):
```python
from streamlitfront import mk_app
if __name__ == '__main__':
app = mk_app(funcs)
app()
```
Execute `streamlit run render_functions.py` in terminal and ...



... 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:
```python
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 ...

... the application name changed!
- obj
You can define a wrapper to transform the initial object into an output of your choice to be rendered:
```python
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 ...

... 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:
```python
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 ...

... the input ``a`` is a slider now !
Obviously, you can combine the three types of configuration:
```python
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 ...

... 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.
```python
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 ...

... the convention is applied !
# Old Example (using deprecated ``dispatch_funcs`` function)
Write a module like this:
```python
# 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 ...


Raw data
{
"_id": null,
"home_page": "https://github.com/i2mint/streamlitfront",
"name": "streamlitfront",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "OtoSense",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/f3/5d/a57ed9a691eb62a585a7d72ac15ff7750fd414edd95370667d16b7babf1d/streamlitfront-0.1.33.tar.gz",
"platform": "any",
"description": "\n# streamlitfront\nGenerate streamlit frontends from python functions\n\n\nTo install:\t```pip install streamlitfront```\n\n\n# Example\n\nDefine functions in a file named ``render_functions.py``:\n\n```python\ndef foo(a: int = 1, b: int = 2, c=3):\n \"\"\"This is foo. It computes something\"\"\"\n return (a * b) + c\n\n\ndef bar(x, greeting=\"hello\"):\n \"\"\"bar greets its input\"\"\"\n return f\"{greeting} {x}\"\n\n\ndef confuser(a: int, x: float = 3.14):\n return (a ** 2) * x\n\n\nfuncs = [foo, bar, confuser]\n```\n\nThen add the following to the file (we will be modifying this part):\n\n```python\nfrom streamlitfront import mk_app\n\nif __name__ == '__main__':\n app = mk_app(funcs)\n app()\n```\n\nExecute `streamlit run render_functions.py` in terminal and ...\n\n\n\n\n\n\n\n... you can play with your functions!\n\n## Configuration\n\nThe 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.\n\n- app\n\n By default, the application name is \"My Front Application\", but you can set the title of the application as follow:\n\n ```python\n from streamlitfront import mk_app\n \n\n if __name__ == '__main__':\n config = {\n 'app': {\n 'title': 'Another application name'\n }\n }\n app = mk_app(funcs, config=config)\n app()\n ```\n\n Execute `streamlit run render_functions.py` in terminal and ...\n\n \n\n ... the application name changed!\n\n- obj\n\n You can define a wrapper to transform the initial object into an output of your choice to be rendered:\n \n ```python\n from typing import Iterable\n from streamlitfront import mk_app\n \n\n def trans(objs: Iterable):\n return list(reversed(objs))\n \n\n if __name__ == '__main__':\n config = {\n 'obj': {\n 'trans': trans\n }\n }\n app = mk_app(funcs, config=config)\n app()\n ```\n\n Execute `streamlit run render_functions.py` in terminal and ...\n \n \n\n ... the view order has changed !\n\n Note that the capital letter at the beginning of the view names are gone, because the default transforming is no longer applied.\n\n- rendering\n\n You can define the way elements are rendered in the GUI.\n For instance, you can choose to render a text input instead of a number input for a specific parameter of a specific function:\n \n ```python\n from front.elements import INT_INPUT_SLIDER_COMPONENT\n from streamlitfront import mk_app\n \n\n if __name__ == '__main__':\n config = {\n 'rendering': {\n 'Foo': {\n 'inputs': {\n 'a': {\n 'component': INT_INPUT_SLIDER_COMPONENT,\n 'max_value': 10\n }\n }\n }\n }\n }\n app = mk_app(funcs, config=config)\n app()\n ```\n\n Execute `streamlit run render_functions.py` in terminal and ...\n\n \n\n ... the input ``a`` is a slider now !\n \nObviously, you can combine the three types of configuration:\n \n```python\nfrom typing import Iterable\nfrom front.elements import INT_INPUT_SLIDER_COMPONENT\nfrom streamlitfront import mk_app\n \n\ndef trans(objs: Iterable):\n return list(reversed(objs))\n\n\nif __name__ == '__main__':\n config = {\n 'app': {\n 'title': 'Another application name'\n },\n 'obj': {\n 'trans': trans\n },\n 'rendering': {\n 'foo': {\n 'inputs': {\n 'a': {\n 'component': INT_INPUT_SLIDER_COMPONENT,\n 'max_value': 10\n }\n }\n }\n }\n }\n app = mk_app(funcs, config=config)\n app()\n```\n\nExecute `streamlit run render_functions.py` in terminal and ...\n\n\n\n... all three configurations are applied !\n\nYou 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.\n \n```python\nfrom typing import Any, Callable, Iterable\nfrom front.elements import VIEW_CONTAINER, FLOAT_INPUT_SLIDER_COMPONENT, TEXT_INPUT_COMPONENT\nfrom streamlitfront import mk_app\n \n\ndef trans(objs: Iterable):\n return list(reversed(objs))\n\n\nif __name__ == '__main__':\n convention = {\n 'app': {\n 'title': 'Another application name'\n },\n 'obj': {\n 'trans': trans\n },\n 'rendering': {\n Callable: {\n 'container': VIEW_CONTAINER,\n 'inputs': {\n float: {\n 'component': FLOAT_INPUT_SLIDER_COMPONENT,\n 'max_value': 10.0,\n 'format': '%.2f',\n 'step': 0.01,\n },\n Any: {\n 'component': TEXT_INPUT_COMPONENT,\n },\n },\n },\n },\n }\n app = mk_app(funcs, convention=convention)\n app()\n```\n\nExecute `streamlit run render_functions.py` in terminal and ...\n\n\n\n... the convention is applied !\n\n# Old Example (using deprecated ``dispatch_funcs`` function)\n\nWrite a module like this:\n\n```python\n# simple.py\n\ndef foo(a: int = 0, b: int = 0, c=0):\n \"\"\"This is foo. It computes something\"\"\"\n return (a * b) + c\n\ndef bar(x, greeting='hello'):\n \"\"\"bar greets its input\"\"\"\n return f'{greeting} {x}'\n\ndef confuser(a: int = 0, x: float = 3.14):\n return (a ** 2) * x\n\nfuncs = [foo, bar, confuser]\n\nif __name__ == '__main__':\n from streamlitfront import dispatch_funcs\n app = dispatch_funcs(funcs)\n app()\n \n # ... and you get a browser based app that exposes foo, bar, and confuser\n\n```\n\nExecute `streamlit run simple.py` in terminal and ...\n\n\n\n\n",
"bugtrack_url": null,
"license": "apache-2.0",
"summary": "Generate streamlit frontends from python functions",
"version": "0.1.33",
"project_urls": {
"Homepage": "https://github.com/i2mint/streamlitfront"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f35da57ed9a691eb62a585a7d72ac15ff7750fd414edd95370667d16b7babf1d",
"md5": "47607186268f90c66c00e977d693813f",
"sha256": "65ffbacb651fc3210b4128dc7d9b8615cb29ce00cbb1fbcc95765b8cf209d881"
},
"downloads": -1,
"filename": "streamlitfront-0.1.33.tar.gz",
"has_sig": false,
"md5_digest": "47607186268f90c66c00e977d693813f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 49310,
"upload_time": "2024-05-30T11:44:29",
"upload_time_iso_8601": "2024-05-30T11:44:29.665549Z",
"url": "https://files.pythonhosted.org/packages/f3/5d/a57ed9a691eb62a585a7d72ac15ff7750fd414edd95370667d16b7babf1d/streamlitfront-0.1.33.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-30 11:44:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "i2mint",
"github_project": "streamlitfront",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "streamlitfront"
}