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.1.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.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastjwt_kit-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 c47b0a6ed9deb3a7a8b68394b46b66479c5a0cbb0f60019d7732b59422de2309
MD5 6fb541a498312e9109faada23dbe7d99
BLAKE2b-256 cbda5c4e4c277c98c101c8beb4dfcb954e2d5a9000134badae0aaf5c9543ae06

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastjwt_kit-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 09d52537d4c99049e29c7da5b3bd9cff82e807f9b896548c13ba09498c60f264
MD5 c9a84afd6b0f75e06fc74df49ca573e9
BLAKE2b-256 b01a9e6fb8dd2df4d54118cc589b1a7dba99a56e24f6210f4784f08efcc80fdc

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