API Reference¶
tesseract-streamlit.parse
¶
Parsing module for tesseract-streamlit
.
Utilities for parsing and formatting inputs to be injected into the Streamlit template.
Routines here handle both the OpenAPI Specification generated for a Tesseract, and functions passed into the user-defined functions module. Each are then parsed and formatted into string descriptions, and structured with lists and dictionaries, for easy injection in the Streamlit Jinja template.
The object to be passed to the Jinja template is an instance of
TemplateData
, which may be created using the only entry-point to
this module: extract_template_data()
.
All other members are private or TypedDict
definitions.
- class tesseract_streamlit.parse.FuncDescription[source]¶
Represents a brief summary of a Python function.
Stores the function’s name, the first line of its docstring as the title, and the remaining docstring content as documentation.
This is used in the Streamlit template to inject the functions into the app, and annotate their plot outputs with the title and docs the user provides.
backend identifies which plotting library is supported. “builtin” indicates that support is provided by Streamlit natively.
- class tesseract_streamlit.parse.JinjaField[source]¶
Input field schema preprocessed for Jinja template compatibilityping.
Replaces “ancestors” from
_InputField
with “parent_container”, “container”, “uid”, “stem”, and “key”.
- class tesseract_streamlit.parse.TemplateData[source]¶
Schema for passing data directly to Jinja template for injection.
- The following key value pairs are:
metadata: background information on the Tesseract instance. schema: structure of the input form. url: URI of the running Tesseract instance. needs_pyvista: whether to enable PyVista support for the UDFs. udf_defs: source code for the UDF definitions. udfs: register of the UDFs, sorted by their input parameters.
-
metadata:
TesseractMetadata
¶
-
schema:
list
[JinjaField
]¶
-
udfs:
NotRequired
[UdfRegister
]¶
- class tesseract_streamlit.parse.TesseractMetadata[source]¶
Basic info about the Tesseract being interfaced.
Title, description, and version information to be injected into the header of the Streamlit template.
- class tesseract_streamlit.parse.UdfRegister[source]¶
Stores the user-defined function descriptions as a register.
Each kind of function is stored in its own list, based on what parameter it takes. If it takes Tesseract inputs as a parameter, it is stored in the list under the ‘inputs’ key. Likewise for Tesseract outputs. If it takes both inputs and outputs, it’s stored under ‘both’.
This register is passed for injection into the Streamlit app template. Storing the functions by the parameters they take enables them to be passed the correct parameters in the generated app.
-
both:
list
[FuncDescription
]¶
-
inputs:
list
[FuncDescription
]¶
-
outputs:
list
[FuncDescription
]¶
-
both:
- exception tesseract_streamlit.parse.UserDefinedFunctionError(message)[source]¶
Exception for invalid user defined functions.
- exception tesseract_streamlit.parse.UserDefinedFunctionWarning(message)[source]¶
Warning for user defined functions.
- tesseract_streamlit.parse.extract_template_data(url, user_code, pretty_headings)[source]¶
Formats Tesseract and user-defined function inputs for template.
Retrieves and parses the OpenAPI specification of the running Tesseract. User code is also analysed. These inputs are then formatted and pre-processed according to the
TemplateData
schema to provide all data required to statically render the Streamlit app.- Parameters:
- Returns:
Preprocessed data describing the Streamlit app based on the
InputSchema
, ready for injection into the app template.- Return type: