types-jwcrypto provides static type annotations for the jwcrypto library, enabling type checkers like Mypy and Pyright to validate code that uses jwcrypto. jwcrypto is a Python implementation of the JOSE (Javascript Object Signing and Encryption) Web Standards, including JWK, JWS, JWE, and JWT, and leverages the Cryptography package for its cryptographic operations. This stub package is part of the typeshed project and is released automatically, often daily. The current version is 1.5.7.20260409, targeting jwcrypto==1.5.*.
pip install types-jwcrypto jwcryptoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to generate a symmetric key, create claims, sign a JSON Web Token (JWT) using that key, serialize it into its compact form, and then deserialize and validate it. For asymmetric keys (RSA, EC), the key generation and signing steps would differ slightly, requiring separate public/private key components.
Explicitly set the `expect_type` argument (e.g., `jwt.JWT(jwt=token_str, key=public_key, expect_type='JWS')`) or ensure your application handles the new validation exceptions. Refactor code to avoid relying on implicit type detection.
Avoid using `RSA1_5` for encryption or signing. Migrate to more secure algorithms like `RSA-OAEP` for encryption or `RSASSA-PSS` for signing, which are generally recommended by the JOSE standards.
Upgrade the underlying `jwcrypto` library to version 1.5.6 or higher. The `types-jwcrypto` package targets `jwcrypto==1.5.*`, so ensuring `jwcrypto` is updated within that minor version range is crucial.
It is best practice to keep the version of `types-jwcrypto` synchronized with the minor version of your `jwcrypto` dependency. Pin your `types-jwcrypto` dependency to match the `jwcrypto` minor version (e.g., `types-jwcrypto~=1.5.0` if `jwcrypto~=1.5.0`) and regularly update both, verifying with your type checker.