Skip to main content

JWT encoding and decoding limited to RS256

Project description

JWTSign

Rust jwt signing bindings for python

Usage:

import time
import json

from jwtsign import PyJwtEncoder, PyJwtDecoder

def read_bin(path: str) -> bytes:
    with open(path, "rb") as file:
        return file.read()

claims = {
    "id": "example",
    "exp": int(time.time() + 60),
}

private_key = read_bin("res/private_key.pem")
public_key = read_bin("res/public_key.pem")
encoder = PyJwtEncoder(private_key)
decoder = PyJwtDecoder(public_key, leeway=60)

# Using object encoding
token_claims_obj = encoder.encode_claims_json_obj(claims)
decoded_claims_obj = decoder.decode(token_claims_obj)

# Using serialized object encoding
token_claims_str = encoder.encode_claims_json_str(json.dumps(claims))
decoded_claims_str = decoder.decode(token_claims_str)

Decoder validates expiration time based on UTC with a leeway defined in the PyJwtDecoder::__init__.

[!NOTE] If at any point you have your claim as serialized JSON keep in mind that this performs slightly faster than the object as encoding parameter, as the rust code uses python bindings to call json.dumps on the object.

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

jwtsign-1.0.8.tar.gz (3.7 kB view details)

Uploaded Source

Built Distributions

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

jwtsign-1.0.8-cp311-cp311-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

jwtsign-1.0.8-cp310-cp310-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

jwtsign-1.0.8-cp39-cp39-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

jwtsign-1.0.8-cp38-cp38-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.28+ x86-64

jwtsign-1.0.8-cp37-cp37m-manylinux_2_28_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.28+ x86-64

File details

Details for the file jwtsign-1.0.8.tar.gz.

File metadata

  • Download URL: jwtsign-1.0.8.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for jwtsign-1.0.8.tar.gz
Algorithm Hash digest
SHA256 418061349f6351d8c61f33f86fb01351adb49ba939aa03ccf633798584599cbc
MD5 83fd3282ad6f87c09a9adcc79b146d41
BLAKE2b-256 511fe7146016b0212e588d07a42cd09618bc5f052e31809d809aa081eb8ecf9d

See more details on using hashes here.

File details

Details for the file jwtsign-1.0.8-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jwtsign-1.0.8-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 81ca0792816bf496f761bdaad249c2a729a43f7559d06e9e770e3ffa76268356
MD5 f258504fe3c5fea6abcb01e7b0c7ce3c
BLAKE2b-256 7799bbb2abb7aaa7c6a5f28b6f5509e3b08541b18373878d42958c35cb896b07

See more details on using hashes here.

File details

Details for the file jwtsign-1.0.8-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jwtsign-1.0.8-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 991b312fe51c63a30c46e09c6a12d5038cf25ba79bba235f8047dd1f91b6ac6a
MD5 ec278c72d0f877468210fc2fcb8e3294
BLAKE2b-256 b465191ace98beae0b6da08850c680afebd8fe9170f1611416b041de30be73e6

See more details on using hashes here.

File details

Details for the file jwtsign-1.0.8-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jwtsign-1.0.8-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bd5a793f6f987f330c16949abbe522c811db02eba514f54a611e89ab603b6c6a
MD5 94f7ea3f681826451fbbb7e6f506f3bc
BLAKE2b-256 b3e0850fc5363963fdf1cd907f38066a9a390fb72fd99b3af874b99e51539236

See more details on using hashes here.

File details

Details for the file jwtsign-1.0.8-cp38-cp38-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jwtsign-1.0.8-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c0ed9489d1c9822fec691dd30c94ef999c472508be6cadd728a7345b6f7e6457
MD5 f6be02ebad5b259bc9e1f67f8710c1ca
BLAKE2b-256 e94d23afb78497224390cf4e2ef10a84b4242287cedba3688263ff3a2722a9d8

See more details on using hashes here.

File details

Details for the file jwtsign-1.0.8-cp37-cp37m-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for jwtsign-1.0.8-cp37-cp37m-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5a75fd6745835627acda4dbecb7bbb479ef55ec293678605e1b219563107ad5f
MD5 2f22baeafbc993d2846a20f4ed32603c
BLAKE2b-256 0b41f48a31380123f7687295a19d4e14507e12d670f56081efa8215dd56c2c56

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