JWT in FastAPI

say it: “JOT in FAST-AY-PEE-EYE” /dʒɒt ɪn ˈfæstˌeɪˌpiˌaɪ/

A signed token carrying user info, created and checked with a library like PyJWT.

What is JWT in FastAPI?

A JWT is a signed token that carries the user's ID and expiry. FastAPI apps usually create and check JWTs with a library such as PyJWT.

token = jwt.encode({'sub': str(user.id), 'exp': expires}, SECRET_KEY, algorithm='HS256')
payload = jwt.decode(token, SECRET_KEY, algorithms=['HS256'])

Level: Freelancer · More FastAPI terms at this level

Updated