Skip to main content

PyJWT Build Status

A Python implementation of JSON Web Token draft 01.

Installing

$ pip install PyJWT

A Note on Dependencies:

The RSASSA-PKCS1-v1_5 algorithms depend on PyCrypto. If you plan on using any of those algorithms, you’ll need to install it as well.

$ pip install PyCrypto

The Elliptic Curve Digital Signature algorithms depend on Python-ECDSA. If you plan on using any of those algorithms, you’ll need to install it as well.

$ pip install ecdsa

Usage

import jwt
jwt.encode({'some': 'payload'}, 'secret')

Additional headers may also be specified.

jwt.encode({'some': 'payload'}, 'secret', headers={'kid': '230498151c214b788dd97f22b85410a5'})

Note the resulting JWT will not be encrypted, but verifiable with a secret key.

jwt.decode('someJWTstring', 'secret')

If the secret is wrong, it will raise a jwt.DecodeError telling you as such. You can still get the payload by setting the verify argument to False.

jwt.decode('someJWTstring', verify=False)

Algorithms

The JWT spec supports several algorithms for cryptographic signing. This library currently supports:

  • HS256 - HMAC using SHA-256 hash algorithm (default)

  • HS384 - HMAC using SHA-384 hash algorithm

  • HS512 - HMAC using SHA-512 hash algorithm

  • ES256 - ECDSA signature algorithm using SHA-256 hash algorithm

  • ES384 - ECDSA signature algorithm using SHA-384 hash algorithm

  • ES512 - ECDSA signature algorithm using SHA-512 hash algorithm

  • RS256 - RSASSA-PKCS1-v1_5 signature algorithm using SHA-256 hash algorithm

  • RS384 - RSASSA-PKCS1-v1_5 signature algorithm using SHA-384 hash algorithm

  • RS512 - RSASSA-PKCS1-v1_5 signature algorithm using SHA-512 hash algorithm

Change the algorithm with by setting it in encode:

jwt.encode({'some': 'payload'}, 'secret', 'HS512')

When using the RSASSA-PKCS1-v1_5 algorithms, the key argument in both jwt.encode() and jwt.decode() ("secret" in the examples) is expected to be an RSA public or private key as imported with Crypto.PublicKey.RSA.importKey().

When using the ECDSA algorithms, the key argument is expected to be an Elliptic Curve private key as imported with ecdsa.SigningKey.from_pem(), or a public key as imported with ecdsa.VerifyingKey.from_pem().

Tests

You can run tests from the project root after cloning with:

$ python tests/test_jwt.py

Support of reserved claim names

JSON Web Token defines some reserved claim names and defines how they should be used. PyJWT supports these reserved claim names:

  • “exp” (Expiration Time) Claim

  • “nbf” (Not Before Time) Claim

  • “iss” (Issuer) Claim

  • “aud” (Audience) Claim

Expiration Time Claim

From [draft 01 of the JWT spec](http://self-issued.info/docs/draft-jones-json-web-token

Metadata

Release files for PyJWT 0.3.1

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

Source distribution (sdist)

Source distribution for PyJWT 0.3.1
File Size Uploaded
PyJWT-0.3.1.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyJWT 0.3.1
File Interpreter ABI Platform
PyJWT-0.3.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 19.4 kB

Release files / PyJWT-0.3.1.tar.gz

Download URL PyJWT-0.3.1.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8b6c028f91c8e5be44f2c3b94c1d96229e1fa810e73e51ed52cf0c426f7cf332
BLAKE2b-256 checksum
How to use checksums
6a7e4c5158be163c888142f150bf3822438dc334549e7cfd990f2ccfc2fb0e3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / PyJWT-0.3.1-py2.py3-none-any.whl

Download URL PyJWT-0.3.1-py2.py3-none-any.whl
Size 11.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a88d511f116dab9e7c29578c2174e08594c102781145d481741bb7c4dcc9db9d
BLAKE2b-256 checksum
How to use checksums
e78974a354c5d669c481b98b055c595e676269809729ded7a0f06a32053165c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.15.1

2 release files

2.15.0

2 release files

2.14.0

2 release files

2.13.0

2 release files

2.12.1

2 release files

2.12.0

2 release files

2.11.0

2 release files

2.10.1

2 release files

2.10.0

2 release files

2.9.0

2 release files

2.8.0

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.7.1

2 release files

1.7.0

2 release files

1.6.4

2 release files

1.6.3

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.3

5 release files

0.2.1

4 release files

0.2.0

4 release files

0.1.9

4 release files

0.1.8

5 release files

0.1.7

5 release files

0.1.6

4 release files

0.1.5

4 release files

0.1.4

4 release files

0.1.3

4 release files

0.1.2

4 release files

0.1.1

4 release files

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