A high-performance, framework-agnostic authorization and session management library for Python
Project description
AuthTuna 🐟
The Modern Async Security Framework for FastAPI
AuthTuna is a battle-tested, async-first security framework for Python that provides a complete, production-ready foundation for authentication, authorization, and session management. Stop reinventing the wheel and start shipping secure applications faster.
Designed for developers who need to build complex, multi-tenant systems with zero compromise on security or performance, AuthTuna combines a powerful hierarchical permission model with advanced, stateful session management to actively defend against a wide range of modern threats.
Why AuthTuna?
🛡️ Production-Grade Security, Out of the Box: From hijack detection to granular, object-level permissions, get the features of an enterprise-grade auth system without the complexity.
🚀 Blazing-Fast & Async-First: Built on asyncio and SQLAlchemy 2.0, AuthTuna is designed for high-concurrency environments and won't block your event loop.
🧩 Batteries-Included, But Pluggable: Use our pre-built routers and templates to get started in minutes, or integrate the core engine into your existing architecture.
👨💻 Unbeatable Developer Experience: With first-class FastAPI support, ready-to-use dependencies, and clear, Pydantic-based models, securing your API has never been easier.
Features & Philosophy
Robust security should be accessible, not an afterthought. AuthTuna provides the tools to manage complex authorization logic in a way that is both intuitive and highly secure.
- ⚔️ Granular, Hierarchical RBAC: Go beyond simple roles. Implement multi-level, context-aware permissions (e.g., Organization → Project → Resource) and resource-based rules (e.g., "users can only edit their own posts").
- 🔒 Advanced Session Management: Our unique dual-state, server-side session model provides the security of server-side validation with the performance of JWTs. Features full programmatic control, hijack detection, and automatic invalidation.
- ⚡ High-Performance Async Core: All database operations are fully asynchronous using the latest SQLAlchemy features with asyncpg for PostgreSQL and aiosqlite for SQLite.
- 📧 Built-in Email Flows: Ready-to-use and customizable flows for email verification, password resets, and MFA notifications with included Jinja templates.
- 🌐 Social & Passwordless Login: Optional, pre-built routers for common social providers (Google, GitHub, etc.) and passwordless authentication.
📦 Installation
pip install authtuna
⚙️ Configuration
AuthTuna is configured through environment variables, making it perfect for containerized deployments. Key variables include:
DEFAULT_DATABASE_URI: Your async database URL (e.g.,postgresql+asyncpg://user:pass@host/db)SESSION_TOKEN_NAME: The cookie name for your session (default:session_token)SESSION_LIFETIME_SECONDS: The duration of an active session.EMAIL_ENABLED/ SMTP settings for email flows.
For a full list of options, see the documentation or authtuna/core/config.py.
🚀 Quick Start
Secure your FastAPI application in under 20 lines of code.
from fastapi import FastAPI, Depends
from authtuna.middlewares.session import DatabaseSessionMiddleware
from authtuna.integrations.fastapi_integration import get_current_user, PermissionChecker, RoleChecker
from authtuna.core.database import User
# Initialize the FastAPI app and add the session middleware
app = FastAPI()
app.add_middleware(DatabaseSessionMiddleware)
# A simple protected route that requires a valid session
@app.get("/me")
async def whoami(user: User = Depends(get_current_user)):
return {"id": user.id, "username": user.username, "email": user.email}
# Protect a route with a specific, scoped permission
@app.get("/projects/{project_id}")
async def read_project(
project_id: str,
user: User = Depends(PermissionChecker("project:read", scope_from_path="project_id"))
):
return {"project_id": project_id, "user": user.id}
# Protect a route with a simple role check
@app.get("/admin")
async def admin_area(user: User = Depends(RoleChecker("admin", "moderator"))):
return {"message": f"Welcome, {user.username}"}
🛠️ Batteries-Included: Pre-built Routers
AuthTuna ships with optional, pre-built routers for common authentication, social login, and administration tasks to get you started even faster.
from fastapi import FastAPI
from authtuna.routers import auth as auth_router, social as social_router, admin as admin_router
from authtuna.middlewares.session import DatabaseSessionMiddleware
app = FastAPI()
app.add_middleware(DatabaseSessionMiddleware)
# Mount the pre-built routers
app.include_router(auth_router.router, prefix="/auth", tags=["Authentication"])
app.include_router(social_router.router, prefix="/auth", tags=["Social Login"])
app.include_router(admin_router.router, prefix="/admin", tags=["Administration"])
🤝 Community & Support
- 🤝 Contributing: Contributions are welcome! Please see CONTRIBUTING.md for details on how to get started.
- 🛡️ Security: If you discover a security vulnerability, please see our security policy for how to report it.
🐟 AuthTuna: Secure, Fast, and Actually Fun to Use
AuthTuna is built by developers who care about security, performance, and developer happiness. We believe you shouldn't have to choose between robust security and a great developer experience. Try AuthTuna and see how easy secure can be.
No hype, no snake oil—just a modern, async security framework that works. (And yes, we eat our own dogfood!)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file authtuna-0.1.5.tar.gz.
File metadata
- Download URL: authtuna-0.1.5.tar.gz
- Upload date:
- Size: 65.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
761d82c15826f812261347287367315968bc15be128d38024bea5101b51c659b
|
|
| MD5 |
ec78a3e135bffe415d224174f9f2ad1f
|
|
| BLAKE2b-256 |
0296bfd8ceb477da1afa9c8631049daa093ce6c2e5b5f90132ddbb7f928782ce
|
Provenance
The following attestation bundles were made for authtuna-0.1.5.tar.gz:
Publisher:
publish-on-push.yml on shashstormer/AuthTuna
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
authtuna-0.1.5.tar.gz -
Subject digest:
761d82c15826f812261347287367315968bc15be128d38024bea5101b51c659b - Sigstore transparency entry: 521023975
- Sigstore integration time:
-
Permalink:
shashstormer/AuthTuna@39cf6fc82fff002e61045847931340a95be01825 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/shashstormer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-on-push.yml@39cf6fc82fff002e61045847931340a95be01825 -
Trigger Event:
push
-
Statement type:
File details
Details for the file authtuna-0.1.5-py3-none-any.whl.
File metadata
- Download URL: authtuna-0.1.5-py3-none-any.whl
- Upload date:
- Size: 87.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d47da93e11b034b8c69799c86bccb8fce17e2e606d04d913463ce18ed51b5d0a
|
|
| MD5 |
eb746b4073506f9f43dae59e3b976209
|
|
| BLAKE2b-256 |
4433636b743269729f28a048f3bb879bccd493c36f5ea4ca3921f55553322def
|
Provenance
The following attestation bundles were made for authtuna-0.1.5-py3-none-any.whl:
Publisher:
publish-on-push.yml on shashstormer/AuthTuna
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
authtuna-0.1.5-py3-none-any.whl -
Subject digest:
d47da93e11b034b8c69799c86bccb8fce17e2e606d04d913463ce18ed51b5d0a - Sigstore transparency entry: 521024002
- Sigstore integration time:
-
Permalink:
shashstormer/AuthTuna@39cf6fc82fff002e61045847931340a95be01825 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/shashstormer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-on-push.yml@39cf6fc82fff002e61045847931340a95be01825 -
Trigger Event:
push
-
Statement type: