.. image:: https://travis-ci.org/GehirnInc/python-jwt.svg?branch=master
:target: https://travis-ci.org/GehirnInc/python-jwt
.. image:: https://coveralls.io/repos/GehirnInc/python-jwt/badge.png?branch=master
:target: https://coveralls.io/r/GehirnInc/python-jwt?branch=master
.. image:: https://badge.fury.io/py/jwt.svg?dummy
:target: http://badge.fury.io/py/jwt
python-jwt
==========
*python-jwt* is a JSON Web Token (JWT) implementation in Python developed by `Gehirn Inc`_.
Examples
--------
.. code-block:: python
import json
from datetime import datetime, timedelta, timezone
from jwt import (
JWT,
jwk_from_dict,
jwk_from_pem,
)
from jwt.utils import get_int_from_datetime
instance = JWT()
message = {
'iss': 'https://example.com/',
'sub': 'yosida95',
'iat': get_int_from_datetime(datetime.now(timezone.utc)),
'exp': get_int_from_datetime(
datetime.now(timezone.utc) + timedelta(hours=1)),
}
"""
Encode the message to JWT(JWS).
"""
# Load a RSA key from a JWK dict.
signing_key = jwk_from_dict({
'kty': 'RSA',
'e': 'AQAB',
'n': '...',
'd': '...'})
# Or load a RSA key from a PEM file.
with open('rsa_private_key.pem', 'rb') as fh:
signing_key = jwk_from_pem(fh.read())
# You can also load an octet key in the same manner as the RSA.
# signing_key = jwk_from_dict({'kty': 'oct', 'k': '...'})
compact_jws = instance.encode(message, signing_key, alg='RS256')
"""
Decode the JWT with verifying the signature.
"""
# Load a public key from PEM file corresponding to the signing private key.
with open('rsa_public_key.json', 'r') as fh:
verifying_key = jwk_from_dict(json.load(fh))
message_received = instance.decode(
compact_jws, verifying_key, do_time_check=True)
"""
Successfuly retrieved the `message` from the `compact_jws`
"""
assert message == message_received
Installation
------------
You can install python-jwt with pip.
.. code-block:: shell
$ pip install jwt
Implementation Details
-------------------------
Supported Algorithms
~~~~~~~~~~~~~~~~~~~~
- Unsecured
- none (disabled by default for security)
- Symmetric
- HS256
- HS384
- HS512
- Asymmetric
- PS256
- PS384
- PS512
- RS256
- RS384
- RS512
Supported Python Versions
~~~~~~~~~~~~~~~~~~~~~~~~~
- Python 3.6+
License
-------
python-jwt is licensed under the Apache License version 2. See ./LICENSE.rst.
.. _Gehirn Inc: http://www.gehirn.co.jp/
Raw data
{
"_id": null,
"home_page": "https://github.com/GehirnInc/python-jwt",
"name": "jwt",
"maintainer": "",
"docs_url": null,
"requires_python": ">= 3.6",
"maintainer_email": "",
"keywords": "",
"author": "Kohei YOSHIDA",
"author_email": "kohei.yoshida@gehirn.co.jp",
"download_url": "",
"platform": "",
"description": ".. image:: https://travis-ci.org/GehirnInc/python-jwt.svg?branch=master\n :target: https://travis-ci.org/GehirnInc/python-jwt\n.. image:: https://coveralls.io/repos/GehirnInc/python-jwt/badge.png?branch=master\n :target: https://coveralls.io/r/GehirnInc/python-jwt?branch=master\n.. image:: https://badge.fury.io/py/jwt.svg?dummy\n :target: http://badge.fury.io/py/jwt\n\npython-jwt\n==========\n\n*python-jwt* is a JSON Web Token (JWT) implementation in Python developed by `Gehirn Inc`_.\n\n\nExamples\n--------\n\n.. code-block:: python\n\n import json\n from datetime import datetime, timedelta, timezone\n\n from jwt import (\n JWT,\n jwk_from_dict,\n jwk_from_pem,\n )\n from jwt.utils import get_int_from_datetime\n\n\n instance = JWT()\n\n message = {\n 'iss': 'https://example.com/',\n 'sub': 'yosida95',\n 'iat': get_int_from_datetime(datetime.now(timezone.utc)),\n 'exp': get_int_from_datetime(\n datetime.now(timezone.utc) + timedelta(hours=1)),\n }\n\n \"\"\"\n Encode the message to JWT(JWS).\n \"\"\"\n\n # Load a RSA key from a JWK dict.\n signing_key = jwk_from_dict({\n 'kty': 'RSA',\n 'e': 'AQAB',\n 'n': '...',\n 'd': '...'})\n # Or load a RSA key from a PEM file.\n with open('rsa_private_key.pem', 'rb') as fh:\n signing_key = jwk_from_pem(fh.read())\n # You can also load an octet key in the same manner as the RSA.\n # signing_key = jwk_from_dict({'kty': 'oct', 'k': '...'})\n\n compact_jws = instance.encode(message, signing_key, alg='RS256')\n\n \"\"\"\n Decode the JWT with verifying the signature.\n \"\"\"\n\n # Load a public key from PEM file corresponding to the signing private key.\n with open('rsa_public_key.json', 'r') as fh:\n verifying_key = jwk_from_dict(json.load(fh))\n\n message_received = instance.decode(\n compact_jws, verifying_key, do_time_check=True)\n\n \"\"\"\n Successfuly retrieved the `message` from the `compact_jws`\n \"\"\"\n assert message == message_received\n\n\nInstallation\n------------\n\nYou can install python-jwt with pip.\n\n.. code-block:: shell\n\n $ pip install jwt\n\n\nImplementation Details\n-------------------------\n\nSupported Algorithms\n~~~~~~~~~~~~~~~~~~~~\n\n- Unsecured\n\n - none (disabled by default for security)\n\n- Symmetric\n\n - HS256\n - HS384\n - HS512\n\n- Asymmetric\n\n - PS256\n - PS384\n - PS512\n - RS256\n - RS384\n - RS512\n\nSupported Python Versions\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\n- Python 3.6+\n\n\nLicense\n-------\npython-jwt is licensed under the Apache License version 2. See ./LICENSE.rst.\n\n\n.. _Gehirn Inc: http://www.gehirn.co.jp/\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "JSON Web Token library for Python 3.",
"version": "1.3.1",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "13af211933474ad6b2a5a4199d9b3a05",
"sha256": "61c9170f92e736b530655e75374681d4fcca9cfa8763ab42be57353b2b203494"
},
"downloads": -1,
"filename": "jwt-1.3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "13af211933474ad6b2a5a4199d9b3a05",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">= 3.6",
"size": 18192,
"upload_time": "2021-10-07T05:19:03",
"upload_time_iso_8601": "2021-10-07T05:19:03.073427Z",
"url": "https://files.pythonhosted.org/packages/ad/66/1e792aef36645b96271b4d27c2a8cc9fc7bbbaf06277a849b9e1a6360e6a/jwt-1.3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-10-07 05:19:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "GehirnInc",
"github_project": "python-jwt",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "jwt"
}