PyNaCl: Python binding to the Networking and Cryptography (NaCl) library
PyNaCl is a Python binding to the Networking and Cryptography (NaCl) library, providing cryptographic operations such as digital signatures, secret-key and public-key encryption, hashing, and password-based key derivation. The current version is 1.6.2, released on January 1, 2026. PyNaCl follows a regular release cadence, with updates approximately every 1-2 years.
Warnings
- breaking PyNaCl 1.6.2 requires Python 3.8 or higher.
- gotcha Ensure that the 'libsodium' library is installed on your system, as PyNaCl depends on it for cryptographic operations.
Install
-
pip install pynacl
Imports
- PublicKeyBox
from nacl.public import PublicKeyBox
- SecretBox
from nacl.secret import SecretBox
- SigningKey
from nacl.signing import SigningKey
- VerifyKey
from nacl.signing import VerifyKey
Quickstart
from nacl.public import PrivateKey, PublicKey, PublicKeyBox # Generate a private key private_key = PrivateKey.generate() # Derive the corresponding public key public_key = private_key.public_key # Create a PublicKeyBox for encryption box = PublicKeyBox(public_key) # Encrypt a message message = b"Secret message" encrypted = box.encrypt(message) # Decrypt the message decrypted = box.decrypt(encrypted) print(decrypted.decode())