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.2

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.2
File Size Uploaded
blenx_auth-0.3.2.tar.gz 484.4 kB Details

Built distribution (wheel)

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

Total release size: 558.7 kB

Release files / blenx_auth-0.3.2.tar.gz

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

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

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

Release history Release notifications | RSS feed

0.3.3

2 release files

This release

0.3.2 This release

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