Stage 02 · Test · Researched comparison
Best Python Cryptography Libraries in 2026
The `cryptography` package is the first pick for most teams. It covers symmetric encryption, hashing, key derivation, X.509 certificates and signing behind one maintained API. Choose PyNaCl when you want a small, opinionated set of high-level primitives such as secret-key encryption and signatures. Choose PyCryptodome when you need a wide catalog of legacy and low-level ciphers, or a drop-in replacement for code written against the old PyCrypto API.
By Shihab Mia
Published 27 Nov 2026 · 7 tools compared
We run no ads and no affiliate links at launch. The order of a list follows our published method. See how we score.
Prices are the starting prices vendors list publicly. Plans change, so confirm the current price on the vendor page before you buy.
Key takeaways
- `cryptography` is open source, actively maintained, and the common dependency behind many other Python security packages.
- PyNaCl wraps libsodium and exposes fewer, safer primitives; PyCryptodome exposes many ciphers plus PyCrypto-compatible module names.
- `hashlib`, `hmac` and `secrets` ship with Python, so hashing and token generation need no third-party install.
- argon2-cffi handles password hashing only; use it alongside an encryption library, not instead of one.
Who each pick is for
- General-purpose encryption, signing and certificate workcryptography
- High-level encryption and signatures via libsodiumPyNaCl
- Wide cipher catalog and PyCrypto-compatible module namesPyCryptodome
- Hashing, message authentication and key derivation without extra installshashlib and hmac (Python standard library)
- Generating tokens, passwords and nonces with a secure random sourcesecrets (Python standard library)
- Password hashing with Argon2idargon2-cffi
- OpenSSL bindings with a long history in Python projectsM2Crypto
Comparison
| Tool | Best for | Standout feature | Listed starting price | Free plan or trial |
|---|---|---|---|---|
| 1cryptography | General-purpose encryption, signing and certificate work | Broad API covering symmetric, asymmetric and X.509 | Free (open source) | Free plan |
| 2PyNaCl | High-level encryption and signatures via libsodium | Small, curated API built on libsodium | Free (open source) | Free plan |
| 3PyCryptodome | Wide cipher catalog and PyCrypto-compatible module names | Large set of ciphers, modes and protocols | Free (open source) | Free plan |
| 4hashlib and hmac (Python standard library) | Hashing, message authentication and key derivation without extra installs | Ships with Python, no dependency to audit | Free (open source) | Free plan |
| 5secrets (Python standard library) | Generating tokens, passwords and nonces with a secure random source | Ships with Python | Free (open source) | Free plan |
| 6argon2-cffi | Password hashing with Argon2id | Implements the Argon2 password hashing standard | Free (open source) | Free plan |
| 7M2Crypto | OpenSSL bindings with a long history in Python projects | Direct OpenSSL bindings covering certificates, TLS and crypto primitives | Free (open source) | Free plan |
How we picked
We picked libraries that are currently maintained, have a public repository or documentation site, and genuinely cover a distinct part of the Python crypto job. Criteria were fit for the task (encryption, signing, hashing, password storage, random generation), platform and interpreter support, licence and price, and the main limits a developer will hit. Sources are vendor documentation, project repositories and public pricing pages; all listed projects are free and open source. Prices and maintenance status change, so confirm details on the project site before you commit.
The tools, one by one
cryptography
Best for general-purpose encryption, signing and certificate work

