{"id":9379,"library":"types-pyjwt","title":"Type Stubs for PyJWT","description":"types-pyjwt is a PEP 561 compliant type stub package providing static type annotations for the PyJWT library. It enables type-checking tools like MyPy, Pyright, and PyCharm to perform static analysis on code using PyJWT. The package itself is auto-generated from the community-maintained typeshed repository. As of PyPI version 1.7.1, it has not seen updates since mid-2021, as the upstream PyJWT library started including its own type annotations from version 2.0.0 onwards.","status":"deprecated","version":"1.7.1","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed/tree/master/stubs/PyJWT","tags":["typing","stubs","pyjwt","type-checking","mypy","pyright"],"install":[{"cmd":"pip install types-pyjwt","lang":"bash","label":"Install types-pyjwt"}],"dependencies":[{"reason":"This package provides type stubs for the PyJWT library. It is designed to be used alongside PyJWT versions older than 2.0.0.","package":"PyJWT","optional":false}],"imports":[{"note":"types-pyjwt does not provide runtime objects to import directly. It provides type hints for the `jwt` module from the actual `PyJWT` library. Imports should always be from `jwt`.","symbol":"jwt","correct":"import jwt\nfrom jwt import PyJWT, decode, encode"}],"quickstart":{"code":"import jwt\nfrom typing import Dict, Any\n\ndef create_and_decode_token(payload: Dict[str, Any], secret: str) -> Dict[str, Any]:\n    # This example assumes PyJWT < 2.0.0 would use types-pyjwt for type hints.\n    # For PyJWT >= 2.0.0, the types are bundled.\n    encoded_jwt = jwt.encode(payload, secret, algorithm=\"HS256\")\n    decoded_payload = jwt.decode(encoded_jwt, secret, algorithms=[\"HS256\"])\n    return decoded_payload\n\nif __name__ == \"__main__\":\n    my_payload = {\"user_id\": 123, \"name\": \"test_user\"}\n    jwt_secret = \"super-secret-key\"\n    \n    # Run a type checker like MyPy on this file to see types-pyjwt in action (if PyJWT < 2.0.0)\n    # Or, if PyJWT >= 2.0.0, to see PyJWT's bundled types.\n    result = create_and_decode_token(my_payload, jwt_secret)\n    print(f\"Decoded payload: {result}\")\n    # Expected output for type checking (e.g., with mypy): No issues if types are correctly applied.","lang":"python","description":"This quickstart demonstrates a basic usage of PyJWT with type hints. When types-pyjwt is installed alongside PyJWT (specifically PyJWT versions prior to 2.0.0), a static type checker would use the stubs from `types-pyjwt` to validate the types in this code. For PyJWT versions 2.0.0 and newer, PyJWT includes its own `py.typed` file and inline annotations, making `types-pyjwt` unnecessary and potentially problematic."},"warnings":[{"fix":"Uninstall `types-pyjwt`: `pip uninstall types-pyjwt`","message":"The `PyJWT` library itself includes type annotations starting from version 2.0.0. If you are using `PyJWT` version 2.0.0 or newer, you MUST uninstall `types-pyjwt` to avoid type conflicts, incorrect type checking results, or outdated stub definitions.","severity":"breaking","affected_versions":"PyJWT >= 2.0.0"},{"fix":"Upgrade to `PyJWT` version 2.0.0 or newer and uninstall `types-pyjwt`.","message":"`types-pyjwt` has not been updated since mid-2021 (version 1.7.1) and is effectively deprecated due to `PyJWT`'s self-typing. Further type improvements or fixes for `PyJWT` are now made directly within the `PyJWT` project.","severity":"deprecated","affected_versions":"All versions of `types-pyjwt`"},{"fix":"Consistently use either `types-pyjwt` (for `PyJWT < 2.0.0`) or PyJWT's built-in types (for `PyJWT >= 2.0.0`). The recommended approach is to upgrade `PyJWT` and remove `types-pyjwt`.","message":"When `types-pyjwt` is installed, type checkers may prefer its stubs over inline annotations in `PyJWT < 2.0.0`. However, for `PyJWT >= 2.0.0`, the presence of `types-pyjwt` can cause confusing errors or `mypy` to complain about duplicate definitions.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Uninstall `types-pyjwt` if your `PyJWT` version is 2.0.0 or higher: `pip uninstall types-pyjwt`.","cause":"Using `types-pyjwt` simultaneously with `PyJWT` version 2.0.0 or newer, which ships with its own type annotations. Type checkers detect two sources of type information for the same module.","error":"error: Duplicate module named 'jwt' (or similar type conflict errors)"},{"fix":"For `PyJWT < 2.0.0`, install `types-pyjwt`: `pip install types-pyjwt`. For `PyJWT >= 2.0.0`, ensure `types-pyjwt` is *not* installed and that your type checker recognizes `py.typed` packages (most modern type checkers do by default).","cause":"Attempting to type-check `PyJWT` code without any type information. This occurs if `PyJWT < 2.0.0` is installed and `types-pyjwt` is missing, or if `types-pyjwt` is installed but the type checker isn't configured correctly to find stubs.","error":"error: No type hints found for package 'jwt' (or 'module 'jwt' has no attribute 'encode' (or 'decode')' with type checker)"}]}