ju.rjsf

Tools for React-JSONSchema-Form (RJSF)

Functions

DFLT_RJSF_VIEWER_ON_SUBMIT(form_data, *[, ...])

Prints form_data in a nicely formatted way.

create_rjsf_viewer(rjsf_spec, *[, ...])

Factory function to create and display an RJSF viewer.

display_form_data(form_data, *[, indent, ...])

Prints form_data in a nicely formatted way.

display_in_notebook(string)

Display a string in a Jupyter notebook cell.

func_to_form_spec(func, *[, doc, ...])

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

FormConfig([submit_text, show_labels, ...])

Configuration for form rendering behavior.

RJSFViewer(rjsf_spec, *[, on_submit, name, ...])

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.

Parameters:

form_data (dict[str, Any]) – The collected form data

Return type:

None

class ju.rjsf.FormConfig(submit_text='Submit', show_labels=True, layout_width='400px', autofocus_first=True)[source]

Bases: object

Configuration 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: object

Renders 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()
display()[source]

Display the form in the notebook.

Return type:

None

get_form_data()[source]

Extract current form data from widgets.

Return type:

dict[str, Any]

Returns:

Dictionary of form field values

set_form_data(data)[source]

Set form data programmatically.

Parameters:

data (dict[str, Any]) – Dictionary of field values to set

Return type:

None

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:
  • rjsf_spec (dict[str, Any]) – The RJSF specification

  • on_submit (Callable) – Optional submission callback

  • config (FormConfig | None) – Optional form configuration

Return type:

RJSFViewer

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.

Parameters:

form_data (dict[str, Any]) – The collected form data

Return type:

None

ju.rjsf.display_in_notebook(string)[source]

Display a string in a Jupyter notebook cell.

Return type:

None

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'
...     }
... }