Skip to main content

A professional-grade, database-agnostic authentication and session management utility library.

Project description

Tokenly-Auth

Tokenly-Auth is a professional-grade, database-agnostic authentication and session management utility library for Python. It provides high-level security primitives without enforcing any specific database ORM or model structure, giving you total flexibility.

Core Features

  • Crypto Utilities: Argon2id password hashing and verification with brute-force protection logic.
  • Token Management: JWT creation and verification.
  • Session Utilities: Secure refresh token hashing for rotation strategies.
  • Middleware: Storage-agnostic rate limiting and authentication decorators.
  • Validation: Strict structural validation for usernames and passwords.
  • Lightweight: No dependency on SQLModel, Pydantic, or any specific database driver.

Installation

pip install tokenly-auth

Quick Start

1. Password Hashing

from tokenly_auth import Security

# Hash a password
hashed = Security["hash"]("my_secure_password")

# Verify a password
is_valid = Security["verify"]("my_secure_password", hashed)

# Reset logic (Verify old -> Hash new)
new_hash = Security["reset"](hashed, "old_password", "new_password")

2. JWT & Tokens

from tokenly_auth import TokenHandler, SessionManager

handler = TokenHandler(SECRET_KEY="your_secret_key")

# Create Access & Refresh tokens
tokens = handler.createJwt(sub="user_id_123")
# Returns: {"access_token": "...", "refresh_token": "...", "refresh_days": 7}

# Hash refresh token for secure storage
session_util = SessionManager()
storage_hash = session_util.hash_refresh_token(tokens["refresh_token"])

3. Middleware & Protection

from tokenly_auth import require_auth, TokenHandler

handler = TokenHandler(SECRET_KEY="your_secret_key")

@require_auth(jwt_handler=handler)
def protected_route(payload):
    return f"Hello {payload['sub']}"

Architecture: Why "Database Agnostic"?

Unlike other libraries that force you to use a specific ORM (like SQLAlchemy or SQLModel), Tokenly-Auth acts as a security toolkit.

  • You control the database (PostgreSQL, MongoDB, Redis, etc.).
  • You control the models.
  • Tokenly-Auth handles the heavy lifting of hashing, signing, and security logic.

Testing

pytest

License

MIT License.

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

tokenly_auth-1.0.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

tokenly_auth-1.0.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file tokenly_auth-1.0.0.tar.gz.

File metadata

  • Download URL: tokenly_auth-1.0.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for tokenly_auth-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dbfc91da33ac35cf148dea4d54e91b0d6072a8157571ce60f7777244300d7552
MD5 8594d7ad368815c5fcaccdde25ae10a0
BLAKE2b-256 f13cdc50bcbaf9d368604ac9658a95245b908cc00cdd4f15b1d2c1c8bab959a5

See more details on using hashes here.

File details

Details for the file tokenly_auth-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tokenly_auth-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for tokenly_auth-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f5e875425499b8c2e33b7477f438ca3a87c2e7b19870b5a37b6a38ce6a6054e
MD5 ebf86a6343af2a566ad22244cb979f3c
BLAKE2b-256 87557ce3297c41a2b67d3d5cae2ab6e796317dc4aa0095805949dbdaabf72067

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