Skip to main content

simplejwt

PyPI version Build Status Test Coverage Maintainability

A dead simple JWT library.

Supported algorithms

  • HS256
  • HS384
  • HS512

Usage

Encode

Returns a new token.

from simplejwt import encode
token = encode('secret', {'my_payload': 'some_data'}, 'HS256')
# eyJ0eXBlIjogIkpXVCIsICJhbGciOiAiSFMyNTYifQ.eyJteV9wYXlsb2FkIjogInNvbWVfZGF0YSJ9.BXAs5tYkARpGHhegb8g8bfj8KhjFUTTjdEf81Ma1VhY
Name Type Default Description
secret str N/A The secret used to create the token.
payload dict N/A The payload data contained within the token.
alg int HS256 The algorithm to use to create the token.

Make

Returns a new token. This function has arguments for registered claims as specified in rfc7519.

Any registered claims provided in the payload will take precedence over any provided as arguments.

from simplejwt import make
token = make('secret', {'my_payload': 'some_data'}, 'HS256', issuer='acme', valid_to=1234567)
# eyJ0eXBlIjogIkpXVCIsICJhbGciOiAiSFMyNTYifQ.eyJteV9wYXlsb2FkIjogInNvbWVfZGF0YSIsICJpc3MiOiAiYWNtZSIsICJleHAiOiAxMjM0NTY3fQ.Nr5IADzsOhlzjxnghquBrRwewg10srDHu__-HN7GGGA
Name Type Default Description
secret str N/A The secret used to create the token.
payload dict N/A The payload data contained within the token.
alg int HS256 The algorithm to use to create the token.
issuer str None The issuer of the token.
subject str None The subject of the token.
audience str None The audience of the token.
valid_to int None The expiry date of the token as a timestamp.
valid_from int None The date the token is valid from as a timestamp.
issued_at int None The date the token was issued as a timestamp.
id str None The id of the token.

Decode

Returns the payload from a token.

from simplejwt import encode, decode
token = encode('secret', {'my_payload': 'some_data'}, 'HS256')
payload = decode('secret', token, 'HS256')
# {'my_payload': 'some_data'}
Name Type Default Description
secret str N/A The secret used to decode the token.
payload dict N/A The token to decode.
alg int HS256 The algorithm to use to create the token.

Running tests

Install the package with test dependencies

pip install -e ".[test]"

Run tox

tox

Release files for simplejwt 2.0.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 simplejwt 2.0.1
File Size Uploaded
simplejwt-2.0.1.tar.gz 6.4 kB Details

Release files / simplejwt-2.0.1.tar.gz

Download URL simplejwt-2.0.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3d9054c3f6c8ebca49693568b483f4bafcfdf962fe9e60f5bf0855bdc19761a2
BLAKE2b-256 checksum
How to use checksums
3fb03680d62a6cde9d2c2a237428e6ef07d6211a9d120e7310fc540a11eacece
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3

Release history Release notifications | RSS feed

This release

2.0.1 This release

1 release file

2.0.0

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.5.0

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

0.0.1

1 release file

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