Skip to main content

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.

Metadata

Release files for tokenly-auth 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tokenly-auth 1.0.0
File Size Uploaded
tokenly_auth-1.0.0.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tokenly-auth 1.0.0
File Interpreter ABI Platform
tokenly_auth-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.8 kB

Release files / tokenly_auth-1.0.0.tar.gz

Download URL tokenly_auth-1.0.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dbfc91da33ac35cf148dea4d54e91b0d6072a8157571ce60f7777244300d7552
BLAKE2b-256 checksum
How to use checksums
f13cdc50bcbaf9d368604ac9658a95245b908cc00cdd4f15b1d2c1c8bab959a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / tokenly_auth-1.0.0-py3-none-any.whl

Download URL tokenly_auth-1.0.0-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f5e875425499b8c2e33b7477f438ca3a87c2e7b19870b5a37b6a38ce6a6054e
BLAKE2b-256 checksum
How to use checksums
87557ce3297c41a2b67d3d5cae2ab6e796317dc4aa0095805949dbdaabf72067
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page