Code:
In [13]: from itsdangerous import TimedJSONWebSignatureSerializer
In [14]: s = TimedJSONWebSignatureSerializer('secret-key')
In [15]: s.dumps(4)
Out[15]: 'eyJhbGciOiJIUzI1NiIsImV4cCI6MTM3ODk4Nzg2MCwiaWF0IjoxMzc4OTg0MjYwfQ.NA.u6eBnrbtEj-FQC9geOx-vCp-f5I_msIpB0sNLxhMA04'
In [16]: s.loads(_, max_age=86400)
Out[16]: 4
Will take in anything that could be turned into JSON. Pretty neat, no need to store tokens in a database.
link: itsdangerous — itsdangerous