Skip to main content

Rust-backed PyJWT-compatible JWT library for Python

Project description

pyjwt-rs

jwt_rsPyJWT 호환을 목표로 하는 Rust 기반 Python 확장 모듈입니다.

핵심 목표는 두 가지입니다.

  • 같은 코드에 import jwt_rs as jwt만 바꿔서 동작할 것
  • Rust 코어로 주요 공개키 JWT workload에서 PyJWT보다 더 빠를 것

Current Status

현재 공개 표면은 PyJWT 스타일을 유지합니다.

  • encode(payload, key, algorithm="HS256", headers=None)
  • decode(token, key, algorithms=None, options=None, audience=None, issuer=None, leeway=0)
  • decode_complete(...)
  • get_unverified_header(token)
  • PyJWS, PyJWK, algorithm registry

현재 지원 알고리즘:

  • HMAC: HS256, HS384, HS512
  • RSA: RS256, RS384, RS512, PS256, PS384, PS512
  • EC: ES256, ES384, ES512, ES256K
  • EdDSA

테스트 상태:

  • 324 passed

품질 정책:

  • 테스트는 hidden warning 없이 통과해야 합니다. CI는 -W error 기반 게이트를 사용합니다.
  • 의도된 skip은 .quality/pytest-allowlist.json에 명시되어야 합니다.
  • 릴리스/호환성 작업은 공개 GitHub issue와 milestone으로 추적합니다.
  • 자세한 운영 정책은 CONTRIBUTING.md, 호환성 갭은 COMPATIBILITY_CHECKLIST.md 에서 관리합니다.

Usage

import jwt_rs as jwt

token = jwt.encode({"sub": "alice"}, "secret", algorithm="HS256")
claims = jwt.decode(token, "secret", algorithms=["HS256"])
header = jwt.get_unverified_header(token)

Performance

성능 목표는 모든 경로 일괄 2배가 아니라, 먼저 실사용 공개키 경로에서 PyJWT를 확실히 추월하는 것입니다.

아래 블록은 benchmark 스크립트로 자동 생성됩니다. 수동으로 적지 않습니다.

Auto-generated from scripts/benchmark_same_api.py on 2026-04-21T07:14:04+00:00 using --iterations 150 --warmup 20.

현재 same-API benchmark 기준:

Case encode decode decode_complete
hs256 1.43x 2.10x 2.04x
rs256 59.10x 2.15x 2.13x
es256 3.12x 1.76x 1.81x
eddsa 1.59x 1.06x 1.06x

좋은 구간:

  • rs256.encode: jwt_rsPyJWT 대비 59.10x
  • es256.encode: jwt_rsPyJWT 대비 3.12x
  • es256.decode: jwt_rsPyJWT 대비 1.76x
  • eddsa.encode: jwt_rsPyJWT 대비 1.59x

아직 미달인 구간:

  • 현재 주요 추적 경로는 모두 PyJWT 이상입니다.

해석:

  • 1.00x 초과면 jwt_rs가 빠릅니다.
  • 2.00x 이상이면 README 목표인 PyJWT 대비 2배를 넘긴 것입니다.
  • 현재 목표는 특히 공개키 경로에서 이 값을 끌어올리는 것입니다.

벤치 재현 명령:

uv run --with pyjwt python scripts/benchmark_same_api.py --iterations 150 --warmup 20

README 자동 갱신 명령:

uv run python scripts/update_readme_bench.py

Development

source "$HOME/.cargo/env"
cd pyjwt-rs
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"
uv run --with maturin maturin develop
uv run pytest -q

Notes

  • Python은 호환 인터페이스를 담당하고, 코어 sign/verify hot path는 Rust가 담당합니다.
  • 현재 공개키 알고리즘 경로는 Rust 내부 OpenSSL backend를 사용합니다.
  • options={"verify_signature": False} 경로는 별도 insecure decode 흐름을 사용합니다.
  • 완전한 PyJWT parity를 목표로 하지만, 성능 최적화를 위해 내부 구현은 PyJWT와 다릅니다.
  • 배포 버전과 PyJWT 호환 버전 구분은 VERSIONING.md 에 정리했습니다.

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

pyjwt_rs-1.2.2.tar.gz (181.0 kB view details)

Uploaded Source

Built Distributions

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

pyjwt_rs-1.2.2-cp312-cp312-win_amd64.whl (2.7 MB view details)

Uploaded CPython 3.12Windows x86-64

pyjwt_rs-1.2.2-cp312-cp312-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyjwt_rs-1.2.2-cp312-cp312-macosx_10_12_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

pyjwt_rs-1.2.2-cp310-cp310-manylinux_2_28_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyjwt_rs-1.2.2-cp310-cp310-manylinux_2_28_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

File details

Details for the file pyjwt_rs-1.2.2.tar.gz.

File metadata

  • Download URL: pyjwt_rs-1.2.2.tar.gz
  • Upload date:
  • Size: 181.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyjwt_rs-1.2.2.tar.gz
Algorithm Hash digest
SHA256 bf430e71fd772e0e23ed1e69bc2840505a3c9edc89e32f698492ae8bbd270673
MD5 ce73d6cdbc9b6bb11daaa5f836425fed
BLAKE2b-256 bda139b122034986cb4e130f225a7d7a4ec39d711c04d2bc8d0d02f17d680ff1

See more details on using hashes here.

File details

Details for the file pyjwt_rs-1.2.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pyjwt_rs-1.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyjwt_rs-1.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2dcf5a5dbfda3cfcf65263f6248f9f16a46106bbfa962355fe169e855d5861ed
MD5 d4b618b2db31d6b216fd3b3c62c2f8ac
BLAKE2b-256 218e045e1b65c7b62b211932deba4f319bb576507edb30f6cb02cf935f691234

See more details on using hashes here.

File details

Details for the file pyjwt_rs-1.2.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyjwt_rs-1.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fba4cafdfdbe2f65b7b5f3df38ffa1042cbd0862367afc95ff9567a4e67f5038
MD5 f867f9d93d4f604a11742d728bd1b1f4
BLAKE2b-256 0fccdd7582650f41e0feed2976edb15b7f5c6fdd291be65beddb90ab62baf147

See more details on using hashes here.

File details

Details for the file pyjwt_rs-1.2.2-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyjwt_rs-1.2.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dd09613d7ddd2726f7529d4260c4802ddc5eff5b0e574ad89e539617c9829dae
MD5 dafe021d83fe3934a7bdfae5aa617a32
BLAKE2b-256 abd8ed66682a8b870b39aba1be0442f6ea3e5286f4c3dcadc94a48e8ad02dcc1

See more details on using hashes here.

File details

Details for the file pyjwt_rs-1.2.2-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyjwt_rs-1.2.2-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6bd94da460216257751e66ce93558f248c9d01660e0e7265892a9ff0cc2d48a9
MD5 b2506ae4c973341232d5bfaf69e978eb
BLAKE2b-256 8d8122f295453c44858b93ab971e2c2349b5ade66c7653e2fe12f8e75e0ffd54

See more details on using hashes here.

File details

Details for the file pyjwt_rs-1.2.2-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyjwt_rs-1.2.2-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b4440d2a8e894dd2bdb377014c5b756b3b29a245e3e82481d0248b627edca1eb
MD5 a8f4a7443a7f357f316184e818141fd0
BLAKE2b-256 e1e84d0de84f44d44bae0abb34541bb8054b9879d6d5a77fdfdff8a93fc7b9e3

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