Skip to content

For reference: This is how to hide private information from text/plain when using widgets #3875

Open
@kolibril13

Description

@kolibril13

Today, I was wondering how to not accidentally commit my open AI key when passing it to a widget.
Even when I import it from another python file that is git-ignored, it would still show up as plain text in the text/plain notebook metadata.
Therefore, here's a solution I came up with, hope that this will be useful for other people as well! :)
image

class MyPrivateButton(ipywidgets.Button):
    def _repr_mimebundle_(self, *args, **kwargs):
        mimebundle = super()._repr_mimebundle_(*args, **kwargs)
        mimebundle["text/plain"]= "Button Widget, all private info got removed!"
        return mimebundle
    
MyPrivateButton(description="My Secret Key")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions