# PyJWT — card for AI agents

Python library for encoding and decoding JSON Web Tokens.

Category: Auth and security libraries · PyPI package `pyjwt` · latest version 2.15.1 (checked 2026-11-01)
Install: `pip install pyjwt`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## PyJWT
- Add `PyJWT` (or `pyjwt`) to requirements, but write `import jwt` in code.
- Encode with a single `algorithm="..."`. Decode with an explicit list, `algorithms=["..."]`, as the README does.
- Use only the verifying `jwt.decode` for auth decisions. The docs' "Reading the Claimset without Validation" path is not a verification step.
- For RS256, PS256, EdDSA or ES256, read the docs' "Cryptographic Dependencies (Optional)" section before installing.
- When signing keys come from an identity provider, follow the docs' "Retrieve RSA signing keys from a JWKS endpoint" section and `PyJWKClient` instead of hand-rolling key fetching.
- Check keys against the docs' "Minimum Key Length Requirements". Use the "Requiring Presence of Claims" section when a claim must exist.

## What it is
- PyJWT encodes and decodes JSON Web Tokens in Python. The docs describe it as "a Python library which allows you to encode and decode JSON Web Tokens (JWT)". The README calls it an implementation of RFC 7519 and credits @progrium with the original implementation. It is MIT licensed.
- You install it as `PyJWT` from pip and import it as `jwt`. You sign a payload with a key and a named algorithm. You read it back by passing the same key and a list of accepted algorithms. The docs index has worked examples for HS256, RS256, PS256, EdDSA and ES256. It also lists sections on claim validation, key length checks and fetching signing keys from a JWKS endpoint.
- The repository was created on 2011-02-24. The changelog runs from v1.0.0 to v2.15.1, and 2.15.1 was published on 2026-09-28. PyJWT is for Python developers who need to issue or check JWTs themselves. It is a token library, not a hosted login service.

## Caveats
- Package name and import name differ: You install `PyJWT` but import `jwt`. Code and requirements files should use each name in its own place.
- Crypto dependencies are a separate, optional step: The docs list "Cryptographic Dependencies (Optional)" as its own installation section. Read it before assuming a plain `pip install pyjwt` covers every algorithm in the examples.
- Unvalidated reads exist: The docs document reading the claimset and the headers without validation. Those reads are not the same as a verified `decode`, so do not use them to grant access.
- Tokens only; the README points elsewhere for full auth: PyJWT's own description stops at encoding and decoding tokens. The README carries an Auth0 sponsor block that points readers to Auth0's Python SDK for adding token-based authentication.