What it is and where it fits
The `cryptography` project provides both a high-level recipes layer and a low-level hazmat layer. The high-level side covers Fernet symmetric encryption, key derivation and X.509 certificate building and parsing. The hazmat layer exposes ciphers, padding modes, HMAC and signature primitives for teams that need direct control. It runs on CPython and PyPy across Linux, macOS and Windows, and publishes binary wheels so most installs need no compiler.
It is licensed under Apache-2.0 and dual BSD, with no paid tier. The main limit is that the hazmat layer does not protect you from misuse: you must pick correct modes, unique nonces and adequate key sizes yourself. Teams that want a smaller surface area and fewer choices should look at PyNaCl instead. Teams that need ciphers this package does not expose should check PyCryptodome.
Standout: Broad API covering symmetric, asymmetric and X.509
Free (open source), as listed by the vendor (cryptography website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Broad API covering symmetric, asymmetric and X.509
- backed by OpenSSL with a Rust layer
- actively maintained
Drawbacks
- Large dependency footprint
- low-level recipes require care with nonces and key handling
Skip it if this limit matters to you: large dependency footprint.
Verdict. A sensible pick for general-purpose encryption, signing and certificate work.
Alternatives in this guide: PyNaCl, PyCryptodome, hashlib and hmac (Python standard library)
PyNaCl
Best for high-level encryption and signatures via libsodium

What it is and where it fits
PyNaCl is a Python binding to libsodium. It exposes a deliberately narrow set of primitives: secret-key authenticated encryption, public-key encryption, signatures, password hashing and key exchange. Because the API is small, there are fewer ways to combine parameters incorrectly. It runs wherever libsodium is available, including Linux, macOS and Windows, and ships wheels for common platforms.
The project is Apache-2.0 licensed with no paid tier. The trade-off is coverage: if you need AES modes, X.509 certificates or legacy ciphers, PyNaCl will not help, and you should use `cryptography` or PyCryptodome. It also depends on the libsodium shared library, which matters for minimal container images and some serverless runtimes. It suits application developers who want encryption and signing without choosing modes and padding.
Standout: Small, curated API built on libsodium
Free (open source), as listed by the vendor (PyNaCl website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Small, curated API built on libsodium
- safe defaults for secret-key encryption and signatures
Drawbacks
- Fewer algorithms than larger libraries
- requires the libsodium system library
Skip it if this limit matters to you: fewer algorithms than larger libraries.
Verdict. A sensible pick for high-level encryption and signatures via libsodium.
Alternatives in this guide: cryptography, PyCryptodome, hashlib and hmac (Python standard library)
PyCryptodome
Best for wide cipher catalog and PyCrypto-compatible module names

What it is and where it fits
PyCryptodome is a self-contained package of cryptographic primitives. It covers block and stream ciphers, hash functions, MACs, public-key algorithms, key derivation and protocol helpers. It installs as a standalone package and does not require OpenSSL, which helps on platforms where system libraries are hard to control. It runs on CPython and PyPy across the major desktop and server platforms.
The licence is public domain with some BSD-licensed parts, and there is no paid tier. The package intentionally keeps module names compatible with the discontinued PyCrypto, which eases migration of old code. That compatibility is also the main risk: old code may use weak defaults, and the broad catalog makes it easy to select an outdated algorithm. New projects that only need common primitives are usually better served by `cryptography` or PyNaCl.
Standout: Large set of ciphers, modes and protocols
Free (open source), as listed by the vendor (PyCryptodome website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Large set of ciphers, modes and protocols
- drop-in module names for older PyCrypto code
Drawbacks
- Wider API means more room for misuse
- some legacy algorithms are easy to pick by mistake
Skip it if this limit matters to you: wider API means more room for misuse.
Verdict. A sensible pick for wide cipher catalog and PyCrypto-compatible module names.
Alternatives in this guide: cryptography, PyNaCl, hashlib and hmac (Python standard library)
hashlib and hmac (Python standard library)
Best for hashing, message authentication and key derivation without extra installs

What it is and where it fits
The `hashlib` module provides hash functions such as SHA-256 and SHA-512, plus key derivation helpers including scrypt and PBKDF2. The `hmac` module builds message authentication codes on top of it. Both ship with every standard CPython install, so there is nothing to add to your dependency list. The module is part of Python and licensed under the Python Software Foundation License.
The limit is scope. Hashing and MACs are useful for integrity checks, password storage (with a proper KDF) and key derivation, but they do not encrypt data or produce signatures. Which algorithms are available depends on the OpenSSL build behind your interpreter, so check `hashlib.algorithms_available` on your target platforms. For password storage specifically, argon2-cffi is a stronger default than PBKDF2. For encryption, pair this with `cryptography` or PyNaCl.
Standout: Ships with Python, no dependency to audit
Free (open source), as listed by the vendor (hashlib and hmac (Python standard library) website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Ships with Python, no dependency to audit
- wraps OpenSSL-backed hash functions
Drawbacks
- Hashing only, no encryption or signatures
- available algorithms depend on the OpenSSL build
Skip it if this limit matters to you: hashing only, no encryption or signatures.
Verdict. A sensible pick for hashing, message authentication and key derivation without extra installs.
Alternatives in this guide: cryptography, PyNaCl, PyCryptodome
secrets (Python standard library)
Best for generating tokens, passwords and nonces with a secure random source

What it is and where it fits
The `secrets` module generates random numbers suitable for managing secrets: tokens, passwords, nonces and reset codes. It is built for security use, unlike the `random` module, which is not suitable for anything security-related. It ships with Python 3.6 and later and needs no install. It is part of the standard library under the PSF License.
Its job is narrow. Use it to create API tokens, session identifiers and nonces that you then feed into an encryption library. It does not encrypt, hash or sign anything by itself. A common mistake is reaching for `random` when generating tokens; `secrets` is the correct choice. Combine it with `cryptography` or PyNaCl for the actual encryption work, and with argon2-cffi for password storage.
Standout: Ships with Python
Free (open source), as listed by the vendor (secrets (Python standard library) website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Ships with Python
- uses the OS random source suitable for security tokens
Drawbacks
- Random generation only
- not a substitute for an encryption library
Skip it if this limit matters to you: random generation only.
Verdict. A sensible pick for generating tokens, passwords and nonces with a secure random source.
Alternatives in this guide: cryptography, PyNaCl, PyCryptodome
argon2-cffi
Best for password hashing with Argon2id
What it is and where it fits
argon2-cffi provides Argon2 password hashing, including the Argon2id variant recommended for password storage. The API is small: hash a password, get a string that encodes the parameters and salt, then verify later. It runs on CPython and PyPy across the main platforms and ships wheels for common environments. The project is MIT licensed with no paid tier.
The main limit is scope: it hashes passwords and nothing else. You still need an encryption library for data at rest and in transit. The other consideration is parameter tuning. Argon2 lets you set memory cost, time cost and parallelism, and the right values depend on your hardware and latency budget. Test on your production class of machine before locking values in. Teams that only need a quick KDF can use PBKDF2 from `hashlib`, but Argon2id is the stronger default for new password storage.
Standout: Implements the Argon2 password hashing standard
Free (open source), as listed by the vendor (argon2-cffi website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Implements the Argon2 password hashing standard
- simple hash and verify API
Drawbacks
- Password hashing only
- tuning memory and time costs needs care
Skip it if this limit matters to you: password hashing only.
Verdict. A sensible pick for password hashing with Argon2id.
Alternatives in this guide: cryptography, PyNaCl, PyCryptodome
M2Crypto
Best for openSSL bindings with a long history in Python projects

What it is and where it fits
M2Crypto wraps OpenSSL for Python and has been used for years in projects that need certificate handling, TLS and low-level crypto access. It exposes RSA, DSA, DH, HMAC, ciphers and X.509 objects, plus SSL/TLS context handling. It runs on CPython, mainly on Linux and other Unix-like systems, and typically builds against the system OpenSSL.
The licence is a BSD-style MIT licence with no paid tier. The practical limits are maintenance pace and build friction: you may need OpenSSL development headers, and wheel coverage is narrower than for `cryptography`. For new code that needs certificates or TLS, `cryptography` is usually the simpler choice. M2Crypto remains relevant for existing codebases and for teams that specifically want direct OpenSSL bindings rather than an abstraction layer.
Standout: Direct OpenSSL bindings covering certificates, TLS and crypto primitives
Free (open source), as listed by the vendor (M2Crypto website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Direct OpenSSL bindings covering certificates, TLS and crypto primitives
- mature codebase
Drawbacks
- Smaller maintainer base than mainstream options
- build can depend on system OpenSSL headers
Skip it if this limit matters to you: smaller maintainer base than mainstream options.
Verdict. A sensible pick for openSSL bindings with a long history in Python projects.
Alternatives in this guide: cryptography, PyNaCl, PyCryptodome
Who should use what
If you are building a typical web service and need encryption, signing and certificates, start with `cryptography`. If you want a small API with safe defaults and do not need X.509, use PyNaCl. If you are migrating old PyCrypto code or need a specific cipher, use PyCryptodome. For password storage, add argon2-cffi regardless of which encryption library you pick, and use `secrets` for token generation. Hashing and MACs alone can come from `hashlib` and `hmac` with no extra dependency.
Questions to settle before you buy
What to check before you buy
- Confirm the library is actively maintained and has releases in the last year.
- Check that it publishes wheels for your Python version and target platform.
- Verify the algorithms you need are exposed at the level you want (high-level recipe vs low-level primitive).
- Review how keys, nonces and salts are generated and stored in your design.
- For password storage, confirm the library supports Argon2id and lets you tune memory and time cost.
FAQ
Which Python cryptography library should a new project use?
Start with `cryptography`. It covers symmetric and asymmetric encryption, signing, key derivation and X.509 certificates under one maintained API, and it is the dependency behind many other Python security packages. Add argon2-cffi for password hashing and use `secrets` for token generation.
Is PyNaCl a replacement for cryptography?
No. PyNaCl wraps libsodium and exposes a smaller set of high-level primitives. It is a good fit when you want fewer choices and safe defaults, but it does not cover X.509 certificates or the broad cipher catalog that `cryptography` and PyCryptodome provide.
Can I use hashlib for encryption?
No. `hashlib` provides hash functions and key derivation helpers, not encryption. Use it for integrity checks, MACs and KDFs, and pair it with an encryption library such as `cryptography` or PyNaCl for confidentiality.
Is PyCryptodome the same as PyCrypto?
No. PyCrypto is discontinued. PyCryptodome is a separate, maintained package that keeps module names compatible with PyCrypto to ease migration. Review old code for weak defaults when you move it over.
Do these libraries send my data anywhere?
These are local libraries that run in your process. They do not send keys or plaintext to a vendor. The privacy risk is in your own code: keep keys out of logs, source control and error messages, and avoid pasting secrets into third-party web tools.
Sources we checked
Method: how we score · editorial policy.
Change log. First published 27 Nov 2026.