Skip to main content

user-registration-sqlalchemy

SQLAlchemy repository adapter for the user-registration Python package.

This package provides a SQLAlchemy 2.x implementation of the repository interfaces required by the framework-agnostic registration service.

It keeps persistence concerns separate from registration business logic.

Features

  • SQLAlchemy 2.x repository implementation
  • Implements the UserRepository contract from user-registration
  • SQLAlchemy 2.x synchronous repository implementation
  • User persistence and lookup
  • Username/email duplicate detection
  • Database constraint error handling
  • Compatible with SQLite, PostgreSQL, MySQL and other SQLAlchemy-supported databases
  • Framework independent

Async SQLAlchemy

The current adapter exposes a synchronous Session-based repository.

Async SQLAlchemy support is not part of the current adapter contract.

Installation

Install the core package and SQLAlchemy adapter:

pip install user-registration user-registration-sqlalchemy

Or:

pip install user-registration-sqlalchemy

The adapter declares user-registration and SQLAlchemy as dependencies.

Architecture

The adapter implements the repository boundary defined by the core package:

                 RegistrationService
                         │
                         ▼
                 UserRepository
                     Protocol
                         │
                         ▼
          SQLAlchemyUserRepository
                         │
                         ▼
                  SQLAlchemy 2.x
                         │
                         ▼
                     Database

The registration service does not need to know whether the application uses SQLite, PostgreSQL, MySQL, or another supported database.

User Model

The adapter provides a SQLAlchemy user model suitable for persistence.

Conceptually:

User
├── id
├── username
├── email
├── password_hash
└── timestamps / persistence fields

Passwords are stored as password hashes rather than plaintext passwords.

Password hashing itself is handled by the core registration package.

Repository

The primary adapter component is:

SQLAlchemyUserRepository

It implements the core repository contract and provides operations required by the registration service, including:

create()
get_by_username()
get_by_email()
exists_by_username()
exists_by_email()

The exact available methods are determined by the package version.

Example

A typical application can compose the components as follows:

from user_registration import RegistrationService
from user_registration_sqlalchemy import SQLAlchemyUserRepository

repository = SQLAlchemyUserRepository(...)

service = RegistrationService(
    repository=repository,
    ...
)

The application remains responsible for creating and configuring its SQLAlchemy engine/session infrastructure.

Database Independence

Because the adapter uses SQLAlchemy, the same repository architecture can support different databases.

For example:

Development
    │
    ▼
SQLite

Testing
    │
    ▼
PostgreSQL

Production
    │
    ▼
PostgreSQL / MySQL / other SQLAlchemy-supported DB

The registration service does not need to change when the persistence technology changes.

Duplicate Users

The adapter translates database uniqueness violations into the core package's duplicate-user domain error.

For example, a unique constraint on:

username
email

can be mapped to the registration layer rather than exposing SQLAlchemy-specific exceptions to the application.

This allows the application layer to consistently handle duplicate registration:

Database
   │
   │ IntegrityError
   ▼
SQLAlchemy Adapter
   │
   │ DuplicateUserError
   ▼
RegistrationService
   │
   ▼
Application / API

Transaction Management

The application owns the SQLAlchemy engine/session lifecycle.

The adapter should be integrated into the application's existing transaction management strategy rather than creating an independent application-wide database lifecycle.

This allows applications to control:

  • sessions
  • transactions
  • connection pools
  • isolation levels
  • database configuration
  • migrations

Testing

Run the SQLAlchemy integration tests from the repository root:

.venv/bin/python -m pytest tests/integration/test_sqlalchemy_repository.py -v

Run all tests:

.venv/bin/python -m pytest -v

Development

Install the adapter in editable mode:

.venv/bin/python -m pip install -e "./adapters/sqlalchemy[dev]"

Run Ruff:

.venv/bin/python -m ruff check adapters/sqlalchemy

Check formatting:

.venv/bin/python -m ruff format --check adapters/sqlalchemy

Run MyPy:

.venv/bin/python -m mypy adapters/sqlalchemy

Compatibility

The adapter requires:

  • Python 3.12+
  • SQLAlchemy >=2.0,<3.0
  • user-registration >=0.1.0,<1.0.0

Core package:

FastAPI adapter:

License

MIT License.

Visit https://github.com/ShamimurRahmanShuvo/user_registration/tree/main/docs for more detials.

Metadata

Release files for user-registration-sqlalchemy 1.0.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 user-registration-sqlalchemy 1.0.1
File Size Uploaded
user_registration_sqlalchemy-1.0.1.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for user-registration-sqlalchemy 1.0.1
File Interpreter ABI Platform
user_registration_sqlalchemy-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.7 kB

Release files / user_registration_sqlalchemy-1.0.1.tar.gz

Download URL user_registration_sqlalchemy-1.0.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
611e68bea5d58d83ef0b295905c8f2042880cdd8965d5fa9a57068f0300e5754
BLAKE2b-256 checksum
How to use checksums
156a669beb685117dce3ebc035ff0ac415dd01a562c539feb516a80954c4106b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / user_registration_sqlalchemy-1.0.1-py3-none-any.whl

Download URL user_registration_sqlalchemy-1.0.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3388688807dc4d42efd0feab6a447b697af54dc2b077b86107235939d96d402
BLAKE2b-256 checksum
How to use checksums
fa971f123cf276da2a329a12df36828d80e5e8b2425e5b861976ec457bb99015
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

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