Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python JWT libraries create, sign, and verify JSON Web Tokens, the signed tokens that carry identity claims between services. Libraries that implement the full JOSE standards also encrypt tokens and manage the keys that sign them. These libraries let APIs and AI agents check who sent each request.
Popularity
PyJWT has the most monthly downloads in this comparison, at 761.0M.
def retrieve_matching_jwk(self, token):
"""Get the signing key by exploring the JWKS endpoint of the OP.
Don't use jwt.PyJWKClient()get_signing_key_from_jwt() because it doesn't check
the algorithm in case of multiple jwk with the same kid.
"""
response_jwks = requests.get(
self.OIDC_OP_JWKS_ENDPOINT,
verify=self.get_settings("OIDC_VERIFY_SSL", True),
timeout=self.get_settings("OIDC_TIMEOUT", None),
proxies=self.get_settings("OIDC_PROXY", None),
)
response_jwks.raise_for_status()
jwks = response_jwks.json()
# Compute the current header from the given token to find a match jws = jwt.get_unverified_header(token)
key = None
for jwk in jwks["keys"]:
if import_from_settings("OIDC_VERIFY_KID", True) and jwk[
"kid"
] != smart_str(jws["kid"]):
continue
if "alg" in jwk and jwk["alg"] != smart_str(jws["alg"]):
continue
key = jwk
if key is None:
raise SuspiciousOperation("Could not find a valid JWKS.")
return jwt.PyJWK(key)
Authlib
Builds OAuth and OpenID Connect servers and clients.
async def _verify_jwt(
self,
alg_values: list[str],
token: str,
claims_cls: type[C],
claims_options: dict | None = None,
claims_params: dict | None = None,
) -> C:
"""Decode and validate a JWT, re-fetching the JWKS as needed.
Args:
alg_values: list of `alg` values allowed when verifying the JWT.
token: the JWT.
claims_cls: the JWTClaims class to use to validate the claims.
claims_options: dict of options passed to the `claims_cls` constructor.
claims_params: dict of params passed to the `claims_cls` constructor.
Returns:
The decoded claims in the JWT.
"""
jwt = JsonWebToken(alg_values)
logger.debug("Attempting to decode JWT (%s) %r", claims_cls.__name__, token)
# Try to decode the keys in cache first, then retry by forcing the keys # to be reloaded jwk_set = await self.load_jwks()
try:
claims = jwt.decode(
token,
key=jwk_set,
claims_cls=claims_cls,
claims_options=claims_options,
claims_params=claims_params,
)
except ValueError:
logger.info("Reloading JWKS after decode error")
jwk_set = await self.load_jwks(force=True) # try reloading the jwks
claims = jwt.decode(
token,
key=jwk_set,
claims_cls=claims_cls,
claims_options=claims_options,
claims_params=claims_params,
)
logger.debug("Decoded JWT (%s) %r; validating", claims_cls.__name__, claims)
claims.validate(
now=self._clock.time(), leeway=120
) # allows 2 min of clock skew
return claims
joserfc
Provides JOSE JWT encoding, decoding, and separate claim validation.
Downloads / mo
128.5M
Stars
184
Last release
1.8.0
License
BSD-3-Clause
Strengths
Supports signed and encrypted JWTs.Choose signed tokens or encrypted tokens through the JWT API.
Checks required and allowed claims.Use JWTClaimsRegistry to require claims and restrict accepted values.
Replaces deprecated Authlib JOSE.Use the separate JOSE library when migrating Authlib JWT code.
Limitations
Decoding skips claim validation.Validate token.claims separately with JWTClaimsRegistry.
Encryption needs its own registry.Pass JWERegistry when encoding or decoding encrypted JWTs.
def main(args):
"""Generates a signed JSON Web Token from local private key."""
with open(args.key) as f:
pem_data = f.read()
f.closed
pem_data_encode = pem_data.encode("utf-8")
key = jwk.JWK.from_pem(pem_data_encode)
if args.jwks:
with open(args.jwks, "w+") as fout:
fout.write("{ \"keys\":[ ")
fout.write(key.export(private_key=False))
fout.write("]}")
fout.close
now = int(time.time())
payload = {
# expire in one hour. "exp": now + args.expire,
"iat": now,
}
if args.iss:
payload["iss"] = args.iss
if args.sub:
payload["sub"] = args.sub
else:
payload["sub"] = args.iss
if args.aud:
if "," in args.aud:
payload["aud"] = args.aud.split(",")
else:
payload["aud"] = args.aud
if args.claims:
for item in args.claims.split(","):
k, v = item.split(':')
payload[k] = v
if args.listclaim:
for item in args.listclaim:
if (len(item) > 1):
k = item[0]
v = item[1:]
payload[k] = v
if args.nestedclaim:
nested = {}
for item in args.nestedclaim:
if (len(item) > 1):
k = item[0]
v = item[1:]
if len(v) == 1:
v = v[0]
nested[k] = v
nested["nested-2"] = copy.copy(nested)
payload[args.nestedkey] = nested
token = jwt.JWT(header={"alg": "RS256", "typ": "JWT", "kid": key.key_id},
claims=payload)
token.make_signed_token(key)
return token.serialize()
PyJWT suits applications that sign and verify tokens and fetch keys from a JWKS endpoint. joserfc and JWCrypto suit applications that also need encrypted tokens. Authlib suits applications that build OAuth or OpenID Connect clients and servers alongside their token handling.
PyJWT is a JSON Web Token implementation for Python that encodes and decodes signed tokens. Its PyJWKClient fetches signing keys from a JWKS endpoint.
python-jose is a JOSE implementation that signs, encrypts, and handles keys. It runs on the cryptography package, PyCryptodome, or a native Python backend.
joserfc implements the JOSE standards, including JWS, JWE, JWK, and JWT. It decodes a token and validates its claims as separate steps.
For coding agents
Found your JWT library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.