This library provides PEP 561 type stubs for the popular `PyJWT` library, which is commonly imported as `jwt`. It enables static type checkers like MyPy, PyCharm, and Pyright to analyze code that uses `PyJWT`. `types-jwt` is part of the `typeshed` project, which centrally manages type definitions for many third-party Python packages. `types-jwt` version 0.1.3 was released in May 2021. However, it's important to note that since `PyJWT` version 2.0.0 (released December 2020) and later include their own inline type annotations, `types-jwt` is primarily relevant for projects using older versions of `PyJWT` (pre-2.0.0) or specific legacy setups.
pip install types-jwtVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to encode and decode a JSON Web Token using the `PyJWT` library, for which `types-jwt` provides type annotations. The example includes setting an expiration time and handling basic decoding errors. Ensure you have `PyJWT` installed for this code to run. While `types-jwt` itself is not directly imported, its presence allows type checkers to provide richer feedback on `jwt` module usage. For production, always use robust, securely generated secret keys and appropriate algorithms.
If using `PyJWT >= 2.0.0`, uninstall `types-jwt`: `pip uninstall types-jwt`. Rely on `PyJWT`'s built-in type hints.
Ensure both `types-jwt` (for type checking) and `PyJWT` (for runtime functionality) are installed: `pip install types-jwt PyJWT`.
Always import from `jwt` (the runtime library) and *never* from `types_jwt` in your Python code: `import jwt`.