Skip to main content

A Rust-backed JWT library

Project description

Python Version

webtoken

Rust-backed JWT

Size

The .so size on linux is ~3.7Mb, no external dependencies.

Speed

Simple benchmark

HS256
Enc: 2.1x | Dec: 1.5x

RS256
Enc: 54.4x | Dec: 1.3x

ES256
Enc: 1.9x | Dec: 1.4x

EdDSA
Enc: 2.9x | Dec: 2.5x

ES512
Enc: 1.9x | Dec: 1.5x

See and suggest more benchmarks under benchmarks.

Installation

pip install webtoken

  • Developed on Linux / Python 3.13
  • Wheels available for Linux (+ Alpine) / Windows / MacOS
  • sdist for FreeBSD

Usage

PyJWT Style (Drop-in Replacement)

import webtoken as jwt

key = "secret"
payload = {"sub": "1234567890", "name": "John Doe", "iat": 1516239022}
token = jwt.encode(payload, key, algorithm="HS256")

decoded = jwt.decode(token, key, algorithms=["HS256"])
print(decoded)
# {'sub': '1234567890', 'name': 'John Doe', 'iat': 1516239022}

Asyncio variants

import webtoken as wt

# The rust based encode/decode release the GIL
# You can send them away on asyncio.to_thread(), or use the provided wrappers

payload = {"name": "Bob"}
token = await wt.encode_async(payload, "secret", algorithm="HS256")

decoded = await wt.decode_async(token, "secret", algorithms=["HS256"])
print(decoded)
# {'name': 'Bob'}

Crypto / base64 complementary utils

Since webtoken already has aws-lc-rs in its standalone module, it exposes several auxiliary utilities.

This, for example, allows running tests, such as the PyJWT ported test suites, without importing cryptography.

import webtoken as wt


wt.base64url_encode('bob')    # utf8 strings or bytes
# b'Ym9i'

wt.base64url_decode(b'Ym9i').decode()
# 'bob'

wt.random_bytes(7)       # cryptographically secure random bytes 
# b'j>A\x0cj\xac\x7f'

priv, pub = wt.generate_key_pair('rs256')
# pub = b'-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhki.......a2ODLeYTResxi\nnQIDAQAB\n-----END PUBLIC KEY-----\n'

Compatibility

Effort is made to make toke as compatible as possible with PyJWT. For compatibility details, See the readme under tests.

Crypto

The crypto backend used by webtoken is aws-lc-rs.

Supported algorithms

PyJWT compat -

  • HS256
  • HS384
  • HS512
  • RS256
  • RS384
  • RS512-
  • ES512

Also -

  • ES256K
  • ML-DSA-65

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

webtoken-0.4.1.tar.gz (95.6 kB view details)

Uploaded Source

Built Distribution

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

webtoken-0.4.1-cp311-abi3-manylinux_2_38_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.38+ x86-64

File details

Details for the file webtoken-0.4.1.tar.gz.

File metadata

  • Download URL: webtoken-0.4.1.tar.gz
  • Upload date:
  • Size: 95.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Manjaro Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for webtoken-0.4.1.tar.gz
Algorithm Hash digest
SHA256 4a2ec5e7110c5c26e9a877112712b7f14eb6ed8110f4f54949e9038c9bd80576
MD5 48d1634c07d460849293d69204299b15
BLAKE2b-256 85cdd1005137ddcce64da4963d08dac3cc4a2e34cbef249291b5d5bf49566771

See more details on using hashes here.

File details

Details for the file webtoken-0.4.1-cp311-abi3-manylinux_2_38_x86_64.whl.

File metadata

  • Download URL: webtoken-0.4.1-cp311-abi3-manylinux_2_38_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.11+, manylinux: glibc 2.38+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Manjaro Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for webtoken-0.4.1-cp311-abi3-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 9aff038b6bbe7bb91dd7762ae3880a22cfbe271a8a6d68ae98c20cfa52e10844
MD5 7c690f5e88bddb237668a962f8b2ae43
BLAKE2b-256 1125ad885025d5735d55205b8e7e189ce1f2ded92803fa3316febe995f02b0c2

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