Adding a User ID

By comparison to creating primary keys and subkeys, adding a new user ID to an existing key is much simpler. The method used to do this is key_add_uid and the only arguments it takes are for the key and the new uid.

import gpg

c = gpg.Context()
c.home_dir = "~/.gnupg-dm"

dmfpr = "177B7C25DB99745EE2EE13ED026D2F19E99E63AA"
key = c.get_key(dmfpr, secret=True)
uid = "Danger Mouse <danger.mouse@secret.example.net>"

c.key_add_uid(key, uid)

Unsurprisingly the result of this is:

bash-4.4$ gpg --homedir ~/.gnupg-dm -K
~/.gnupg-dm/pubring.kbx
----------------------
sec   rsa3072 2018-03-15 [SC] [expires: 2019-03-15]
      177B7C25DB99745EE2EE13ED026D2F19E99E63AA
uid           [ultimate] Danger Mouse <danger.mouse@secret.example.net>
uid           [ultimate] Danger Mouse <dm@secret.example.net>
ssb   rsa3072 2018-03-15 [E] [expires: 2018-09-13]

bash-4.4$