(name, data, encoder=None, display=None)
Records a data value in the given notebook cell.

    The recorded data value can be retrieved during later inspection of the
    output notebook.

    The data type of the scraps is implied by the value type of any of the
    registered data encoders, but can be overwritten by setting the `encoder`
    argument to a particular encoder's registered name (e.g. `"json"`).

    This data is persisted by generating a display output with a special media
    type identifying the content storage encoder and data. These outputs are not
    visible in notebook rendering but still exist in the document. Scrapbook
    then can rehydrate the data associated with the notebook in the future by
    reading these cell outputs.

    Example
    -------

        sb.glue("hello", "world")
        sb.glue("number", 123)
        sb.glue("some_list", [1, 3, 5])
        sb.glue("some_dict", {"a": 1, "b": 2})
        sb.glue("non_json", df, 'arrow')

    The scrapbook library can be used later to recover scraps (recorded values)
    from the output notebook

        nb = sb.read_notebook('notebook.ipynb')
        nb.scraps

    Parameters
    ----------
    name: str
        Name of the value to record.
    data: any
        The value to record. This must be an object for which an encoder's
        `encodable` method returns True.
    encoder: str (optional)
        The name of the handler to use in persisting data in the notebook.
    display: any (optional)
        An indicator for persisting controlling displays for the named record.
Records a data value in the given notebook cell.
Records a data value in the given notebook cell .
def glue(name, data, encoder=None, display=None):
    """
    Records a data value in the given notebook cell.

    The recorded data value can be retrieved during later inspection of the
    output notebook.

    The data type of the scraps is implied by the value type of any of the
    registered data encoders, but can be overwritten by setting the `encoder`
    argument to a particular encoder's registered name (e.g. `"json"`).

    This data is persisted by generating a display output with a special media
    type identifying the content storage encoder and data. These outputs are not
    visible in notebook rendering but still exist in the document. Scrapbook
    then can rehydrate the data associated with the notebook in the future by
    reading these cell outputs.

    Example
    -------

        sb.glue("hello", "world")
        sb.glue("number", 123)
        sb.glue("some_list", [1, 3, 5])
        sb.glue("some_dict", {"a": 1, "b": 2})
        sb.glue("non_json", df, 'arrow')

    The scrapbook library can be used later to recover scraps (recorded values)
    from the output notebook

        nb = sb.read_notebook('notebook.ipynb')
        nb.scraps

    Parameters
    ----------
    name: str
        Name of the value to record.
    data: any
        The value to record. This must be an object for which an encoder's
        `encodable` method returns True.
    encoder: str (optional)
        The name of the handler to use in persisting data in the notebook.
    display: any (optional)
        An indicator for persisting controlling displays for the named record.
    """
    # Keep slow import lazy
    import IPython
    from IPython.display import display as ip_display

    # TODO: Implement the cool stuff. Remote storage indicators?!? Maybe remote media type?!?
    if not encoder:
        try:
            encoder = encoder_registry.determine_encoder_name(data)
        except NotImplementedError:
            if display is not None:
                # Do not raise an exception if the scrap isn't encodable because
                # the corresponding display object may be.
                encoder = 'display'
            else:
                raise

    if display is None:
        display = encoder == "display"

    # Only store data that can be stored (purely display scraps can skip)
    if encoder != "display":
        ipy_data, metadata = _prepare_ipy_data_format(
            name, scrap_to_payload(encoder_registry.encode(Scrap(name, data, encoder))), encoder
        )
        ip_display(ipy_data, metadata=metadata, raw=True)

    # Only display data that is marked for display
    if display:
        display_kwargs = {}
        if isinstance(display, (list, tuple)):
            display_kwargs = {"include": display}
        elif isinstance(display, dict):
            display_kwargs = display
        raw_data, raw_metadata = IPython.core.formatters.format_display_data(data, **display_kwargs)
        data, metadata = _prepare_ipy_display_format(name, raw_data, raw_metadata)
        ip_display(data, metadata=metadata, raw=True)
def glue ( name , data , encoder = None , display = None ) : # Keep slow import lazy import IPython from IPython . display import display as ip_display # TODO: Implement the cool stuff. Remote storage indicators?!? Maybe remote media type?!? if not encoder : try : encoder = encoder_registry . determine_encoder_name ( data ) except NotImplementedError : if display is not None : # Do not raise an exception if the scrap isn't encodable because # the corresponding display object may be. encoder = 'display' else : raise if display is None : display = encoder == "display" # Only store data that can be stored (purely display scraps can skip) if encoder != "display" : ipy_data , metadata = _prepare_ipy_data_format ( name , scrap_to_payload ( encoder_registry . encode ( Scrap ( name , data , encoder ) ) ) , encoder ) ip_display ( ipy_data , metadata = metadata , raw = True ) # Only display data that is marked for display if display : display_kwargs = { } if isinstance ( display , ( list , tuple ) ) : display_kwargs = { "include" : display } elif isinstance ( display , dict ) : display_kwargs = display raw_data , raw_metadata = IPython . core . formatters . format_display_data ( data , * * display_kwargs ) data , metadata = _prepare_ipy_display_format ( name , raw_data , raw_metadata ) ip_display ( data , metadata = metadata , raw = True )