Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 4 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

cryptography

Encrypt, sign and make certificates in Python.

Auth and security librariesPYPI

GitHubWebsite

1. License

“"license_expression":"Apache-2.0 OR BSD-3-Clause"”

Choose Apache-2.0 or BSD-3-Clause; both allow paid and closed-source products.

pypi.org/pypi/cryptography/50.0.2/json

From the package registry and GitHub, checked daily; card checked Nov 10, 2026. Tap a verdict to see its source.How we checkedReport an error

What cryptography does

cryptography is the main free Python library for keeping data secret and proving it was not changed. Its simple part, Fernet, locks a piece of text with a key so nobody without the key can read or alter it. It can also sign messages, turn a password into a key and create certificates for secure connections.

What people build with it

Store secrets your app must reuse

Your app saves customers' tokens for other services and needs them back later; it keeps them encrypted in the database and decrypts them only when calling out.

Links that stop working

A password reset or invite link carries an encrypted token that your server refuses once it is older than, say, 15 minutes.

Replace a key after staff changes

Someone who knew your encryption key leaves; you add a new key, re-encrypt stored tokens with it and then retire the old one.

Encrypt with a person's passphrase

A notes or backup feature lets people protect their data with a passphrase they choose; the passphrase is stretched into a proper key first.

Prove a message came from you

Your server signs an order receipt or a file, and anyone holding your public key can check that nobody changed it.

Certificate for local secure testing

Your development server needs a certificate for localhost so you can test secure connections before going live.

cryptography popularity

77 / 100
Gid Score, #158 overall
316M
downloads a week, pypi
7,859
GitHub stars
148
agent projects use it
cryptography: downloads per weekPyPI, cryptography 314,317,246
cryptography: GitHub starspyca/cryptography 7,859

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How cryptography is used

  • cryptography is a dependency in 148 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (9.1% of the 1,623 Python ones), #4 of 141 in auth and security libraries.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,374; those are left out of every share on this page.
  • The most used alternative in our scan is PyJWT (118 projects).
  • Projects that use it most often also use python-dotenv (66.2%), Uvicorn (65.5%), Pydantic (64.9%).

By coding agent

88 projects, 2.7%
65 projects, 2.1%
54 projects, 2.2%
14 projects, 4.2%
12 projects, 2.6%
8 projects, 1.7%
6 projects, 1.7%

Often used with

In 66.2% of its projects
In 65.5% of its projects
In 64.9% of its projects
In 58.8% of its projects
In 58.1% of its projects
In 54.1% of its projects
In 45.3% of its projects
In 41.9% of its projects

cryptography in practice

Strengths

A short Fernet example

The README's example generates a key with <code>Fernet.generate_key()</code>, wraps it in <code>Fernet</code>, then calls <code>encrypt</code> and <code>decrypt</code> on a byte string.

Recipes ask for few decisions

The docs say the recipes level requires "little to no configuration choices". They also say it does not require developers to make many decisions.

Hazmat is fenced off by name

The low-level primitives sit in their own <code>cryptography.hazmat</code> package. The docs say their documentation "will always contain an admonition at the top."

Recipes go past Fernet

The recipes section of the table of contents also lists Cobblestone streaming symmetric encryption in 128- and 256-bit encryptor and decryptor variants. It also lists X.509 pages on Certificate Transparency, OCSP and X.509 Verification.

Watch out for

No external audit

The docs state that neither the code nor the documentation has been externally audited. They invite contact from anyone interested in discussing an audit.

Hazmat expects expertise

The maintainers write that hazmat primitives "require making decisions" and in-depth knowledge of the concepts involved. They recommend the recipes layer whenever possible.

Install trouble has its own FAQ entries

The FAQ list includes entries titled for installs that fail with OpenSSL older than 3.0.0, for a missing Rust compiler, and for errors installing or importing on AWS Lambda.

More about cryptography

Packages around it
  • python-dotenv: .env file loader
  • requests: HTTP client
  • pydantic: data validation
  • uvicorn: ASGI server
  • pyyaml: YAML parser
  • aiohttp: async HTTP client/server
