Python example: Remove a password: Libsecret Library Reference Manual

## Python example: Remove a password

Here's how to remove a password from the running secret service, like gnome-keyring or ksecretservice.

Each stored password has a set of attributes which are used to find which password to remove. If multiple passwords match the attributes, then the one stored most recently is removed.

These examples use the example schema.

This first example removes a password asynchronously, and is appropriate for GUI applications so that the UI does not block.

    1
    2
    3
    4
    5
    6
    7
    8
    from gi.repository import Secret

    def on_password_clear(source, result, unused):
        removed = Secret.password_clear_finish(result)
        # removed will be true if the password was removed

    Secret.password_clear(EXAMPLE_SCHEMA, { "number": "8", "even": "true" },
                                                  None, on_password_clear)

This next example removes a password synchronously. The function call will block until the removal completes. So this is appropriate for non GUI applications.

    1
    2
    3
    4
    from gi.repository import Secret

    removed = Secret.password_clear_sync(EXAMPLE_SCHEMA, { "number": "8", "even": "true" }, None)
    # removed will be true if the password was removed