## Numbers (AgentGid data)
- Gid Score: 74.4 (#220 of all tools, 7 of 141 in its category)
- Used in 118 public projects set up for AI coding agents (1.9%)
- Downloads last week: 176,058,198 (as of 2026-11-24), +14.8% over 4 weeks
- GitHub stars: 5,729 (as of 2026-11-24)
- Last push: 2026-11-23

## Often used with
Pydantic 72.9%, python-dotenv 70.3%, Uvicorn 70.3%, FastAPI 66.1%, Requests 61.0%, python-multipart 57.6%

## Checked alternatives (same job)
- python-jose: https://agentgid.com/tools/python-jose/agent.md
- Authlib: https://agentgid.com/tools/authlib/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/pyjwt/
- Homepage: https://github.com/jpadilla/pyjwt
- Repository: https://github.com/jpadilla/pyjwt
- Source: https://github.com/jpadilla/pyjwt#readme
- Source: https://github.com/jpadilla/pyjwt
- Source: https://github.com/jpadilla/pyjwt/releases
- Source: https://pyjwt.readthedocs.io


## PyJWT: make and check login tokens in Python

PyJWT is a free Python library for JSON Web Tokens, the signed text passes many apps use to keep a person logged in. Your server makes a token after login, and later checks that nobody changed it and that it has not expired. It does not store passwords and does not handle the login screen itself.

### Where to use it
- Keep users logged in to your service: After a person signs in, your Python backend hands out a token that says who they are and ends in 15 minutes; every later request is checked with it.
- Accept tokens from a sign-in provider: Your app lets people log in through an outside identity service and checks its tokens with the public keys that service publishes, so you never hold its secret.
- Let one service vouch for another: Your main app signs a token with a private key; the billing service checks it with the matching public key and refuses tokens meant for someone else.
- Links that expire, like password reset: A reset or invite link carries a short-lived token with the user's ID, so it stops working after an hour without a database lookup. (idea, not from the official pages)
- Look inside a token while debugging: Your assistant reads which key and algorithm a token says it uses, before choosing how to check it, without trusting its contents yet.

### How to start
- Install PyJWT into your project's Python environment; add the crypto extra if you will use RSA or elliptic-curve keys.

```
$ pip install pyjwt
$ pip install pyjwt[crypto]
```

- Make a token and read it back. The import name is jwt.

```
>>> import jwt
>>> encoded_jwt = jwt.encode({"some": "payload"}, "secret", algorithm="HS256")
>>> jwt.decode(encoded_jwt, "secret", algorithms=["HS256"])
{'some': 'payload'}
```


### License
Free to use in personal and paid products under the MIT license. Keep the copyright and permission notice with copies of the library.

### Good to know
- Anyone holding a token can read what is inside it; the signature only stops changes. Do not put secrets such as passwords into a token.
- RSA, ECDSA and EdDSA keys need the extra cryptography package; the plain install covers only shared-secret signing.
- Short secret keys draw a warning by default, and you can make them an error. A shared secret for HS256 should be at least 32 bytes.
- The project is active: 2.13.0, 2.14.0 and 2.15.0 in 2026 each list security fixes, and 2.15.1 came out on 2026-09-28.
- It needs Python 3.9 or newer.

Checked 2026-11-11 against: https://pyjwt.readthedocs.io/en/stable/, https://pyjwt.readthedocs.io/en/stable/installation.html, https://pyjwt.readthedocs.io/en/stable/usage.html, https://pyjwt.readthedocs.io/en/stable/api.html, https://pyjwt.readthedocs.io/en/stable/changelog.html, https://pyjwt.readthedocs.io/en/stable/faq.html, https://pyjwt.readthedocs.io/en/stable/algorithms.html, https://github.com/jpadilla/pyjwt/blob/master/README.rst, https://github.com/jpadilla/pyjwt/blob/master/LICENSE, https://pypi.org/pypi/pyjwt/json, https://pypi.org/pypi/pyjwt/2.15.1/json

### Mistakes to avoid
- Don't: jwt.decode(token, key) with no algorithms argument → Do: jwt.decode(token, key, algorithms=["HS256"]) with the exact algorithms you issue (Since 2.0 the algorithms list is required; in our run the call without it raised DecodeError.)
- Don't: jwt.encode(...).decode("utf-8") from 1.x tutorials → Do: Use the return value of jwt.encode as it is; it is already a str (Since 2.0 tokens come back as text; in our run .decode raised AttributeError 'str' object has no attribute 'decode'.)
- Don't: jwt.decode(token, verify=False) to peek at a token → Do: jwt.decode(token, options={"verify_signature": False}) for debugging only, or jwt.get_unverified_header(token) (The old verify parameter was dropped in 2.0, and claims read without checking cannot be trusted.)
- Don't: pip install pyjwt and then algorithm="RS256" → Do: pip install "pyjwt[crypto]" (keep it this way in requirements files) (RSA, ECDSA and EdDSA need the cryptography package, which the plain install does not bring.)
- Don't: A short HS256 secret such as "secret" or a 6-letter word → Do: secrets.token_hex(32) or longer, kept in server settings; consider options enforce_minimum_key_length True (Keys shorter than the hash output draw InsecureKeyLengthWarning (our run showed it for "secret").)

### Questions
- Why does jwt.decode fail with "It is required that you pass in a value for the algorithms argument"? Since version 2.0 you must list the algorithms you accept, for example algorithms=["HS256"]; this blocks tokens that switch to a weaker algorithm.
- Does it check expiry by itself? Yes, when the token has an exp claim; an expired token raises ExpiredSignatureError. To require exp in every token, list it in options require.
- Can I allow a few seconds of clock difference between servers? Yes, pass leeway in seconds (or as a timedelta) to jwt.decode.
- Can I use it in a paid product? Yes, it is under the MIT license; keep its notice with copies of the code.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
