ju.rjsf¶
Tools for React-JSONSchema-Form (RJSF)
Functions
|
Prints form_data in a nicely formatted way. |
|
Factory function to create and display an RJSF viewer. |
|
Prints form_data in a nicely formatted way. |
|
Display a string in a Jupyter notebook cell. |
|
Returns a JSON object that can be used as a form specification, along with the function, to generate a FuncCaller React component in a React application. |
Classes
|
Configuration for form rendering behavior. |
|
Renders RJSF specifications as Jupyter widgets. |
- ju.rjsf.DFLT_RJSF_VIEWER_ON_SUBMIT(form_data, *, indent=2, ensure_ascii=False, prefix='**Submitted data:**\\n\\n')¶
Prints form_data in a nicely formatted way.
- class ju.rjsf.FormConfig(submit_text='Submit', show_labels=True, layout_width='400px', autofocus_first=True)[source]¶
Bases:
objectConfiguration for form rendering behavior.
- class ju.rjsf.RJSFViewer(rjsf_spec, *, on_submit=<function display_form_data>, name=None, unpack_form_data=None, config=None)[source]¶
Bases:
objectRenders RJSF specifications as Jupyter widgets.
Provides a bridge between RJSF form specifications and ipywidgets, allowing interactive form viewing and data collection in notebooks.
Example
>>> rjsf_dict = {'rjsf': {'schema': {...}, 'uiSchema': {...}}} >>> viewer = RJSFViewer(rjsf_dict) >>> viewer.display()
- property widget: Widget¶
Access the underlying widget for custom layouts.
- ju.rjsf.create_rjsf_viewer(rjsf_spec, *, on_submit=<function display_form_data>, name=None, unpack_form_data=None, config=None, display=False)[source]¶
Factory function to create and display an RJSF viewer.
- Parameters:
- Return type:
- Returns:
Configured RJSFViewer instance
Example
>>> def handle_data(data): ... print(f"Received: {data}") >>> viewer = create_rjsf_viewer(rjsf_dict, on_submit=handle_data) >>> viewer.display()
- ju.rjsf.display_form_data(form_data, *, indent=2, ensure_ascii=False, prefix='**Submitted data:**\\n\\n')[source]¶
Prints form_data in a nicely formatted way.
- ju.rjsf.display_in_notebook(string)[source]¶
Display a string in a Jupyter notebook cell.
- Return type:
- ju.rjsf.func_to_form_spec(func, *, doc=True, param_to_prop_type=functools.partial(<function parametrized_param_to_type>, type_mapping=((<class 'str'>, 'string'), (<class 'bool'>, 'boolean'), (<class 'int'>, 'integer'), (<class 'float'>, 'number'), (<class 'collections.abc.Mapping'>, 'object'), (collections.abc.Sequence[str], 'array'), (<class 'bytes'>, 'string'), (<class 'bytearray'>, 'string'), (<class 'memoryview'>, 'string'), (<class 'collections.UserString'>, 'string'), (<class 'collections.abc.Sequence'>, 'array'))), nest_under_field='rjsf', base_rjsf_spec={'disabled': False, 'focusOnFirstError': False, 'liveOmit': False, 'liveValidate': False, 'noHtml5Validate': False, 'noValidate': False, 'omitExtraData': False, 'readonly': False, 'schema': {'properties': {}, 'required': [], 'title': '', 'type': 'object'}, 'showErrorList': 'top', 'uiSchema': {'ui:submitButtonOptions': {'submitText': 'Run'}}}, pyname_to_title=<function asis>)[source]¶
Returns a JSON object that can be used as a form specification, along with the function, to generate a FuncCaller React component in a React application.
param func: The function to transform return: The form specification for the function
>>> def foo( ... a_bool: bool, ... a_float=3.14, ... an_int=2, ... a_str: str = 'hello', ... something_else=None ... ): ... '''A Foo function''' >>> >>> form_spec = func_to_form_spec(foo) >>> assert form_spec == { ... 'rjsf': { ... 'schema': { ... 'title': 'foo', ... 'type': 'object', ... 'properties': { ... 'a_bool': {'type': 'boolean'}, ... 'a_float': {'type': 'number', 'default': 3.14}, ... 'an_int': {'type': 'integer', 'default': 2}, ... 'a_str': {'type': 'string', 'default': 'hello'}, ... 'something_else': {'type': 'string', 'default': None} ... }, ... 'required': ['a_bool'], ... 'description': 'A Foo function' ... }, ... 'uiSchema': { ... 'ui:submitButtonOptions': { ... 'submitText': 'Run' ... }, ... 'a_bool': {'ui:autofocus': True} ... }, ... 'liveValidate': False, ... 'disabled': False, ... 'readonly': False, ... 'omitExtraData': False, ... 'liveOmit': False, ... 'noValidate': False, ... 'noHtml5Validate': False, ... 'focusOnFirstError': False, ... 'showErrorList': 'top' ... } ... }