Install & Compatibility
Where this runs
tested against v0.6.1rc1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.204s · 36MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.6s · import 0.174s · 36MB
34MB installed
● package 34MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
PGPKey
✓ from pgpy import PGPKey
✗ from pgpy.constants import PGPKey
PGPKey is a top-level class, not in constants
PGPMessage
✓ from pgpy import PGPMessage
✗ from pgpy.message import PGPMessage
PGPMessage is exported at package level
Generate a PGP key, save to file, encrypt a message.
import pgpy
from pgpy.constants import (
PubKeyAlgorithm,
KeyFlags,
HashAlgorithm,
SymmetricKeyAlgorithm,
CompressionAlgorithm
)
# Generate a new RSA key
key = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 2048)
uid = pgpy.PGPUID.new('Alice', email='alice@example.com')
key.add_uid(uid, usage={KeyFlags.EncryptCommunications, KeyFlags.SignData},
hashes=[HashAlgorithm.SHA256],
ciphers=[SymmetricKeyAlgorithm.AES256],
compression=[CompressionAlgorithm.ZLIB])
# Save private key
with open('private.key', 'wb') as f:
f.write(str(key).encode())
# Encrypt a message
msg = pgpy.PGPMessage.new('Hello, world!')
encrypted = key.encrypt(msg)
print(encrypted)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pgpy'
The pip package is named pgpy13, not pgpy, but the import is 'pgpy'. Users often install 'pgpy' instead.
fixRun 'pip uninstall pgpy' then 'pip install pgpy13'.
AttributeError: 'NoneType' object has no attribute 'encrypt'
Key was not properly loaded or not found when trying to encrypt.
fixEnsure the key is correctly read and parsed: key, _ = pgpy.PGPKey.from_file('path/to/key.asc') ValueError: This key has no usable encryption subkey
The primary key can sign but not encrypt. Must add an encryption subkey or use a key with encryption capabilities.
fixWhen generating key, add usage={KeyFlags.EncryptCommunications} to the UID or generate a key with encryption subkey. Upgrade
Version history
0.6.1rc1latest on PyPI · released Mar 1, 2025
Audit
Dependencies
cryptographyrequiredUnderlying cryptographic operations
sixoptionalPython 2/3 compatibility (original dependency)