{
 "kind": "tool",
 "slug": "cryptography",
 "path": "tools/cryptography/",
 "name": "cryptography",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Auth and security libraries",
   "tools/auth-security/"
  ]
 ],
 "lead": "Encrypt, sign and make certificates in Python.",
 "chips": [
  {
   "label": "Auth and security libraries",
   "path": "tools/auth-security/"
  },
  {
   "label": "PYPI"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "pip install cryptography"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/pyca/cryptography"
  },
  {
   "label": "Website",
   "href": "https://github.com/pyca/cryptography"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "Apache-2.0 OR BSD-3-Clause",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "\"license_expression\":\"Apache-2.0 OR BSD-3-Clause\"",
   "note": "Choose Apache-2.0 or BSD-3-Clause; both allow paid and closed-source products.",
   "src": "https://pypi.org/pypi/cryptography/50.0.2/json"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Nov 24, 2026",
   "note": "",
   "src": "https://github.com/pyca/cryptography"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "148 projects",
   "status": "info",
   "sub": "#4 of 141 in its category",
   "note": "Dependency in 148 public GitHub projects set up for AI coding agents that we scanned (2.4%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 10, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What cryptography does",
   "parts": [
    {
     "t": "prose",
     "text": "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."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Store secrets your app must reuse",
       "text": "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.",
       "idea": false
      },
      {
       "title": "Links that stop working",
       "text": "A password reset or invite link carries an encrypted token that your server refuses once it is older than, say, 15 minutes.",
       "idea": false
      },
      {
       "title": "Replace a key after staff changes",
       "text": "Someone who knew your encryption key leaves; you add a new key, re-encrypt stored tokens with it and then retire the old one.",
       "idea": false
      },
      {
       "title": "Encrypt with a person's passphrase",
       "text": "A notes or backup feature lets people protect their data with a passphrase they choose; the passphrase is stretched into a proper key first.",
       "idea": false
      },
      {
       "title": "Prove a message came from you",
       "text": "Your server signs an order receipt or a file, and anyone holding your public key can check that nobody changed it.",
       "idea": false
      },
      {
       "title": "Certificate for local secure testing",
       "text": "Your development server needs a certificate for localhost so you can test secure connections before going live.",
       "idea": false
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "cryptography popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "77",
       "of": "/ 100",
       "l": "Gid Score, #158 overall"
      },
      {
       "n": "316M",
       "l": "downloads a week, pypi"
      },
      {
       "n": "7,859",
       "l": "GitHub stars"
      },
      {
       "n": "148",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How cryptography is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "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%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "88 projects, 2.7%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "65 projects, 2.1%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "54 projects, 2.2%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "14 projects, 4.2%",
       "v": "OpenClaw",
       "path": "agents/openclaw/"
      },
      {
       "l": "12 projects, 2.6%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "8 projects, 1.7%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "6 projects, 1.7%",
       "v": "OpenCode",
       "path": "agents/opencode/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 66.2% of its projects",
       "v": "python-dotenv",
       "path": "tools/python-dotenv/"
      },
      {
       "l": "In 65.5% of its projects",
       "v": "Uvicorn",
       "path": "tools/uvicorn/"
      },
      {
       "l": "In 64.9% of its projects",
       "v": "Pydantic",
       "path": "tools/pydantic/"
      },
      {
       "l": "In 58.8% of its projects",
       "v": "PyYAML",
       "path": "tools/pyyaml/"
      },
      {
       "l": "In 58.1% of its projects",
       "v": "Requests",
       "path": "tools/requests-py/"
      },
      {
       "l": "In 54.1% of its projects",
       "v": "FastAPI",
       "path": "tools/fastapi/"
      },
      {
       "l": "In 45.3% of its projects",
       "v": "python-multipart",
       "path": "tools/python-multipart/"
      },
      {
       "l": "In 41.9% of its projects",
       "v": "PyJWT",
       "path": "tools/pyjwt/"
      }
     ]
    }
   ]
  },
  {
   "id": "profile",
   "nav": "Profile",
   "h2": "cryptography in practice",
   "parts": [
    {
     "t": "h3",
     "text": "Strengths"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "A short Fernet example",
       "v": "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."
      },
      {
       "l": "Recipes ask for few decisions",
       "v": "The docs say the recipes level requires \"little to no configuration choices\". They also say it does not require developers to make many decisions."
      },
      {
       "l": "Hazmat is fenced off by name",
       "v": "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.\""
      },
      {
       "l": "Recipes go past Fernet",
       "v": "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."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Watch out for"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "No external audit",
       "v": "The docs state that neither the code nor the documentation has been externally audited. They invite contact from anyone interested in discussing an audit."
      },
      {
       "l": "Hazmat expects expertise",
       "v": "The maintainers write that hazmat primitives \"require making decisions\" and in-depth knowledge of the concepts involved. They recommend the recipes layer whenever possible."
      },
      {
       "l": "Install trouble has its own FAQ entries",
       "v": "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."
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "profile",
   "h2": "More about cryptography",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Packages around it",
       "items": [
        "python-dotenv: .env file loader",
        "requests: HTTP client",
        "pydantic: data validation",
        "uvicorn: ASGI server",
        "pyyaml: YAML parser",
        "aiohttp: async HTTP client/server"
       ]
      },
      {
       "title": "More in Auth and security libraries",
       "path": "tools/auth-security/",
       "items": [
        {
         "text": "bcryptjs",
         "path": "tools/bcryptjs/"
        },
        {
         "text": "NextAuth.js",
         "path": "tools/next-auth/"
        },
        {
         "text": "jsonwebtoken",
         "path": "tools/jsonwebtoken/"
        },
        {
         "text": "jose",
         "path": "tools/jose/"
        },
        {
         "text": "Better Auth",
         "path": "tools/better-auth/"
        },
        {
         "text": "DOMPurify",
         "path": "tools/dompurify/"
        },
        {
         "text": "Helmet",
         "path": "tools/helmet/"
        },
        {
         "text": "bcrypt (JavaScript)",
         "path": "tools/bcrypt-npm/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "cryptography",
       "me": true,
       "facts": [
        "Apache-2.0 OR BSD-3-Clause",
        "Gid 77",
        "316M/wk"
       ]
      },
      {
       "name": "PyNaCl",
       "why": "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.",
       "path": "tools/pynacl/",
       "facts": []
      },
      {
       "name": "argon2-cffi",
       "why": "Pick argon2-cffi to store and check users' login passwords; it hashes them one way instead of encrypting them.",
       "path": "tools/argon2-cffi/",
       "facts": []
      },
      {
       "name": "PyJWT",
       "why": "Pick PyJWT when you need standard JSON Web Tokens for logins between services rather than private encrypted tokens.",
       "path": "tools/pyjwt/",
       "facts": [
        "MIT",
        "Gid 74",
        "176M/wk"
       ]
      },
      {
       "name": "bcrypt (Python)",
       "why": "Modern password hashing library with secure bcrypt algorithm implementation.",
       "path": "tools/bcrypt-pypi/",
       "facts": [
        "Apache-2.0",
        "Gid 66",
        "41M/wk"
       ]
      }
     ],
     "more": "Compare cryptography with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "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."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Install it into your project's Python environment (Python 3.9 or newer).",
       "code": "$ pip install cryptography",
       "src": "https://cryptography.io/en/stable/installation/"
      },
      {
       "text": "Make a key once, keep it secret, and use Fernet to encrypt and decrypt.",
       "code": ">>> from cryptography.fernet import Fernet\n>>> # Put this somewhere safe!\n>>> key = Fernet.generate_key()\n>>> f = Fernet(key)\n>>> token = f.encrypt(b\"A really secret message. Not for prying eyes.\")\n>>> token\nb'...'\n>>> f.decrypt(token)\nb'A really secret message. Not for prying eyes.'\n",
       "src": "https://github.com/pyca/cryptography/blob/main/README.rst"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Rules for your agent"
    },
    {
     "t": "rules",
     "label": "Paste into AGENTS.md or CLAUDE.md",
     "text": "## cryptography\n- Prefer the recipes layer, such as `cryptography.fernet.Fernet`, for symmetric encryption. The docs say to fall back to `cryptography.hazmat` \"only when necessary\".\n- Create Fernet keys with `Fernet.generate_key()` and keep them somewhere safe. The README example comments \"Put this somewhere safe!\"\n- Before reaching into `cryptography.hazmat`, note that the docs say these primitives \"require making decisions\" and in-depth knowledge.\n- The project supports Python 3.9+ and PyPy3 7.3.11+.\n- 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.\n- To report a security issue, consult the project's security reporting documentation.\n"
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "Building encryption from hazmat pieces (AES plus your own mode and padding) for ordinary app data",
       "fix": "Use Fernet from cryptography.fernet unless a fixed outside format forces the low-level parts",
       "why": "The low-level layer needs many correct decisions; the docs recommend the recipes layer whenever possible."
      },
      {
       "dont": "Calling Fernet.generate_key() at app start-up, or keeping the key only in memory",
       "fix": "Generate the key once, store it as a secret (FERNET_KEY in the environment) and back it up",
       "why": "A new key every start makes all stored tokens unreadable."
      },
      {
       "dont": "Fernet(password.encode()) or a padded password used as the key",
       "fix": "Derive the key with a key derivation function such as Argon2id, store the random salt, then base64-encode it for Fernet",
       "why": "Fernet expects a random 32-byte key; a password must be stretched first."
      },
      {
       "dont": "Copying the docs' Argon2id example (memory_cost=2**21) onto a small server",
       "fix": "On machines with little memory use iterations=3, memory_cost=2**16, as our demo did",
       "why": "memory_cost is in KiB, so 2**21 asks for 2 GiB per call; the docs give the low-memory setting from RFC 9106."
      },
      {
       "dont": "Encrypting a multi-gigabyte file with one Fernet call",
       "fix": "Use the Cobblestone streaming recipe (version 50+) or encrypt in separate parts",
       "why": "Fernet needs the whole message in memory."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Can I use it in a paid, closed-source app?",
       "a": "Yes. You choose between Apache 2.0 and BSD 3-clause; both allow commercial and closed-source use with the notices kept.",
       "evidence": {
        "url": "https://pypi.org/pypi/cryptography/50.0.2/json",
        "quote": "\"license_expression\":\"Apache-2.0 OR BSD-3-Clause\""
       }
      },
      {
       "q": "Should I store user login passwords with Fernet?",
       "a": "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.",
       "evidence": {
        "url": "https://cryptography.io/en/stable/hazmat/primitives/key-derivation-functions/",
        "quote": "The Argon2 family of key derivation functions are designed for password storage and is described in RFC 9106"
       }
      },
      {
       "q": "How is it different from PyNaCl?",
       "a": "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.",
       "evidence": {
        "url": "https://cryptography.io/en/stable/faq/",
        "quote": "If you prefer NaCl's design, we highly recommend PyNaCl"
       }
      },
      {
       "q": "Will updates break my code?",
       "a": "Documented functions are not removed or renamed without a compatibility alias, except when a security fix requires it.",
       "evidence": {
        "url": "https://cryptography.io/en/stable/api-stability/",
        "quote": "Public APIs will not be removed or renamed without providing a compatibility alias."
       }
      },
      {
       "q": "Is it maintained?",
       "a": "Yes. Version 50.0.2 came out on 30 September 2026, and new major versions appear every few months.",
       "evidence": {
        "url": "https://cryptography.io/en/stable/changelog/",
        "quote": "50.0.2 - 2026-09-30"
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "pypi cryptography"
  ],
  [
   "Category",
   "Auth and security libraries"
  ],
  [
   "License",
   "Apache-2.0 OR BSD-3-Clause"
  ],
  [
   "Latest version",
   "50.0.2, September 30, 2026"
  ],
  [
   "On GitHub since",
   "August 2013"
  ],
  [
   "Gid Score",
   "77.1"
  ],
  [
   "Rank in category",
   "#4 of 141"
  ],
  [
   "GitHub",
   "pyca/cryptography"
  ],
  [
   "Last change",
   "Nov 24, 2026"
  ]
 ],
 "good": [
  "If you lose a Fernet key, nothing encrypted with it can be read again; anyone who gets the key can read and forge messages.",
  "Each Fernet token shows, unencrypted, when it was made, so an attacker can see that time.",
  "Fernet works on data that fits in memory; for very large files the library added a separate streaming recipe, Cobblestone, in version 50."
 ],
 "checked_line": "Read by AgentGid from 15 official pages, card checked Nov 10, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/pyca.png"
}