Skip to main content

A lightweight, pure Python JWT implementation

Project description

Your updated README.md for the Butterfly JWT library looks good and includes concise, clear instructions for installation, usage, and features. Here’s the enhanced content you can use:

# Butterfly JWT

Butterfly JWT is a lightweight, pure Python library for handling JSON Web Tokens (JWT) efficiently and securely, with a focus on ease of integration and high security standards. This library is designed to work without any external dependencies, making it an excellent choice for projects requiring minimal setup.

## Installation

To install Butterfly JWT, simply run the following command in your terminal:

```bash
pip install butterfly-jwt

Usage

Encoding a Token

To encode a new JWT, provide a secret key and payload. Optionally, specify the email for encryption and set the development mode:

from butterfly import jwt

# Create a token
secret_key = "your_secret_key"
payload = {"user_id": 123, "username": "example_user"}
email = "user@example.com"
token = jwt.encode(secret_key, payload, email=email)

Decoding a Token

To decode and verify a JWT, use the decode function. This function will check the token's validity, signature, and expiration:

from butterfly import jwt

try:
    payload = jwt.decode(secret_key, token)
    print("Token is valid. Payload:", payload)
except ValueError as e:
    print("Token verification failed:", str(e))

Using the ButterflyJWT Class

For more detailed control, you can directly use the ButterflyJWT class:

from butterfly.jwt import ButterflyJWT

# Create a JWT instance
jwt_handler = ButterflyJWT(secret_key)

# Create a token
token = jwt_handler.create_token(payload, email="user@example.com")

# Verify and decode a token
try:
    payload = jwt_handler.verify_token(token)
    print("Token is valid. Payload:", payload)
except ValueError as e:
    print("Token verification failed:", str(e))

Features

  • Pure Python implementation: Ensures compatibility and easy deployment.
  • No external dependencies: Ideal for environments with strict dependency requirements.
  • URL-safe Base64 encoding: Securely encodes tokens to be URL-friendly.
  • HMAC-SHA256 signature: Provides a robust mechanism for verifying token integrity.
  • Token expiration checking: Automatically verifies token expiry to maintain security.
  • Constant-time signature verification: Prevents timing attacks on token signatures.

License

This project is licensed under the MIT License - see the LICENSE file for details.


This version enhances clarity on the library’s features, provides detailed code examples for both encoding and decoding tokens, and includes an example of handling email encryption within the token. It should be quite helpful for users of your library!

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

butterfly_jwt-0.2.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

butterfly_jwt-0.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file butterfly_jwt-0.2.0.tar.gz.

File metadata

  • Download URL: butterfly_jwt-0.2.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for butterfly_jwt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 25cf87e473e5552a997cbea8afabb2e539582c73fd4048f41c17435b89fa5cff
MD5 964b26f525d58df35afb9520bd18d1d6
BLAKE2b-256 09c15a17218598f6dfccc782f98d8b9a5dc33a1a0cb53f6771d3f84093e53ad1

See more details on using hashes here.

File details

Details for the file butterfly_jwt-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: butterfly_jwt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for butterfly_jwt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c2df95cfc04fc7f54a821640666a75951888eb2f298d57362836b7d37871637
MD5 72eb192eed3590e062d3b48244fc4b4c
BLAKE2b-256 1dffc539f20cbe69c4faed8b3576b05f9531e4290c9d1a99f5a9d74e0bf82510

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