Skip to main content

A Library to get Keys from a keyserver specified

Project description


A Library to get GPG/PGP keys from a Keyserver. This library uses the requests module to get the keys.

Tested Python Versions

Python 2.7

  • 2.7.15

Python 3

  • 3.7

Intstall via AUR

Install via PyPI

pip install hkp4py

pip3 install hkp4py


This object represents a keyserver using the hkp protocol.


Initialize the KeyServer object.

# python2and3 compliance
from __future__ import absolute_import, unicode_literals, print_function

from hkp4py import KeyServer

server = KeyServer("hkps://")

HKPS support via following pool.

The hkps pool is also supported.



Add keys to a keyserver.

key = "a long key"


Find keys with the keyserver object.

keys ='') # search by string
keys ='0x{}'.format('6F4B4E15768C8C4E'), exact=True) #search by fingerprint

Key Object

for key in keys:
    # Key Basic Information
    print("Key Algorithm:\t{}".format(key.algo))
    print("Key fpr:\t{}".format(key.keyid))
    print("Key Length:\t{}".format(key.key_length))
    print("Disabled?\t{}".format('yes' if key.disabled else 'no'))
    print("Expired?\t{}".format('yes' if key.expired else 'no'))
    print("Revoked?\t{}".format('yes' if key.revoked else 'no'))
    print("From Host:\t{}".format(
    print("From Port:\t{}".format(key.port))
    print("Date Created:\t{}".format(key.creation_date))
    print("Date Expired:\t{}".format(key.expiration_date))

Identity Object

    for identity in key.identities:
        print("\tDisabled?\t{}".format('yes' if identity.disabled else 'no'))
        print("\tExpired?\t{}".format('yes' if identity.expired else 'no'))
        print("\tRevoked?\t{}".format('yes' if identity.revoked else 'no'))
        print("\tDate Created:\t{}".format(identity.creation_date))
        print("\tDate Expired:\t{}".format(identity.expiration_date))

More Advanced options

To set a different User-Agent and proxies for veiling purposes. The KeyServer has the following additional options for the connection.

server = KeyServer("hkps://",
                   proxies={"http": "socks5h://localhost:5050", "https":
                   headers={"User-Agent": "Testing"})

Import key with gpgme python bindings

from __future__ import absolute_import, unicode_literals

import gpg

result = gpg.Context().key_import(key.key_blob)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for hkp4py, version
Filename, size File type Python version Upload date Hashes
Filename, size hkp4py- (7.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size hkp4py- (6.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page