Skip to main content

Module for generating and verifying JSON Web Tokens

Project description

Build Status Coverage Status PyPI version

Module for generating and verifying JSON Web Tokens.

Example:

import jwt, Crypto.PublicKey.RSA as RSA, datetime
key = RSA.generate(2048)
payload = { 'foo': 'bar', 'wup': 90 };
token = jwt.generate_jwt(payload, key, 'PS256', datetime.timedelta(minutes=5))
header, claims = jwt.verify_jwt(token, key, ['PS256'])
for k in payload: assert claims[k] == payload[k]

The API is described here.

Installation

pip install python_jwt

Another Example

You can read and write keys from and to PEM-format strings:

import jwt, Crypto.PublicKey.RSA as RSA, datetime
key = RSA.generate(2048)
priv_pem = key.exportKey()
pub_pem = key.publickey().exportKey()
payload = { 'foo': 'bar', 'wup': 90 };
priv_key = RSA.importKey(priv_pem)
pub_key = RSA.importKey(pub_pem)
token = jwt.generate_jwt(payload, priv_key, 'RS256', datetime.timedelta(minutes=5))
header, claims = jwt.verify_jwt(token, pub_key, ['RS256'])
for k in payload: assert claims[k] == payload[k]

Licence

MIT

Tests

make test

Lint

make lint

Code Coverage

make coverage

coverage.py results are available here.

Coveralls page is here.

Benchmarks

make bench

Here are some results on a laptop with an Intel Core i5-3210M 2.5Ghz CPU and 6Gb RAM running Ubuntu 13.04.

Generate Key

user (ns)

sys (ns)

real (ns)

RSA

152,700,000

300,000

152,906,095

Generate Token

user (ns)

sys (ns)

real (ns)

HS256

140,000

10,000

157,202

HS384

160,000

10,000

156,403

HS512

139,999

20,000

153,212

PS256

3,159,999

49,999

3,218,649

PS384

3,170,000

10,000

3,176,899

PS512

3,120,000

9,999

3,141,219

RS256

3,070,000

20,000

3,094,644

RS384

3,090,000

0

3,092,471

RS512

3,079,999

20,000

3,095,314

Load Key

user (ns)

sys (ns)

real (ns)

RSA

811,000

0

810,139

Verify Token

user (ns)

sys (ns)

real (ns)

HS256

140,000

0

129,947

HS384

130,000

0

130,161

HS512

119,999

0

128,850

PS256

780,000

10,000

775,609

PS384

759,999

0

752,933

PS512

739,999

0

738,118

RS256

700,000

0

719,365

RS384

719,999

0

721,524

RS512

730,000

0

719,706

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_jwt-1.1.6.tar.gz (191.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_jwt-1.1.6-py2.py3-none-any.whl (24.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python_jwt-1.1.6.tar.gz.

File metadata

  • Download URL: python_jwt-1.1.6.tar.gz
  • Upload date:
  • Size: 191.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for python_jwt-1.1.6.tar.gz
Algorithm Hash digest
SHA256 b8b618301b66d30f6b5e8378dffd36ea4d9e56b1b558061264a5e0948cdaa25c
MD5 b8ab6398930bdf9bfce7fd32e616a1b0
BLAKE2b-256 7c31b89b726c588f4b07f75525cf4c7ce4cd328333e4ded715a5ef95c59e28c4

See more details on using hashes here.

File details

Details for the file python_jwt-1.1.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for python_jwt-1.1.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 89cf7c25fde94fd648f9b9b2fc16c303cb6cfe6d430d336bce651c27ef7b3b32
MD5 feb75b31f45e73f2c2f0b65d05aed906
BLAKE2b-256 64dd6c9b093ac0955674a5e37105dc793f521964342fa1de553a849b381cfb2c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page