python-jose is an active Python library implementing the JSON Object Signing and Encryption (JOSE) standards, including JSON Web Signature (JWS), JSON Web Encryption (JWE), JSON Web Key (JWK), JSON Web Algorithms (JWA), and JSON Web Tokens (JWT). Currently at version 3.5.0, it maintains a regular release schedule with significant updates to Python version support and cryptographic backends.
pip install python-joseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates encoding and decoding a JSON Web Token (JWT) using a symmetric (HS256) algorithm. For asymmetric algorithms (like RS256), you would use public/private key pairs instead of a shared secret. Ensure `JWT_SECRET_KEY` is set securely in your environment for production use.
Upgrade to a supported Python version (3.9+ for python-jose 3.5.0).
Always install with `pip install python-jose[cryptography]` for production environments to ensure optimal performance and security. Review your installed dependencies to confirm `cryptography` is active.
Upgrade to `python-jose` version 3.4.0 or higher immediately to patch critical security vulnerabilities.
Upgrade to `python-jose` 3.4.0+ to avoid `datetime.utcnow()` deprecation warnings and ensure future compatibility.
Review code for direct access to backend-specific utilities like `get_random_bytes` or reliance on `JWKError` message specifics. Adapt to the new behavior or use standard `os.urandom` if random bytes are needed.
Evaluate your project's specific needs for JOSE implementation. If long-term maintenance, broader community support, or specific advanced features are critical, consider alternatives like `PyJWT` or `joserfc` (from Authlib), which may offer different API structures.
Ensure the correct secret key (or public key for asymmetric algorithms) is provided to `jose.jwt.decode`, and that the token is valid and untampered.
When decoding, explicitly pass the token's algorithm in the `algorithms` list: `jose.jwt.decode(token, key, algorithms=['HS256'])`.
Install the necessary backend for `python-jose`: `pip install "python-jose[cryptography]"`.
Install the library using pip: `pip install python-jose`.