# Keyring

class proton.keyring._base.Keyring

  Base class for keyring implementations.

  Keyrings emulate a dictionary, with:

  - keys: lower case alphanumeric strings (dashes are allowed)

  - values: JSON-serializable list or dictionary.

  classmethod get_from_factory(backend: str = None) → Keyring

    > param backend:

    >   Optional. Specific backend name.

    If backend is passed then it will attempt to get that specific backend, otherwise it will attempt to get the default backend. The definition of default is as follows:

    > - The backend passes the _validate()

    > - The backend with the highest _get_priority() value

    Raises:

      RuntimeError – if there’s no available backend

  __getitem__(key: str)

    Get an item from the keyring

    Parameters:

      key (str) – Key (lowercaps alphanumeric, dashes are allowed)

    Raises:

      - TypeError – if key is not of valid type

      - ValueError – if key doesn’t satisfy constraints

      - KeyError – if key does not exist

      - KeyringLocked – if keyring is locked when it shouldn’t be

      - KeyringError – if there’s something broken with keyring

  __delitem__(key: str)

    Remove an item from the keyring

    Parameters:

      key (str) – Key (lowercaps alphanumeric, dashes are allowed)

    Raises:

      - TypeError – if key is not of valid type

      - ValueError – if key doesn’t satisfy constraints

      - KeyError – if key does not exist

      - KeyringLocked – if keyring is locked when it shouldn’t be

      - KeyringError – if there’s something broken with keyring

  __setitem__(key: str, value: dict | list)

    Add or replace an item in the keyring

    Parameters:

      - key (str) – Key (lowercaps alphanumeric, dashes are allowed)

      - value (dict or list) – Value to set. It has to be json-serializable.

    Raises:

      - TypeError – if key or value is not of valid type

      - ValueError – if key or value doesn’t satisfy constraints

      - KeyringLocked – if keyring is locked when it shouldn’t be

      - KeyringError – if there’s something broken with keyring

  _ensure_key_is_valid(key)

    Ensure key satisfies requirements

  _ensure_value_is_valid(value)

    Ensure value satisfies requirements

class proton.keyring.textfile.KeyringBackendJsonFiles(path_config=None)

  Primitive data storage implementation, to be used when no better keyring is present.

  It stores each entry a json in the configuration path.