Skip to main content

Reusable authentication library for FastAPI applications.

Status: Beta. Open for feedback.

Features

  • JWT-based access and refresh token rotation
  • Email verification and password reset flows
  • Google OIDC OAuth client
  • Argon2id password hashing
  • Account lockout after repeated failures
  • Role / permission guards
  • Protocol-based repository contracts (SQLAlchemy + Beanie/MongoDB backends included)
  • Framework-agnostic core (no FastAPI required to use services)

Installation

# Core — no web framework dependency
pip install blenx-auth

# With FastAPI integration layer (pulls the SQLAlchemy backend too)
pip install blenx-auth[fastapi]

# With the SQLAlchemy backend only (DB driver is your choice)
pip install blenx-auth[sqlalchemy]

# With the Beanie (MongoDB) adapter
pip install blenx-auth[beanie]

Structure

src/blenx_auth/
├── __init__.py
├── core/                   # Framework- and storage-free business core
│   ├── constants.py        # Security invariants / enums
│   ├── exceptions.py       # Domain exceptions
│   ├── dto.py              # Plain data objects crossing the ports
│   ├── ports.py            # Repository + email-sender protocols
│   ├── email.py            # NullEmailSender + get_email_sender factory
│   ├── password.py         # Argon2id hashing + policy
│   ├── jwt.py              # TokenService
│   ├── schemas.py          # Pydantic wire models (FastAPI adapter)
│   ├── settings.py         # AuthSettings protocol (pure Python)
│   └── services/           # AuthenticationService, EmailVerificationService,
│                           # PasswordResetService
├── sqlalchemy/             # SQLAlchemy (PostgreSQL) adapter — default backend
│   ├── base.py             # AuthBase + UserId (uuid)
│   ├── models.py           # User / RefreshToken / OAuthAccount ORM models
│   ├── repositories.py     # SQLAlchemy*Repository protocol implementations
│   └── session.py          # create_session_factory(...) helper
├── beanie/                 # Beanie (MongoDB) adapter — optional [beanie]
│   ├── models.py           # User / RefreshToken / OAuthAccount Documents
│   ├── bootstrap.py        # init_beanie_db(...) helper
│   └── repositories.py     # Beanie*Repository protocol implementations
└── fastapi/                # Optional FastAPI integration subpackage [fastapi]
    ├── __init__.py
    ├── composition.py      # SQLAlchemyAuth / BeanieAuth composition roots
    ├── current_user.py     # Current-user dependency factory
    ├── exception_handlers.py  # auth_error_handler
    ├── google_oauth.py     # Google OIDC client (pure httpx-oauth)
    ├── permissions.py      # make_permission_guards(...) dependency factories
    └── routers/            # make_auth_router / make_users_router / make_oauth_router

The host application wire-up is a composition root: pick a backend, bind the services, and hand the result to the router factories.

from blenx_auth.fastapi import SQLAlchemyAuth, make_auth_router, make_users_router

auth = SQLAlchemyAuth(settings=settings, session_factory=session_factory)
app.include_router(make_auth_router(auth))
app.include_router(make_users_router(auth))

Examples

See the examples/ directory for:

  • standalone.py — wiring core services to in-memory fakes (no DB, no web framework)
  • sqlalchemy_example.py — using the SQLAlchemy repositories
  • beanie_example.py — using the Beanie (MongoDB) repositories

License

MIT

Metadata

Release files for blenx-auth 0.3.3

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

Source distribution (sdist)

Source distribution for blenx-auth 0.3.3
File Size Uploaded
blenx_auth-0.3.3.tar.gz 484.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for blenx-auth 0.3.3
File Interpreter ABI Platform
blenx_auth-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 558.8 kB

Release files / blenx_auth-0.3.3.tar.gz

Download URL blenx_auth-0.3.3.tar.gz
Size 484.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a8bd80d0e6e496957b99b2b161d01c56e92916c8e1a3cc16d6b3658f2c97e73e
BLAKE2b-256 checksum
How to use checksums
7217274633f2991c9e1891858d5ff4887fcde416c67f9fd8e03d37adeeec1094
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.4

Release files / blenx_auth-0.3.3-py3-none-any.whl

Download URL blenx_auth-0.3.3-py3-none-any.whl
Size 74.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd3bea5f9165cbb8d7c0a345cb7d073b99eeff1ec8a14f9d45028ea05c57af22
BLAKE2b-256 checksum
How to use checksums
ac5435a5fc3ec091298a4c767886d0c416c70e38fbbca4d3065da36b08d8c22b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.4

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

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