{"id":2337,"library":"types-cryptography","title":"Typing Stubs for Cryptography","description":"This package provides static type checking stubs for the `cryptography` library, enabling tools like MyPy to verify type correctness in Python code that uses `cryptography`. It is part of the broader Typeshed project, which maintains a repository of type stubs for many popular Python libraries. As of this entry, the current version is 3.3.23.2, with updates typically following `cryptography` releases.","status":"active","version":"3.3.23.2","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","cryptography","typeshed","mypy"],"install":[{"cmd":"pip install types-cryptography","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"This package provides type hints for the `cryptography` library; `cryptography` itself must be installed to run the code you are type-checking.","package":"cryptography","optional":false}],"imports":[{"note":"Type stubs are not imported directly. Instead, they provide type information for symbols imported from the actual `cryptography` library, which type checkers consume automatically.","symbol":"Fernet","correct":"from cryptography.fernet import Fernet"}],"quickstart":{"code":"import os\nfrom cryptography.fernet import Fernet\n\n# Example usage of cryptography, for which types-cryptography provides stubs\nkey = Fernet.generate_key()\nf = Fernet(key)\n\nmessage: bytes = b\"my secret data\"\nencrypted_message: bytes = f.encrypt(message)\ndecrypted_message: bytes = f.decrypt(encrypted_message)\n\nprint(f\"Original: {message}\")\nprint(f\"Encrypted: {encrypted_message}\")\nprint(f\"Decrypted: {decrypted_message}\")\n\n# To type-check this file:\n# 1. pip install cryptography types-cryptography mypy\n# 2. mypy your_script_name.py","lang":"python","description":"This quickstart demonstrates a basic usage of the `cryptography` library. `types-cryptography` is installed to allow static type checkers like MyPy to verify the type correctness of this code. After installing `cryptography`, `types-cryptography`, and `mypy`, you can run `mypy <your_script_name>.py` to check for type errors."},"warnings":[{"fix":"Ensure both `cryptography` and `types-cryptography` are installed in your environment.","message":"`types-cryptography` only provides type hints. You *must* install the actual `cryptography` library (`pip install cryptography`) for your code to run.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always import from `cryptography` (e.g., `from cryptography.fernet import Fernet`). Type checkers will automatically discover the stubs provided by `types-cryptography`.","message":"Do not attempt to import symbols directly from `types_cryptography` or `cryptography-stubs`. This package is purely for type checkers and does not expose runtime objects. Imports should always be from `cryptography` itself.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If you encounter type errors for new `cryptography` features, check for an updated `types-cryptography` version or consider using `type: ignore` comments as a temporary workaround until stubs are released.","message":"The version of `types-cryptography` might not always be perfectly in sync with the very latest release of `cryptography`. This can occasionally lead to minor type checking errors (e.g., missing attributes for newly added features) until the stubs are updated.","severity":"gotcha","affected_versions":"All versions, especially with new `cryptography` releases"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}