PGPy
raw JSON → 0.6.1rc1 verified Fri May 01 auth: no python
PGPy is a Python library for Pretty Good Privacy (PGP) encryption and signing. This temporary fork (pgpy13) provides Python 3.13 compatibility for the original PGPy library. Current version 0.6.1rc1 targets Python >=3.9.
pip install pgpy13 Common errors
error ModuleNotFoundError: No module named 'pgpy' ↓
cause The pip package is named pgpy13, not pgpy, but the import is 'pgpy'. Users often install 'pgpy' instead.
fix
Run 'pip uninstall pgpy' then 'pip install pgpy13'.
error AttributeError: 'NoneType' object has no attribute 'encrypt' ↓
cause Key was not properly loaded or not found when trying to encrypt.
fix
Ensure the key is correctly read and parsed: key, _ = pgpy.PGPKey.from_file('path/to/key.asc')
error ValueError: This key has no usable encryption subkey ↓
cause The primary key can sign but not encrypt. Must add an encryption subkey or use a key with encryption capabilities.
fix
When generating key, add usage={KeyFlags.EncryptCommunications} to the UID or generate a key with encryption subkey.
Warnings
breaking pgpy13 is a temporary fork with a different import path. Do not use both pgpy and pgpy13 in the same environment. ↓
fix Uninstall pgpy before installing pgpy13 or vice versa.
gotcha The package is named 'pgpy13' but the module import is still 'pgpy'. ↓
fix Use 'import pgpy' after pip install pgpy13.
deprecated This fork may be temporary; original PGPy might later update to support Python 3.13. Monitor the original repo. ↓
fix Switch back to original pgpy once it gains Python 3.13 support.
Imports
- PGPKey wrong
from pgpy.constants import PGPKeycorrectfrom pgpy import PGPKey - PGPMessage wrong
from pgpy.message import PGPMessagecorrectfrom pgpy import PGPMessage
Quickstart
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)