Functions
    • Dark
      Light

    Functions

    • Dark
      Light

    Article summary

    There are various functions available in the pre-installed sm_udf library for common use cases.

    Data Access

    Database

    sm_udf.app_builder.odbc.get_sql_engine()

    Returns a sqlalchemy.engine.Engine that is set up to connect to the database.

    Usage:

    from sm_udf.app_builder.odbc import get_sql_engine()
    
    engine = get_sql_engine()
    
    with engine.connect() as conn:
        conn.execute(sqlalchemy_query)

    Sight Machine SDK

    sm_udf.app_builder.smsdk.get_smsdk_client()

    Returns an smsdk.client.Client that is set up to connect to the Sight Machine API.

    Usage:

    from sm_udf.app_builder.smsdk import get_smsdk_client
    
    client = get_smsdk_client()

    Output Formatting

    Graphs & Charts

    sm_udf.app_builder.util.setup_plotly_theme()

    Sets up a custom theme for Plotly that matches the look and feel of other Sight Machine applications and dashboards.

    Usage:

    from sm_udf.app_builder.util import setup_plotly_theme
    
    setup_plotly_theme()

    Final Output

    sm_udf.app_builder.util.return_app_builder_results(results)

    Formats your results for final output. This is required to be the final line of the final cell in your notebook, and results must be a Python dictionary containing only JSON-serializable values.

    Usage:

    from sm_udf.app_builder.util import return_app_builder_results
    
    return_app_builder_results(response)

    Encode Page Linking for Markdown Panels

    sm_udf.app_builder.util.create_markdown_encoded_data_link()

    Help encode the link_mapping to pass to data-link for creating a link element in a markdown panel.

    Usage:

    from sm_udf.app_builder.util import create_markdown_encoded_data_link
    
    link_encoded = create_markdown_encoded_data_link(link_mapping)
    markdown = f"""
    <span data-link="{link_encoded}">View Chart</span>
    """
    
    markdown_panel = {
        "id": "markdown-panel",
        "viz_type": "markdown",
        "viz_props": {
            "markdown": markdown
        }
    }


    What's Next