Registry / type-stubs / types-jwt

types-jwt

JSON →
library0.1.3pypypiunverified

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-jwt
INSTALL
IMPORT
SIG · TYPES-JWT
T
types-jwt
type-stubspythonv0.1.3
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.3 · 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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.1MB
glibc
py 3.103.910 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.

encode
from jwt import encode
from jwt-stubs import encode

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.

import jwt import os from datetime import datetime, timedelta, timezone from typing import Dict, Any # These types are enhanced by types-jwt if PyJWT < 2.0 # Note: This quickstart uses PyJWT (the runtime library) # types-jwt provides type hints for this code during static analysis. # Replace with a strong, secret key in a real application secret_key: bytes = os.environ.get('JWT_SECRET_KEY', 'your-super-secret-key').encode('utf-8') algorithm: str = "HS256" # 1. Encode a JWT payload: Dict[str, Any] = { "user_id": 123, "username": "testuser", "exp": datetime.now(timezone.utc) + timedelta(hours=1), # Token expires in 1 hour "iat": datetime.now(timezone.utc) # Issued at time } try: encoded_jwt: str = jwt.encode(payload, secret_key, algorithm=algorithm) print(f"Encoded JWT: {encoded_jwt}") # 2. Decode the JWT decoded_payload: Dict[str, Any] = jwt.decode( encoded_jwt, secret_key, algorithms=[algorithm] ) print(f"Decoded Payload: {decoded_payload}") except jwt.ExpiredSignatureError: print("Token has expired!") except jwt.InvalidTokenError as e: print(f"Invalid token: {e}")
Debug
Known issues
breaking`types-jwt` (and `types-PyJWT`) are largely redundant for `PyJWT` versions 2.0.0 and higher. Starting with `PyJWT` 2.0.0 (released December 2020), the `PyJWT` library itself includes inline type annotations. Users should uninstall `types-jwt` if they are using `PyJWT >= 2.0.0` to avoid potential conflicts, redundant packages, or unexpected type-checking behavior.
fix
If using `PyJWT >= 2.0.0`, uninstall `types-jwt`: `pip uninstall types-jwt`. Rely on `PyJWT`'s built-in type hints.
affects: PyJWT >= 2.0.0
gotchaInstalling `types-jwt` does NOT install the actual `PyJWT` runtime library. `types-jwt` only provides static type hints. To use JWT functionality (e.g., `jwt.encode`, `jwt.decode`), you must explicitly install `PyJWT` (e.g., `pip install PyJWT`) in addition to `types-jwt`.
fix
Ensure both `types-jwt` (for type checking) and `PyJWT` (for runtime functionality) are installed: `pip install types-jwt PyJWT`.
affects: All versions
gotchaType stub packages from `typeshed` are designed for static analysis tools (like MyPy) and should not be directly imported in your application's runtime code. All imports for JWT operations should come from the actual `PyJWT` library (i.e., `import jwt` or `from jwt import ...`). Importing from `types_jwt` will result in a `ModuleNotFoundError` or `ImportError` at runtime.
fix
Always import from `jwt` (the runtime library) and *never* from `types_jwt` in your Python code: `import jwt`.
affects: All versions
Upgrade
Version history
0.1.3latest on PyPI · released May 12, 2021
Audit
Dependencies
PyJWTrequired`types-jwt` provides type stubs for the `PyJWT` runtime library. You must install `PyJWT` (e.g., `pip install PyJWT`) to use the `jwt` module at runtime.
mypyoptionalA static type checker like MyPy is needed to utilize the type stubs provided by `types-jwt` for static analysis.
Agent activity
40 hits · last 30 days
node
36
Amazon
1
OpenAI (training)
1
Resources
types-jwt — pip install types-jwt · libregistry