Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.3.3 instead.

blenx-auth

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

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.1
File Size Uploaded
blenx_auth-0.3.1.tar.gz 78.1 kB Details

Built distribution (wheel)

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

Total release size: 129.6 kB

Release files / blenx_auth-0.3.1.tar.gz

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

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

Download URL blenx_auth-0.3.1-py3-none-any.whl
Size 51.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dab40bf85aade2e4c4299f8e346a7f80229d7bfc775fb788a77d65131451a70d
BLAKE2b-256 checksum
How to use checksums
56457b510992850c38fdca62197b1cf6e8b8daa7e255fc89b8308556e2f01c44
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

0.3.2

2 release files

This release

0.3.1 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