test_add.py 617 B

1234567891011121314151617181920212223242526272829
  1. import secretstorage
  2. import dbus
  3. # Connect to the session bus
  4. bus = dbus.SessionBus()
  5. # Connect to the Secret Service
  6. connection = secretstorage.dbus_init()
  7. collection = secretstorage.get_default_collection(connection)
  8. # Define attributes and label
  9. attributes = {
  10. 'username': 'alice',
  11. 'service': 'example-app'
  12. }
  13. label = 'My Example Secret'
  14. secret = 'super_secret_password_123'
  15. # Create the item
  16. item = collection.create_item(
  17. label=label,
  18. attributes=attributes,
  19. secret=secret,
  20. replace=True # Replace if an item with same attributes exists
  21. )
  22. print(f"Secret stored with label: {label}")