Python cryptography libraries

Updated Nov 2026

Python cryptography libraries encrypt data, sign and verify messages, and hash passwords. A high-level recipe chooses the algorithm and its parameters for the caller rather than exposing each primitive. These libraries let apps and services protect stored data, secrets, and user passwords.

Popularity

cryptography has the most monthly downloads in this comparison, at 1.4B.

LibraryMonthly downloadsStarsLast releaseLicense
cryptography
1.4B
7.9KSep 2026Apache-2.0 OR BSD-3-Clause
rsa
196.7M
490Apr 2025Apache-2.0
PyNaCl
177.2M
1.2KJan 2026Apache-2.0
bcrypt
175.9M
1.5KSep 2025Apache-2.0
PyCryptodome
86.4M
3.3KNov 2026BSD-2-Clause AND Unlicense AND MIT
argon2-cffi
83.3M
742Jun 2025MIT
ecdsa
43.4M
978Mar 2026MIT
Passlib
35.2M
Not on GitHubOct 2020BSD
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibraryAuthenticated encryptionPassword hash recordsDigital signatures
cryptographyBuilt-inBuilt-inBuilt-in
rsaUnsupportedUnsupportedBuilt-in
PyNaClBuilt-inBuilt-inBuilt-in
bcryptUnsupportedBuilt-inUnsupported
PyCryptodomeBuilt-inBuilt-inBuilt-in
argon2-cffiUnsupportedBuilt-inUnsupported
ecdsaUnsupportedUnsupportedBuilt-in
PasslibUnsupportedBuilt-inUnsupported
Built-inNot supported

Libraries and code examples

Provides cryptographic recipes and lower-level cryptographic primitives.

Downloads / mo
1.4B
Stars
7.9K
Last release
50.0.2
License
Apache-2.0 OR BSD-3-Clause

Strengths

  • Authenticates encrypted messages. Use Fernet to encrypt messages and detect tampering.
  • Supports Fernet key rotation. Rotate encrypted tokens with MultiFernet.

Limitations

  • Fernet keeps whole messages in-memory. Choose a streaming design for data that cannot fit in memory.
  • Token timestamps stay visible. Fernet tokens expose creation timestamps while their message payloads remain encrypted.

Quickstart

From fernet.md
$ python3 -m pip install cryptography
from cryptography.fernet import Fernet
key = Fernet.generate_key()
f = Fernet(key)
token = f.encrypt(b"my deep dark secret")

cryptography examples

From open-source projects on GitHub

Implements RSA in pure Python.

Downloads / mo
196.7M
Stars
490
Last release
4.9.1
License
Apache-2.0

Quickstart

From usage.rst
$ python3 -m pip install rsa
import rsa
public_key, private_key = rsa.newkeys(2048)
signature = rsa.sign(b"message", private_key, "SHA-256")

rsa examples

From open-source projects on GitHub
def verify(self, msg, sig):
    if not self.is_public():
        warnings.warn("Attempting to verify a message with a private key. " "This is not recommended.")
    try:
        pyrsa.verify(msg, sig, self._prepared_key)
        return True
    except pyrsa.pkcs1.VerificationError:
        return False

Exposes the libsodium cryptography library through Python bindings.

Downloads / mo
177.2M
Stars
1.2K
Last release
1.6.2
License
Apache-2.0
Runs on
libsodium

Strengths

  • Includes authenticated message encryption. Use SecretBox or Aead to encrypt and authenticate messages.
  • Includes memory-hard password hashing. Use Argon2id, Argon2i, or scrypt through nacl.pwhash.

Limitations

  • Password keys need saved parameters. Store the salt, chosen derivation function, and its cost settings.

Quickstart

From secret.md
$ python3 -m pip install PyNaCl
import nacl.secret
import nacl.utils
key = nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE)
box = nacl.secret.SecretBox(key)
encrypted = box.encrypt(b"message")

PyNaCl examples

From open-source projects on GitHub

Hashes and checks passwords with bcrypt.

Downloads / mo
175.9M
Stars
1.5K
Last release
5.0.0
License
Apache-2.0

Strengths

  • Tunes password-hashing work. Set the work factor when generating a salt.
  • Derives OpenSSH-compatible keys. Use bcrypt.kdf for OpenSSH’s password-based key derivation.

Limitations

  • Long passwords raise errors. Validate encoded password length before calling hashpw.
  • New password storage favors alternatives. Consider Argon2id or scrypt for new password-storage designs.

Quickstart

From README.rst
$ python3 -m pip install bcrypt
import bcrypt
hashed = bcrypt.hashpw(b"super secret password", bcrypt.gensalt())

Provides a self-contained Python package of low-level cryptographic primitives.

Downloads / mo
86.4M
Stars
3.3K
Last release
4.5.0
License
BSD-2-Clause AND Unlicense AND MIT

Strengths

  • Includes authenticated AES modes. Encrypt messages and verify their authentication tags with AES-GCM.
  • Derives password-based keys. Derive encryption keys from passwords with scrypt.

Limitations

  • Cipher modes have different guarantees. Choose an authenticated mode when ciphertext tampering must be detected.
  • GCM needs unique nonces. Generate a fresh nonce for each message encrypted under the same key.

Quickstart

From modern.html
$ python3 -m pip install pycryptodome
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
key = get_random_bytes(32)
nonce = get_random_bytes(12)
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
ciphertext, tag = cipher.encrypt_and_digest(b"Attack at dawn")

PyCryptodome examples

From open-source projects on GitHub

Hashes passwords with Argon2.

Downloads / mo
83.3M
Stars
742
Last release
25.1.0
License
MIT

Quickstart

From index.rst
$ python3 -m pip install argon2-cffi
from argon2 import PasswordHasher
ph = PasswordHasher()
hash = ph.hash("correct horse battery staple")

argon2-cffi examples

From open-source projects on GitHub

Signs and verifies ECDSA signatures in pure Python.

Downloads / mo
43.4M
Stars
978
Last release
0.19.2
License
MIT

Quickstart

From quickstart.rst
$ python3 -m pip install ecdsa
from ecdsa import SigningKey, NIST256p
from hashlib import sha256
key = SigningKey.generate(curve=NIST256p)
signature = key.sign_deterministic(b"message", hashfunc=sha256)

ecdsa examples

From open-source projects on GitHub
def verify(self, msg, sig):
    try:
        return self.prepared_key.verify(
            sig, msg, hashfunc=self.hash_alg, sigdecode=ecdsa.util.sigdecode_string, allow_truncate=False
        )
    except Exception:
        return False

Passlib

Hashes passwords through a framework that supports over 30 schemes.

Downloads / mo
35.2M
Last release
1.7.4
License
BSD

Quickstart

From context-tutorial.rst
$ python3 -m pip install passlib
from passlib.context import CryptContext
context = CryptContext(schemes=["pbkdf2_sha512"])
hash = context.hash("password")

FAQ

cryptography suits most applications, with authenticated encryption recipes and lower-level primitives. argon2-cffi and bcrypt suit password storage. PyNaCl suits code that wants the fixed choices of libsodium.

PyCryptodome is a self-contained package of low-level ciphers, signatures, message authentication codes, and key derivation functions. The caller chooses the cipher mode and parameters for each operation.

Passlib is a password hashing framework that selects, verifies, and migrates between many hash schemes.

bcrypt generates password records that store the cost factor and salt inside the encoded bytes, then verifies passwords against them. It focuses on password storage rather than general encryption.

PyNaCl is a Python binding to libsodium with authenticated symmetric encryption, public-key signatures, and password hashing helpers.

For coding agents

Found your cryptography library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official