Keyrings-alt
Keyrings-alt is a Python package that provides alternative backend implementations for the `keyring` library, enabling password storage solutions across various environments. It's currently at version 5.0.2 and maintains an active release cadence, often aligning with `keyring` library updates.
Warnings
- breaking `keyrings-alt` v4.0.0 and later require Python 3.8 or newer. Previous versions supported older Python environments.
- breaking `keyrings-alt` v5.0.0 and later explicitly require `keyring` library version 24.0.0 or newer. Installing `keyrings-alt` might automatically upgrade `keyring`.
- gotcha Users typically interact with `keyrings-alt` indirectly through the `keyring` library's API (e.g., `keyring.set_password`, `keyring.get_password`). Direct imports from `keyrings.alt` are generally for advanced scenarios like explicit backend instantiation.
- gotcha Different backends provided by `keyrings-alt` (e.g., `FileKeyring`, `NullKeyring`) have varying security implications. Some backends, like `FileKeyring`, store credentials in plaintext or in less secure ways than system-native keyrings.
Install
-
pip install keyrings-alt
Imports
- FileKeyring
from keyrings.alt.file import FileKeyring
Quickstart
import keyring
import os
# keyrings-alt, once installed, provides additional backends
# that the 'keyring' library automatically discovers and uses.
service_name = "my-app-service"
username = "test-user"
password = os.environ.get('KEYRING_TEST_PASSWORD', 'super-secret-password-123')
print(f"Using keyring for service '{service_name}', user '{username}'.")
# Set a password. The 'keyring' library will try to use the best available backend,
# which might be one provided by keyrings-alt if no stronger native keyring is present.
keyring.set_password(service_name, username, password)
print(f"Password set for service '{service_name}' user '{username}'.")
# Retrieve the password
retrieved_password = keyring.get_password(service_name, username)
print(f"Retrieved password: {'*' * len(retrieved_password) if retrieved_password else 'None'}")
if retrieved_password == password:
print("Password retrieved successfully and matches original.")
else:
print("Password retrieval failed or did not match.")
# You can inspect the currently active keyring backend
current_keyring = keyring.get_keyring()
print(f"\nCurrently active keyring backend: {current_keyring.__class__.__name__}")