Skip to main content

jot is a Python implementation of the draft [JSON Web Token (JWT)](http://tools.ietf.org/html/draft-jones-json-web-token-07) specification.

It supports signing through the draft [JWS](http://tools.ietf.org/html/draft-jones-json-web-signature-04) specification. Only HMAC SHA-256/384/512 are supported as of yet.

It will eventually support encryption through JWE, following a similar API.

Plaintext JWT

Plaintext JWTs are neither signed nor encrypted and take a JSON-compatible object as the sole argument.

>>> from jot import jwt
>>> msg = jwt.encode({'status': 'ready'})
>>> msg
'eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJzdGF0dXMiOiJyZWFkeSJ9.'
>>> jwt.decode(msg)
{'headers': {u'alg': u'none', u'typ': u'JWT'}, 'valid': True, 'payload':
{u'status': u'ready'}}

Signed JWT (JWS)

For encoding, you need to provide an object representing your desired algorithm along with a key and, optionally, a key id for the header.

>>> from jot import jwt, jws
>>> msg = jwt.encode({'status': 'ready'}, signer=jws.HmacSha(
bits=256, key='verysecret', key_id='client1'))
>>> msg
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImNsaWVudDEifQ.eyJzdGF0dXM
iOiJyZWFkeSJ9.DcKKQXXUjGP7pape8BgQ3AcQSPH8toWFLY2woIVUZ-w'

To decode and verify, you must pass a signer object for every possible expected algorithm. This may only be one. You can pass a key directly to the signer object if you expect only a particular one:

>>> jwt.decode(msg, signers=[jws.HmacSha(bits=256, key='verysecret')])
{'headers': {u'alg': u'HS256', u'typ': u'JWT', u'kid': u'client1'},
'valid': True, 'payload': {u'status': u'ready'}}

If you expect any of several keys, you can pass a dictionary of key_id -> key mappings. decode() will use the ‘kid’ (key id) header to choose the correct one.

>>> jwt.decode(msg, signers=[jws.HmacSha(bits=256, keydict={'client1':
'verysecret', 'client2': 'evensecreter'})])
{'headers': {u'alg': u'HS256', u'typ': u'JWT', u'kid': u'client1'},
'valid': True, 'payload': {u'status': u'ready'}}

An invalid key, or a key id not being found in the key dictionary, will flip the ‘valid’ attribute to False:

>>> jwt.decode(msg, signers=[jws.HmacSha(bits=256, keydict={'client1':
'notverysecret', 'client2': 'evensecreter'})])
{'headers': {u'alg': u'HS256', u'typ': u'JWT', u'kid': u'client1'},
'valid': False, 'payload': {u'status': u'ready'}}
>>> jwt.decode(msg, signers=[jws.HmacSha(bits=256, keydict={'client10':
'verysecret', 'client2': 'evensecreter'})])
{'headers': {u'alg': u'HS256', u'typ': u'JWT', u'kid': u'client1'},
'valid': False, 'payload': {u'status': u'ready'}}

The headers and payload should not be trusted if valid is False, but they are provided for informational purposes.

Metadata

Release files for jot 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jot 0.2
File Size Uploaded Provenance
jot-0.2.tar.gz 5.2 kB Without provenance Details

Release files / jot-0.2.tar.gz

Download URL jot-0.2.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6a433c5d9337c47967df441db4b54d3cec6f1a0456887d2258572fcf86e7136c
BLAKE2b-256 checksum
How to use checksums
a6f3e514043df7898ce60dcf3b35c2a4bbf7b53b40673cf3910701a950e3ff86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for jot 0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page