Skip to main content

Lightweight and extensible Python library for generating and verifying JWT tokens with multiple algorithms (HS256, ES256, RS256, etc.). Built on PyJWT, it provides an intuitive interface, flexible configuration, and secure key storage.

Project description

๐Ÿ” JWTifyPy

JWTifyPy is a lightweight and extensible Python library for generating and verifying JWT tokens, with support for various algorithms like HS256, ES256, RS256, and more. Built on top of PyJWT, it offers an intuitive interface, easy configuration, and secure key storage โ€” everything you need to work with JWTs.


๐Ÿ“ฆ Installation

pip install jwtifypy

โš™๏ธ Optional Dependencies

To support environment variables (.env) and advanced cryptographic algorithms (ES256), you may install optional packages like python-dotenv and cryptography.

Use extras to include these:

  • With dotenv support:
pip install jwtifypy[env]
  • With cryptography support:
pip install jwtifypy[crypto]
  • Full feature set:
pip install jwtifypy[full]

๐Ÿš€ Quick Start

๐Ÿ”ง Initialization

from jwtifypy import JWTConfig

JWTConfig.init(config={
    "keys": {
        "algorithm": "HS256",
        "secret": "env:MY_SECRET_ENV"
    }
})

๐Ÿ”น Basic Examples

from jwtifypy import JWTManager

# ๐Ÿ“ฅ Default token using the "default" key
token = JWTManager.create_access_token("user123")
print(token)
# ๐Ÿ‘‰ eyJhbGciOiJIUzI1NiIsInR5cCI6...

# ๐Ÿ”‘ Token using a named key
admin_token = JWTManager.using("admin").create_access_token("admin42")
print(admin_token)
# ๐Ÿ‘‰ eyJhbGciOiJSUzI1NiIsInR5cCI6...

๐Ÿ“› Add an Issuer (iss)

token_with_issuer = (
    JWTManager.using("admin")
    .with_issuer("my-service")
    .create_access_token("issuer-user")
)
print(token_with_issuer)

๐ŸŽฏ Add an Audience (aud)

# ๐ŸŽฏ Single audience
token_with_aud = (
    JWTManager.using("admin")
    .with_audience("client-app")
    .create_access_token("aud-user")
)
print(token_with_aud)

# ๐Ÿ“ฆ Multiple audiences (for decoding)
token_with_multiple_aud = (
    JWTManager.using("admin")
    .with_audience(
        audience_for_encoding="web",
        audience_for_decoding=["web", "mobile"]
    )
    .create_access_token("multi-aud-user")
)
print(token_with_multiple_aud)

๐Ÿค– Reuse Manager Conveniently

# ๐Ÿค– Create a separate manager using the "admin" key
JWTAdmin = JWTManager.using("admin")

# ๐ŸŽฏ Audience
token_with_aud = (
    JWTAdmin
    .with_audience("client-app")
    .create_access_token("aud-user")
)
print(token_with_aud)

# ๐Ÿ”— Issuer + Audience together
token_full = (
    JWTAdmin
    .with_issuer("auth-server")
    .with_audience("bot")
    .create_access_token("full-user")
)
print(token_full)

๐Ÿ” Token Verification with iss and aud

payload = (
    JWTManager.using("admin")
    .with_issuer("auth-server")
    .with_audience("bot")
    .decode_token(token_full)
)

print(payload["sub"])  # ๐Ÿ‘‰ full-user
print(payload["aud"])  # ๐Ÿ‘‰ web
print(payload["iss"])  # ๐Ÿ‘‰ auth-server

โš™๏ธ Key Features

  • โœ… Supports HS256, ES256, RS256, and more
  • ๐Ÿ” Named key store (default, admin, service-X, etc.)
  • ๐Ÿ“ค Simple JWT creation/decoding interface
  • ๐Ÿ›  Extensible for advanced scenarios
  • โฑ Supports standard claims: sub, exp, iat, aud, iss, etc.

๐Ÿงฉ Custom Configuration

from jwtifypy import JWTConfig

JWTConfig.init(config={
    "keys": {
        # ๐Ÿ”‘ Symmetric key (HS256) using a shared secret
        "default": {
            "alg": "HS256",
            "secret": "secret"
        },

        # ๐Ÿ” Asymmetric key (RS256) using RSA keys from files
        "admin": {
            "algorithm": "RS256",
            "private_key": "file:/path/to/private.pem",
            "public_key": "file:/path/to/public.pem"
        },

        # ๐Ÿงฌ Asymmetric key (ES256) using ECDSA, private key from env
        # public_key will be auto-generated if `cryptography` is installed
        "service": {
            "alg": "ES256",
            "private_key": "env:PRIVATE_KEY"
        }
    },

    # โฑ Leeway in seconds for time validation (exp, iat)
    "leeway": 1.0,

    # โš™๏ธ Additional validation options (as in PyJWT)
    "options": {
        "verify_sub": False,
        "strict_aud": False
    }
})

๐Ÿ—‚๏ธ Project Structure

jwtifypy/
โ”œโ”€โ”€ __init__.py       # Public interface
โ”œโ”€โ”€ manager.py        # JWTManager class
โ”œโ”€โ”€ config.py         # Config and initialization
โ”œโ”€โ”€ key.py            # Key parsing/handling (HS/RS/ES)
โ”œโ”€โ”€ store.py          # JWTKeyStore
โ”œโ”€โ”€ exceptions.py     # Custom exceptions
โ””โ”€โ”€ utils.py          # Utilities

๐Ÿงช Running Tests

pytest tests/

๐Ÿ›ก๏ธ Security Recommendations

  • โ— Never hardcode secrets. Use environment variables.
  • ๐Ÿ” Prefer RS256/ES256 for service-to-service authentication.
  • โณ Set short token expiration (exp).
  • ๐Ÿ”Ž Use and validate claims (iss, aud, sub) when security matters.

๐Ÿ“œ License

MIT ยฉ 2025 Created by [LordCode Projects] / [Dybfuo Projects]

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

jwtifypy-0.2.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

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

jwtifypy-0.2.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file jwtifypy-0.2.1.tar.gz.

File metadata

  • Download URL: jwtifypy-0.2.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/6.11.0-1018-azure

File hashes

Hashes for jwtifypy-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6b8f39787b560f3b6b2b902bce9e4ac16fbb1fe8a05ca5c43b031947b82c2948
MD5 fa6a10a4dab00ca4b5c68063f3f29050
BLAKE2b-256 6bdc4f21d3c51a92e6b6d102641f5c4edd8c6ea55fc9efb7543404c87cde2e22

See more details on using hashes here.

File details

Details for the file jwtifypy-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: jwtifypy-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.13 Linux/6.11.0-1018-azure

File hashes

Hashes for jwtifypy-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cba770943735a61520e3618edded54c6529bffd8527120d1ae8f81b797d2422b
MD5 46a6f07cdcf6a6f66f390a00b0f87689
BLAKE2b-256 07ea2b4c97b0aa7a95062323e28ca59b5df3bebfd58e32cadbbe248a2c26ce1c

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