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.2.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.2-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.2.tar.gz.

File metadata

  • Download URL: webtoken-0.4.2.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.2.tar.gz
Algorithm Hash digest
SHA256 fc53efcab887c781b86687b4ae676e0310f72baceb90c81b1ad154f845ddbcd8
MD5 48f7957e27ef25b962f37803eab81f64
BLAKE2b-256 9da08d41fcc76645561920aa88a7662a3f89ad2356632997c7682fd8f07a559b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: webtoken-0.4.2-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.2-cp311-abi3-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 6c86c21417a153b756697c105663e21a17b3577bafeb3e61045f8c25930cc79f
MD5 b8dac0d8eb9b137c54a6067157cfb988
BLAKE2b-256 77e166a761c246836e58086b6787212ae3a114c3addacf9ed1e0600c237f5f89

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