Skip to content

Instantly share code, notes, and snippets.

@abeluck
Created July 19, 2012 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abeluck/3146378 to your computer and use it in GitHub Desktop.
Save abeluck/3146378 to your computer and use it in GitHub Desktop.
Python + gpgme snippets
import gpgme
# Loop through all keys in the default keyring
# Print the key id, the first uid, and all subkeys
# open context, defaults to ~/.gnupg afaik
ctx = gpgme.Context()
for key in ctx.keylist():
# looks like subkeys[0] is the master key
print "Key: %s %s" % (key.subkeys[0].keyid, key.uids[0].uid)
# loop through subkeys, start at 1 because 0 is master key
for idx in range(1, len(key.subkeys)):
print "\tSubkey: %s" % ( key.subkeys[idx].keyid )
import gpgme
import os
# Set the 'homedir' that gpg reads the keyring from
os.environ['GNUPGHOME'] = '/path/to/some/directory/' # supports relative paths too
ctx = gpgme.Context()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment