Skip to main content

A small, opinionated JWT toolkit: create, verify, expire, and handle errors without writing the same PyJWT boilerplate every project.

Project description

fastjwt-kit

A small, opinionated wrapper around PyJWT that handles the boilerplate every project rewrites: token creation, expiry, claim validation, and clean error handling — without you having to import jwt exceptions directly.

Install

pip install fastjwt-kit

Quickstart

from fastjwt_kit import create_access_token, verify_token, TokenExpiredError

token = create_access_token(subject="user-123", secret="change-me")

try:
    claims = verify_token(token, secret="change-me")
    print(claims["sub"])  # "user-123"
except TokenExpiredError:
    print("Token expired — ask the user to log in again")

That's it — no manual exp math, no catching raw jwt.ExpiredSignatureError.

Access + refresh tokens

from fastjwt_kit import create_access_token, create_refresh_token

access = create_access_token(subject="user-123", secret="change-me")          # 15 min default
refresh = create_refresh_token(subject="user-123", secret="change-me")        # 7 days default

Custom expiry, issuer, audience, and extra claims

import datetime as dt
from fastjwt_kit import create_token, verify_token

token = create_token(
    subject="user-123",
    secret="change-me",
    expires_in=dt.timedelta(hours=1),
    issuer="my-app",
    audience="my-app-clients",
    extra_claims={"role": "admin"},
)

claims = verify_token(token, secret="change-me", issuer="my-app", audience="my-app-clients")

Error handling

All errors inherit from TokenError, so you can catch broadly or specifically:

from fastjwt_kit import TokenError, TokenExpiredError, InvalidTokenError, InvalidClaimsError

try:
    claims = verify_token(token, secret="change-me")
except TokenExpiredError:
    ...  # token was valid but has expired
except InvalidClaimsError:
    ...  # issuer/audience didn't match
except InvalidTokenError:
    ...  # malformed or tampered token
except TokenError:
    ...  # catch-all

API

Function Description
create_token(subject, secret, *, expires_in, ...) Create a JWT with full control over claims.
create_access_token(subject, secret, ...) Create a short-lived token (default 15 min), tagged type: access.
create_refresh_token(subject, secret, ...) Create a long-lived token (default 7 days), tagged type: refresh.
verify_token(token, secret, *, algorithm, issuer, audience) Decode and validate a token, raising fastjwt_kit exceptions.

Why not just use PyJWT directly?

You can! This package just wraps the parts everyone ends up rewriting: expiry defaults, issuer/audience checks, and exception types that don't leak the underlying library. If you only need raw encode/decode, PyJWT alone is enough.

Roadmap

  • Password hashing module
  • FastAPI signup/login router + get_current_user dependency
  • Config/env validation helpers

Feedback and issues welcome — this is an early release and will evolve based on real usage.

License

MIT

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

fastjwt_kit-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

fastjwt_kit-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file fastjwt_kit-0.1.0.tar.gz.

File metadata

  • Download URL: fastjwt_kit-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for fastjwt_kit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5b8c61f269c69bc8c62010af8b5e2d7424c795b17d41bee4822237719a857c51
MD5 4ba81267d907805307254d80573ab7a2
BLAKE2b-256 85e38f90b655aa5a3ae92ded1d441b2d88e486de94b299b7d7969b5f6524e869

See more details on using hashes here.

File details

Details for the file fastjwt_kit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastjwt_kit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for fastjwt_kit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0fc25998cdedba9ab289b801906f2ff2548fd8398c28395fddcc736a3bf6d6b9
MD5 6a7b3a3314327ad65520149eadf6158c
BLAKE2b-256 fa6d71300ed67cc06db0379ceac516728deee59663ef316dc239cbf4f272380f

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