More in Auth and security libraries

Alternatives

cryptography This page

Apache-2.0 OR BSD-3-ClauseGid 77316M/wk

PyNaCl

Pick PyNaCl if you prefer a small set of fixed, hand-picked algorithms; the cryptography FAQ recommends it for that and the same team maintains it.

argon2-cffi

Pick argon2-cffi to store and check users' login passwords; it hashes them one way instead of encrypting them.

PyJWT

Pick PyJWT when you need standard JSON Web Tokens for logins between services rather than private encrypted tokens.

MITGid 74176M/wk

bcrypt (Python)

Modern password hashing library with secure bcrypt algorithm implementation.

Apache-2.0Gid 6641M/wk

Compare cryptography with another tool

Get started

Tell your AI assistant

“Use the Python package cryptography (pin cryptography==50.0.2, Python 3.9+) and its Fernet recipe to encrypt the stored tokens; read the key from the FERNET_KEY environment variable, never hard-code it, and catch InvalidToken.”

  1. Install it into your project's Python environment (Python 3.9 or newer).

    $ pip install cryptography

    From cryptography.io/en/stable/installation/

  2. Make a key once, keep it secret, and use Fernet to encrypt and decrypt.

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

    From github.com/pyca/cryptography/blob/main/README.rst

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## cryptography
- Prefer the recipes layer, such as `cryptography.fernet.Fernet`, for symmetric encryption. The docs say to fall back to `cryptography.hazmat` "only when necessary".
- Create Fernet keys with `Fernet.generate_key()` and keep them somewhere safe. The README example comments "Put this somewhere safe!"
- Before reaching into `cryptography.hazmat`, note that the docs say these primitives "require making decisions" and in-depth knowledge.
- The project supports Python 3.9+ and PyPy3 7.3.11+.
- Install with `pip install cryptography` or `uv add cryptography`. If the install fails, check the FAQ entries on the Rust compiler and on OpenSSL older than 3.0.0.
- To report a security issue, consult the project's security reporting documentation.

Mistakes to avoid

Building encryption from hazmat pieces (AES plus your own mode and padding) for ordinary app data
Use Fernet from cryptography.fernet unless a fixed outside format forces the low-level parts

The low-level layer needs many correct decisions; the docs recommend the recipes layer whenever possible.

Calling Fernet.generate_key() at app start-up, or keeping the key only in memory
Generate the key once, store it as a secret (FERNET_KEY in the environment) and back it up

A new key every start makes all stored tokens unreadable.

Fernet(password.encode()) or a padded password used as the key
Derive the key with a key derivation function such as Argon2id, store the random salt, then base64-encode it for Fernet

Fernet expects a random 32-byte key; a password must be stretched first.

Copying the docs' Argon2id example (memory_cost=2**21) onto a small server
On machines with little memory use iterations=3, memory_cost=2**16, as our demo did

memory_cost is in KiB, so 2**21 asks for 2 GiB per call; the docs give the low-memory setting from RFC 9106.

Encrypting a multi-gigabyte file with one Fernet call
Use the Cobblestone streaming recipe (version 50+) or encrypt in separate parts

Fernet needs the whole message in memory.

Questions

Can I use it in a paid, closed-source app?

Yes. You choose between Apache 2.0 and BSD 3-clause; both allow commercial and closed-source use with the notices kept.

Should I store user login passwords with Fernet?

No. Fernet can be undone with the key. Login passwords should go through a slow one-way function such as Argon2, which the docs describe as designed for password storage.

How is it different from PyNaCl?

cryptography is a general-purpose library that works with existing systems; PyNaCl offers a smaller, hand-picked set of algorithms and is made by the same team.

Will updates break my code?

Documented functions are not removed or renamed without a compatibility alias, except when a security fix requires it.

Is it maintained?

Yes. Version 50.0.2 came out on 30 September 2026, and new major versions appear every few months.