Python bindings for post-quantum cryptography — ML-KEM, ML-DSA, SLH-DSA, Classic McEliece, HQC, and SNTRUP
Maintained. Last release 4 months ago, commits in 1 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install pqcrypto
Python bindings for post-quantum cryptography. Wraps well-tested Rust implementations of NIST-standardized and candidate KEM and signature schemes via PyO3/maturin. All variants live in a single compiled wheel.
Installation
pip install pqcrypto
Or build from source:
pip install maturin pytest
maturin develop
Quick Start
The Python API mirrors the Rust crate design: keygen, encaps, decaps
(KEM) and keygen, sign, verify (signatures).
KEM — Key Encapsulation
from pqcrypto.kem.ml_kem_512 import keygen, encaps, decaps
from pqcrypto.kem.ml_kem_512 import PublicKey, SecretKey
pk, sk = keygen()
ct, ss = encaps(pk)
assert decaps(sk, ct) == ss
pk_obj = PublicKey(pk)
sk_obj = SecretKey(sk)
ct2, ss2 = pk_obj.encaps()
assert ss2 == sk_obj.decaps(ct2)
Signatures
from pqcrypto.sign.ml_dsa_44 import keygen, sign, verify
from pqcrypto.sign.ml_dsa_44 import PublicKey, SecretKey
pk, sk = keygen()
sig = sign(sk, b"message")
verify(pk, b"message", sig) # returns None; raises InvalidSignatureError if invalid
# FIPS 204/205 context string:
sig = sign(sk, b"message", b"my-context")
verify(pk, b"message", sig, b"my-context")
# HashML-DSA / HashSLH-DSA pre-hash mode:
from pqcrypto import HashAlgorithm
sig = sign(sk, b"message", hash_algorithm=HashAlgorithm.Sha256)
verify(pk, b"message", sig, hash_algorithm=HashAlgorithm.Sha256)
pk_obj = PublicKey(pk)
sk_obj = SecretKey(sk)
sig_obj = sk_obj.sign(b"message")
pk_obj.verify(b"message", sig_obj)
Size constants
from pqcrypto.kem.ml_kem_512 import PUBLIC_KEY_SIZE, SECRET_KEY_SIZE, CIPHERTEXT_SIZE, SHARED_SECRET_SIZE
from pqcrypto.sign.ml_dsa_44 import PUBLIC_KEY_SIZE, SECRET_KEY_SIZE, SIGNATURE_SIZE
Algorithms
Modules live in pqcrypto.kem (KEM) and (signatures).
