Python bindings to FreeDesktop.org Secret Service API for secure password and credential storage
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Manages D-Bus connections to the Secret Service daemon, providing connection initialization, service availability checking, and proper connection lifecycle management.
Creates a new D-Bus connection to the session bus for communicating with the Secret Service daemon. This connection is required for all SecretStorage operations.
def dbus_init() -> DBusConnection:
"""
Returns a new connection to the session bus.
Returns:
DBusConnection: Active D-Bus connection instance
Raises:
SecretServiceNotAvailableException: If D-Bus session bus is unavailable
or environment variables are not set
"""Usage Example:
import secretstorage
from contextlib import closing
# Create connection (must be closed manually)
connection = secretstorage.dbus_init()
try:
# Use connection for operations
collection = secretstorage.get_default_collection(connection)
finally:
connection.close()
# Or use with context manager
with closing(secretstorage.dbus_init()) as connection:
collection = secretstorage.get_default_collection(connection)
# Connection automatically closed when exiting contextVerifies whether the Secret Service daemon is running or available for activation, allowing applications to gracefully handle systems without secret service support.
def check_service_availability(connection: DBusConnection) -> bool:
"""
Returns True if Secret Service daemon is either running or available for activation.
Parameters:
connection (DBusConnection): Active D-Bus connection
Returns:
bool: True if service is available, False otherwise
"""Usage Example:
import secretstorage
connection = secretstorage.dbus_init()
if secretstorage.check_service_availability(connection):
# Safe to use secret service operations
collection = secretstorage.get_default_collection(connection)
else:
# Handle case where secret service is not available
print("Secret service not available, using alternative storage")# From jeepney.io.blocking (external dependency)
class DBusConnection:
"""D-Bus connection for communicating with system services."""
def close(self) -> None:
"""Close the D-Bus connection."""Install with Tessl CLI
npx tessl i tessl/pypi-secretstorage