Skip to main content

hkp4py

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

KeyServer

This object represents a keyserver using the hkp protocol.

Initialize

Initialize the KeyServer object.

# python2and3 compliance
from __future__ import absolute_import, unicode_literals, print_function

from hkp4py import KeyServer


server = KeyServer("hkps://pgp.ext.selfnet.de")

HKPS support via following pool.

The hkps pool is also supported.

hkps://hkps.pool.sks-keyservers.net

Add

Add keys to a keyserver.

key = "a long key"
server.add(key)

Find keys with the keyserver object.

keys = server.search('@gnupg.org') # search by string
keys = server.search('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(key.host))
    print("From Port:\t{}".format(key.port))
    print("Date Created:\t{}".format(key.creation_date))
    print("Date Expired:\t{}".format(key.expiration_date))
    print(key.key)
    print(key.key_blob)

Identity Object

    for identity in key.identities:
        print("Identity:\t{}".format(identity.uid))
        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://pgp.ext.selfnet.de",
                   proxies={"http": "socks5h://localhost:5050", "https":
                   "socks5h://localhost:5050"},
                   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)

Metadata

Release files for hkp4py 0.2.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hkp4py 0.2.3.1
File Size Uploaded Provenance
hkp4py-0.2.3.1.tar.gz 6.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for hkp4py 0.2.3.1
File Interpreter ABI Platform
hkp4py-0.2.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / hkp4py-0.2.3.1.tar.gz

Download URL hkp4py-0.2.3.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d9f24abc4e5eb4ee8c760474c20c79b06640951604bb16aac3f1ff3161949726
BLAKE2b-256 checksum
How to use checksums
128fcfbf0ec8946dcbacab876a8e82d2f3679527d1974f5739706cbb27a5e311
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

Release files / hkp4py-0.2.3.1-py3-none-any.whl

Download URL hkp4py-0.2.3.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6c5c1d38755292a06bf6be745d1b160c28146ba3766ee58ae9285afa358f8e1
BLAKE2b-256 checksum
How to use checksums
fefddbc9ff38a36f0b9711f147de1f26a35c19c6f9de55b07222c17d3d1d0c20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

Security for hkp4py 0.2.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page