cryptography: a Fernet recipe on top of seven Rust crates and OpenSSL bindings
cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.
At a glance
- What is it?
- cryptography is the Python Cryptographic Authority's package for cryptographic recipes and primitives, and the README's whole argument is that it should be your cryptographic standard library. Behind the Fernet example is a Rust extension built with maturin and pyo3's stable ABI, an OpenSSL binding, a documented minimum Rust version, and three licence files under an OR expression.
- Who is it for?
- cryptography suits a Python project that wants symmetric encryption, message digests, key derivation or X.509 handling from one maintained package rather than from a binding to a system library you have to install separately. It does not suit a project on Python 3.8 or older, since the floor is 3.9 with PyPy3 7.3.11 as the alternative, and a source build needs a Rust toolchain.
- Can I use it commercially?
- Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
- Is it still maintained?
- Yes. The repository received new commits within the last day.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.
Star history
- pyca/cryptography7,850 ★ · +72
| Repository | 2026-09-22 | 2026-11-15 |
|---|---|---|
| pyca/cryptography | 7.8k | 7.9k |
72 Stars in the last 54 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Two layers in one package, and the README only demos the top one
The README's claim is that cryptography provides cryptographic recipes and primitives to Python developers, and that the goal is for it to be your cryptographic standard library. It supports Python 3.9+ and PyPy3 7.3.11+.
The two layers are named explicitly. It includes both high level recipes and low level interfaces to common cryptographic algorithms such as symmetric ciphers, message digests, and key derivation functions.
Everything in the README's example is the high level half. Nothing in those four lines touches a cipher directly: you generate a key through a named class, construct an object from the key, and encrypt. The low level half, which is the part where you choose an algorithm and handle IVs and padding yourself, is mentioned and not shown.
That distinction is the one to keep when you evaluate it. The recipes are opinionated and safe by default; the primitives give you the algorithm's surface and put the choices back in your hands.
The Fernet example carries a comment about where the key goes
The example is four statements and one warning:
>>> from cryptography.fernet import Fernet
>>> # Put this somewhere safe!
>>> key = Fernet.generate_key()
>>> f = Fernet(key)
>>> token = f.encrypt(b"A really secret message. Not for prying eyes.")
>>> token
b'...'
>>> f.decrypt(token)
b'A really secret message. Not for prying eyes.'The comment is on the line that generates the key, and it is the sentence that matters most in the whole README. `Fernet.generate_key()` produces a symmetric key, the object `f` is useless to anyone without it, and the token in between is ciphertext.
So the API is the easy part and the key management is the hard part. A key that lives next to the ciphertext, in a source file or an environment variable committed by accident, gives you encryption with none of the protection. The example shows the mechanism in four lines because the mechanism is small, and the comment is there because the mechanism is not the job.
Notice also that Fernet takes bytes, not str, in both directions.
pip install cryptography hides a maturin build with four pinned exclusions
The installation line is one command:
$ pip install cryptographyWhat runs behind it is in pyproject.toml. The build backend is maturin, with a requirement of `maturin>=1.14.1,<2`, and the build also needs `cffi>=2.0.0` on any implementation that is not PyPy, `cffi>=2.1.1` on Python 3.15 and newer, and a setuptools with four versions excluded:
"setuptools!=74.0.0,!=74.1.0,!=74.1.1,!=74.1.2",The comment above those requirements explains why: cffi imports distutils, distutils was removed from the standard library in Python 3.12, and installing setuptools puts it back. The requirements are also required to stay in sync with the files under `.github/requirements/`.
This is the practical difference between `pip install cryptography` and building it yourself. pip install needs a Rust toolchain only if no wheel matches your platform, and the pins above are what a source build has to satisfy.
Seven Rust crates, pyo3 with abi3, and an MSRV stated in the manifest
The Cargo workspace names its members, and the list is the internal architecture:
members = [
"src/rust/",
"src/rust/cryptography-cffi",
"src/rust/cryptography-crypto",
"src/rust/cryptography-keepalive",
"src/rust/cryptography-key-parsing",
"src/rust/cryptography-openssl",
"src/rust/cryptography-x509",
"src/rust/cryptography-x509-verification",
]So the primitives, the C FFI bridge, key parsing, the X.509 handling and its verification are separate crates. The Python binding is pyo3 at version 0.29 with the `abi3` and `abi3t` features, which is how the extension is built against the stable ABI rather than against one CPython version.
Two numbers in the workspace are worth copying. `rust-version = "1.83.0"` is labelled in the file as the MSRV, the minimum supported Rust version, and the release profile sets `overflow-checks = true`, which keeps arithmetic overflow checks in release builds of this crate.
Edition is 2021 and `publish = false`, so the workspace is not published to a Rust registry; it exists to build the Python extension.
Three licence files and an OR, which is a choice about how you adopt it
The manifest declares `license = "Apache-2.0 OR BSD-3-Clause"` and lists three files:
license-files = [ "LICENSE", "LICENSE.APACHE", "LICENSE.BSD" ]The Cargo workspace repeats the same expression, so the Python and Rust sides agree.
An OR between two licences is a choice for the user rather than a restriction: you pick which of the two terms you will comply with.
One piece of repository housekeeping contradicts that: the repository metadata does not resolve a licence identifier for this project, so a tool reading the GitHub API instead of the manifest gets nothing, while a tool reading pyproject.toml or Cargo.toml gets the expression above. If you are satisfying a compliance process, read the files.
The authors field is The Python Cryptographic Authority and individual contributors, with [email protected] as the contact.
vectors/ and noxfile.py are how the project argues correctness
The repository root is short and three of its entries are about verification rather than code.
`vectors/` is a directory for cryptographic test vectors, which is how a library checks that its output matches published or cross-implementation values rather than matching itself.
`noxfile.py` is the session runner, which is how a project that must test several Python versions and build configurations without a bespoke script harness does it. Alongside it, `ci-constraints-requirements.txt` holds the pinned constraint set for continuous integration, and `release.py` is the release script, which matters because the repository has no GitHub releases: the package reaches users through PyPI, and the badge at the top of the README points at the PyPI version.
Then there is `CHANGELOG.rst` for the version history, `docs/` with `.readthedocs.yml` for the documentation build, and three contribution files: `CONTRIBUTING.rst`, `AGENTS.md` and `CLAUDE.md`.
Security reports do not go to the issue tracker. The README routes them to a separate security reporting page, and points bugs to the issue tracker, development discussion to the cryptography-dev mailing list, and questions to `#pyca` on irc.libera.chat.
51.0.0-dev1 in Python and 0.51.0-dev1 in Rust, and no releases on GitHub
The version appears twice with different formats. pyproject.toml declares `version = "51.0.0-dev1"` and the Cargo workspace declares `version = "0.51.0-dev1"`.
Both are development versions, which means the tree you clone is a pre-release state.
There are no GitHub releases, so the tags are not the distribution record. The package is published to PyPI, the README's first badge is the PyPI version, and the version history is `CHANGELOG.rst`.
The last push to main was on 2026-11-02, so the branch is being worked on, and the version being worked towards is 51.
The declared classifiers give the supported surface: Development Status 5 - Production/Stable, Python 3 Only, Python 3.9 through 3.12 and later versions, on MacOS, POSIX, BSD, Linux and Windows. A CPython 3.8 environment is outside that list.
Editorial conclusion
cryptography suits a Python project that wants symmetric encryption, message digests, key derivation or X.509 handling from one maintained package rather than from a binding to a system library you have to install separately. It does not suit a project on Python 3.8 or older, since the floor is 3.9 with PyPy3 7.3.11 as the alternative, and a source build needs a Rust toolchain. Verify three things before you depend on it: which Python versions you actually support against the declared 3.9 and newer floor, whether the build can reach a package index for its pinned cffi and setuptools versions, and which licence you are relying on, since the project is dual licensed under Apache-2.0 or BSD-3-Clause with three licence files in the repository root.
Frequently asked questions
how to use cryptography library in python
cryptography provides both high level recipes and low level interfaces to common algorithms such as symmetric ciphers, message digests and key derivation functions. The README's high level example uses Fernet: `from cryptography.fernet import Fernet`, then `key = Fernet.generate_key()`, `f = Fernet(key)`, `f.encrypt(b"...")` and `f.decrypt(token)`, with the note that the generated key must go somewhere safe.
how to install cryptography in python
Run `pip install cryptography`. The project supports Python 3.9 and newer, or PyPy3 7.3.11 and newer. A source build uses maturin as the build backend, so it needs a Rust toolchain as well as cffi and a setuptools version that is not one of the four excluded releases.
how to install cryptography package in python
The published package installs with `pip install cryptography`, and the README points to the installation documentation for full details. When you build from source, pyproject.toml also requires `maturin>=1.14.1,<2`, `cffi>=2.0.0` outside PyPy, `cffi>=2.1.1` on Python 3.15 and newer, and a setuptools that is not 74.0.0, 74.1.0, 74.1.1 or 74.1.2, because cffi imports distutils, which Python 3.12 removed from the standard library.
how to install cryptography fernet in python
Fernet ships inside the cryptography package, so there is nothing separate to install. Install cryptography with `pip install cryptography` and import it directly with `from cryptography.fernet import Fernet`, then generate a key with `Fernet.generate_key()` and keep it somewhere safe, since the ciphertext is unreadable without it.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/pyca-cryptography)Star history chart for your README
[](https://hysenlabs.com/projects/pyca-cryptography)Was this useful?