# Python cryptography libraries

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

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [cryptography](#cryptography) | 1.4B | 7.9K | Sep 2026 | Apache-2.0 OR BSD-3-Clause |
| [rsa](#rsa) | 196.7M | 490 | Apr 2025 | Apache-2.0 |
| [PyNaCl](#pynacl) | 177.2M | 1.2K | Jan 2026 | Apache-2.0 |
| [bcrypt](#bcrypt) | 175.9M | 1.5K | Sep 2025 | Apache-2.0 |
| [PyCryptodome](#pycryptodome) | 86.4M | 3.3K | Nov 2026 | BSD-2-Clause AND Unlicense AND MIT |
| [argon2-cffi](#argontwo-cffi) | 83.3M | 742 | Jun 2025 | MIT |
| [ecdsa](#ecdsa) | 43.4M | 978 | Mar 2026 | MIT |
| [Passlib](#passlib) | 35.2M | Not on GitHub | Oct 2020 | BSD |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[cryptography](#cryptography) has the most monthly downloads in this comparison, at 1.4B.

## Capabilities

| Library | Authenticated encryption | Password hash records | Digital signatures |
| --- | --- | --- | --- |
| [cryptography](#cryptography) | Yes | Yes | Yes |
| [rsa](#rsa) | No | No | Yes |
| [PyNaCl](#pynacl) | Yes | Yes | Yes |
| [bcrypt](#bcrypt) | No | Yes | No |
| [PyCryptodome](#pycryptodome) | Yes | Yes | Yes |
| [argon2-cffi](#argontwo-cffi) | No | Yes | No |
| [ecdsa](#ecdsa) | No | No | Yes |
| [Passlib](#passlib) | No | Yes | No |

## Libraries

### cryptography

[GitHub](https://github.com/pyca/cryptography) · [PyPI](https://pypi.org/project/cryptography) · [Docs](https://pypi.org/pypi/cryptography/50.0.2/json)

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
- Capabilities: [From the cryptography docs](https://pypi.org/pypi/cryptography/50.0.2/json)

**Strengths**

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

**Watch out for**

- **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.

```sh
python3 -m pip install cryptography
```

**paramiko/paramiko** (9.9K stars)

[paramiko/paramiko](https://github.com/paramiko/paramiko) 

```python
def _write_private_key(
    self,
    f: RawIOBase,
    key: PrivateKey,
    file_format: FileFormat,
    password: Optional[str] = None,
):
    if password is None:
        encryption = serialization.NoEncryption()
    else:
        encryption = serialization.BestAvailableEncryption(b(password))

    f.write(
        key.private_bytes(
            file_format.encoding, file_format.format, encryption
        ).decode()
    )

```

[paramiko/pkey.py](https://github.com/paramiko/paramiko/blob/0e9ccb91e0f9a68f2587233d523ad7fe46e730fe/paramiko/pkey.py#L825-L841) · [More projects using cryptography →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20cryptography%20for%20authenticated%20encryption%2C%20private-key%20serialization%2C%20packet%20protection%20and%20password%20hashing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from cryptography.fernet import Fernet
key = Fernet.generate_key()
f = Fernet(key)
token = f.encrypt(b"my deep dark secret")

```

From [fernet.md](https://cryptography.io/en/latest/fernet/)

### rsa

[GitHub](https://github.com/sybrenstuvel/python-rsa) · [PyPI](https://pypi.org/project/rsa) · [Docs](https://stuvel.eu/python-rsa-doc/usage.html)

Implements RSA in pure Python.

- Downloads / mo: 196.7M
- Stars: 490
- Last release: 4.9.1
- License: Apache-2.0
- Capabilities: [From the rsa docs](https://stuvel.eu/python-rsa-doc/usage.html)

```sh
python3 -m pip install rsa
```

**mpdavis/python-jose** (1.8K stars)

[mpdavis/python-jose](https://github.com/mpdavis/python-jose) 

```python
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

```

[jose/backends/rsa_backend.py](https://github.com/mpdavis/python-jose/blob/018b310ddb8b50dcfd09a0c152117835a21dd656/jose/backends/rsa_backend.py#L206-L213) · [More projects using rsa →](https://dashboard.exa.ai/playground/search?q=rsa%20GitHub%20projects)

**Quickstart**

```python
import rsa
public_key, private_key = rsa.newkeys(2048)
signature = rsa.sign(b"message", private_key, "SHA-256")

```

From [usage.rst](https://stuvel.eu/python-rsa-doc/usage.html)

### PyNaCl

[GitHub](https://github.com/pyca/pynacl) · [PyPI](https://pypi.org/project/PyNaCl) · [Docs](https://pynacl.readthedocs.io/en/latest/secret/)

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
- Capabilities: [From the PyNaCl docs](https://pynacl.readthedocs.io/en/latest/secret/)

**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.

**Watch out for**

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

```sh
python3 -m pip install PyNaCl
```

**Rapptz/discord.py** (16.2K stars)

[Rapptz/discord.py](https://github.com/Rapptz/discord.py) 

```python
def _encrypt_aead_xchacha20_poly1305_rtpsize(self, header: bytes, data) -> bytes:
    # Esentially the same as _lite
    # Uses an incrementing 32-bit integer which is appended to the payload
    # The only other difference is we require AEAD with Additional Authenticated Data (the header)
    box = nacl.secret.Aead(bytes(self.secret_key))
    nonce = bytearray(24)

    nonce[:4] = struct.pack('>I', self._incr_nonce)
    self.checked_add('_incr_nonce', 1, 4294967295)

    return header + box.encrypt(bytes(data), bytes(header), bytes(nonce)).ciphertext + nonce[:4]

```

[discord/voice_client.py](https://github.com/Rapptz/discord.py/blob/65232c38702be5844cf2ce865a4777eb1928b5d0/discord/voice_client.py#L403-L413) · [More projects using PyNaCl →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20PyNaCl%20for%20authenticated%20encryption%2C%20private-key%20serialization%2C%20packet%20protection%20and%20password%20hashing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
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")

```

From [secret.md](https://pynacl.readthedocs.io/en/latest/secret/)

### bcrypt

[GitHub](https://github.com/pyca/bcrypt) · [PyPI](https://pypi.org/project/bcrypt)

Hashes and checks passwords with bcrypt.

- Downloads / mo: 175.9M
- Stars: 1.5K
- Last release: 5.0.0
- License: Apache-2.0
- Capabilities: [From the bcrypt docs](https://github.com/pyca/bcrypt)

**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.

**Watch out for**

- **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.

```sh
python3 -m pip install bcrypt
```

**Quickstart**

```python
import bcrypt
hashed = bcrypt.hashpw(b"super secret password", bcrypt.gensalt())

```

From [README.rst](https://github.com/pyca/bcrypt) · [Find projects using bcrypt →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20bcrypt%20for%20authenticated%20encryption%2C%20private-key%20serialization%2C%20packet%20protection%20and%20password%20hashing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### PyCryptodome

[GitHub](https://github.com/Legrandin/pycryptodome) · [PyPI](https://pypi.org/project/pycryptodome) · [Docs](https://www.pycryptodome.org/src/cipher/aes)

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
- Capabilities: [From the PyCryptodome docs](https://www.pycryptodome.org/src/cipher/aes)

**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.

**Watch out for**

- **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.

```sh
python3 -m pip install pycryptodome
```

**ansible/ansible** (71.5K stars)

[ansible/ansible](https://github.com/ansible/ansible) 

```python
@staticmethod
def _encrypt_pycrypto(b_plaintext, b_key1, b_key2, b_iv):
    # PKCS#7 PAD DATA http://tools.ietf.org/html/rfc5652#section-6.3
    bs = AES_pycrypto.block_size
    padding_length = (bs - len(b_plaintext) % bs) or bs
    b_plaintext += to_bytes(padding_length * chr(padding_length), encoding='ascii', errors='strict')

    # COUNTER.new PARAMETERS
    # 1) nbits (integer) - Length of the counter, in bits.
    # 2) initial_value (integer) - initial value of the counter. "iv" from _gen_key_initctr

    ctr = Counter_pycrypto.new(128, initial_value=int(b_iv, 16))

    # AES.new PARAMETERS
    # 1) AES key, must be either 16, 24, or 32 bytes long -- "key" from _gen_key_initctr
    # 2) MODE_CTR, is the recommended mode
    # 3) counter=<CounterObject>

    cipher = AES_pycrypto.new(b_key1, AES_pycrypto.MODE_CTR, counter=ctr)

    # ENCRYPT PADDED DATA
    b_ciphertext = cipher.encrypt(b_plaintext)

    # COMBINE SALT, DIGEST AND DATA
    hmac = HMAC_pycrypto.new(b_key2, b_ciphertext, SHA256_pycrypto)

    return to_bytes(hmac.hexdigest(), errors='surrogate_or_strict'), hexlify(b_ciphertext)

```

[lib/ansible/parsing/vault/__init__.py](https://github.com/ansible/ansible/blob/5cfdbd83151edd000e79edf550f0c5bc54aebd19/lib/ansible/parsing/vault/__init__.py#L1233-L1259) · [More projects using PyCryptodome →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20pycryptodome%20for%20authenticated%20encryption%2C%20private-key%20serialization%2C%20packet%20protection%20and%20password%20hashing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
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")

```

From [modern.html](https://pycryptodome.readthedocs.io/en/latest/src/cipher/modern.html)

### argon2-cffi

[GitHub](https://github.com/hynek/argon2-cffi) · [PyPI](https://pypi.org/project/argon2-cffi) · [Docs](https://argon2-cffi.readthedocs.io/en/stable/)

Hashes passwords with Argon2.

- Downloads / mo: 83.3M
- Stars: 742
- Last release: 25.1.0
- License: MIT
- Capabilities: [From the argon2-cffi docs](https://argon2-cffi.readthedocs.io/en/stable/)

```sh
python3 -m pip install argon2-cffi
```

**jupyter-server/jupyter_server** (573 stars)

[jupyter-server/jupyter_server](https://github.com/jupyter-server/jupyter_server) 

```python
def passwd(passphrase=None, algorithm="argon2"):
    """Generate hashed password and salt for use in server configuration.

    In the server configuration, set `c.ServerApp.password` to
    the generated string.

    Parameters
    ----------
    passphrase : str
        Password to hash.  If unspecified, the user is asked to input
        and verify a password.
    algorithm : str
        Hashing algorithm to use (e.g, 'sha1' or any argument supported
        by :func:`hashlib.new`, or 'argon2').

    Returns
    -------
    hashed_passphrase : str
        Hashed password, in the format 'hash_algorithm:salt:passphrase_hash'.

    Examples
    --------
    >>> passwd("mypassword")  # doctest: +ELLIPSIS
    'argon2:...'

    """
    if passphrase is None:
        for _ in range(3):
            p0 = getpass.getpass("Enter password: ")
            p1 = getpass.getpass("Verify password: ")
            if p0 == p1:
                passphrase = p0
                break
            warnings.warn("Passwords do not match.", stacklevel=2)
        else:
            msg = "No matching passwords found. Giving up."
            raise ValueError(msg)

    if algorithm == "argon2":
        import argon2

        ph = argon2.PasswordHasher(
            memory_cost=10240,
            time_cost=10,
            parallelism=8,
        )
        h_ph = ph.hash(passphrase)

        return f"{algorithm}:{h_ph}"

    h = hashlib.new(algorithm)
    salt = ("%0" + str(salt_len) + "x") % random.getrandbits(4 * salt_len)
    h.update(passphrase.encode("utf-8") + salt.encode("ascii"))

    return f"{algorithm}:{salt}:{h.hexdigest()}"

```

[jupyter_server/auth/security.py](https://github.com/jupyter-server/jupyter_server/blob/c4c5a51d2cf77d31a266376582ee05c4d661ad4b/jupyter_server/auth/security.py#L23-L77) · [More projects using argon2-cffi →](https://dashboard.exa.ai/playground/search?q=argon2-cffi%20GitHub%20projects)

**Quickstart**

```python
from argon2 import PasswordHasher
ph = PasswordHasher()
hash = ph.hash("correct horse battery staple")

```

From [index.rst](https://argon2-cffi.readthedocs.io/en/stable/)

### ecdsa

[GitHub](https://github.com/tlsfuzzer/python-ecdsa) · [PyPI](https://pypi.org/project/ecdsa)

Signs and verifies ECDSA signatures in pure Python.

- Downloads / mo: 43.4M
- Stars: 978
- Last release: 0.19.2
- License: MIT
- Capabilities: [From the ecdsa docs](https://github.com/tlsfuzzer/python-ecdsa)

```sh
python3 -m pip install ecdsa
```

**mpdavis/python-jose** (1.8K stars)

[mpdavis/python-jose](https://github.com/mpdavis/python-jose) 

```python
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

```

[jose/backends/ecdsa_backend.py](https://github.com/mpdavis/python-jose/blob/018b310ddb8b50dcfd09a0c152117835a21dd656/jose/backends/ecdsa_backend.py#L103-L109) · [More projects using ecdsa →](https://dashboard.exa.ai/playground/search?q=ecdsa%20GitHub%20projects)

**Quickstart**

```python
from ecdsa import SigningKey, NIST256p
from hashlib import sha256
key = SigningKey.generate(curve=NIST256p)
signature = key.sign_deterministic(b"message", hashfunc=sha256)

```

From [quickstart.rst](https://ecdsa.readthedocs.io/en/latest/quickstart.html)

### Passlib

[PyPI](https://pypi.org/project/passlib) · [Docs](https://passlib.readthedocs.io/en/stable/lib/passlib.context.html)

Hashes passwords through a framework that supports over 30 schemes.

- Downloads / mo: 35.2M
- Last release: 1.7.4
- License: BSD
- Capabilities: [From the Passlib docs](https://passlib.readthedocs.io/en/stable/lib/passlib.context.html)

```sh
python3 -m pip install passlib
```

**Quickstart**

```python
from passlib.context import CryptContext
context = CryptContext(schemes=["pbkdf2_sha512"])
hash = context.hash("password")

```

From [context-tutorial.rst](https://passlib.readthedocs.io/en/stable/narr/context-tutorial.html) · [Find projects using Passlib →](https://dashboard.exa.ai/playground/search?q=passlib%20GitHub%20projects)

## FAQ

### Which Python cryptography library should I use?

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

### What is PyCryptodome?

[PyCryptodome](#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.

### What is Passlib?

[Passlib](#passlib) is a password hashing framework that selects, verifies, and migrates between many hash schemes.

### What is bcrypt in Python?

[bcrypt](#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.

### What is PyNaCl?

[PyNaCl](#pynacl) is a Python binding to libsodium with authenticated symmetric encryption, public-key signatures, and password hashing helpers.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python cryptography libraries cryptography PyCryptodome PyNaCl bcrypt encryption signatures password hashing code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
