Install & Compatibility
Where this runs
tested against v3.3.23.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Fernet
✓ from cryptography.fernet import Fernet
✗ from cryptography-stubs.fernet import Fernet
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.
import os
from cryptography.fernet import Fernet
# Example usage of cryptography, for which types-cryptography provides stubs
key = Fernet.generate_key()
f = Fernet(key)
message: bytes = b"my secret data"
encrypted_message: bytes = f.encrypt(message)
decrypted_message: bytes = f.decrypt(encrypted_message)
print(f"Original: {message}")
print(f"Encrypted: {encrypted_message}")
print(f"Decrypted: {decrypted_message}")
# To type-check this file:
# 1. pip install cryptography types-cryptography mypy
# 2. mypy your_script_name.py
Debug
Known issues
gotcha`types-cryptography` only provides type hints. You *must* install the actual `cryptography` library (`pip install cryptography`) for your code to run.fixEnsure both `cryptography` and `types-cryptography` are installed in your environment.
affects: All versions
gotchaDo 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.fixAlways import from `cryptography` (e.g., `from cryptography.fernet import Fernet`). Type checkers will automatically discover the stubs provided by `types-cryptography`.
affects: All versions
gotchaThe 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.fixIf 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.
affects: All versions, especially with new `cryptography` releases
Upgrade
Version history
3.3.23.2latest on PyPI · released Nov 8, 2022
Audit
Dependencies
cryptographyrequiredThis package provides type hints for the `cryptography` library; `cryptography` itself must be installed to run the code you are type-checking.