SQLAlchemy integration for UserHarbor, a framework agnostic user management system for Python applications.
Project description
Project status: UserHarbor SQLAlchemy is currently in an early stage of development. The API may change frequently. The library is not ready for production use yet.
userharbor-sqlalchemy provides a SQLAlchemy-based UserStore implementation for
userharbor.
It stores:
- users,
- email verification tokens,
- sessions,
- password reset tokens,
- password hashes.
The package only handles persistence. It does not send emails, expose HTTP endpoints, or implement application-specific authentication flows.
Installation
pip install userharbor-sqlalchemy
This package depends on userharbor and SQLAlchemy 2.x.
Example usage
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from userharbor import UserHarbor
from userharbor_sqlalchemy import SQLAlchemyUserStore
from userharbor_sqlalchemy.models import UserHarborBase
class EmailSender:
def send_verification(
self,
username: str,
email: str,
verification_token: str,
) -> None:
print(f"Send verification token to {email}: {verification_token}")
def send_password_reset(
self,
username: str,
email: str,
reset_token: str,
) -> None:
print(f"Send password reset token to {email}: {reset_token}")
engine = create_engine("sqlite:///users.db")
SessionLocal = sessionmaker(bind=engine)
UserHarborBase.metadata.create_all(engine)
store = SQLAlchemyUserStore(SessionLocal)
email_sender = EmailSender()
harbor = UserHarbor(
secret_key="your-secret-key",
store=store,
email_sender=email_sender,
)
harbor.register(
username="jane",
email="jane@example.com",
password="StrongPassword123!",
)
harbor.verify_email("verification-token-from-email")
session_token = harbor.login(
username="jane",
password="StrongPassword123!",
)
current_user = harbor.get_current_user(session_token)
print(current_user.username)
harbor.logout(session_token)
For real applications, replace EmailSender with an implementation that sends
verification and password reset messages through your email provider.
Transactions
SQLAlchemyUserStore.transaction() provides a transaction context used by
UserHarbor for multi-step operations such as email verification, password reset,
password change, and account deletion. Successful blocks are committed; exceptions
roll back all changes from the block.
License
UserHarbor SQLAlchemy is released under the MIT License.
Project details
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 userharbor_sqlalchemy-0.2.0.tar.gz.
File metadata
- Download URL: userharbor_sqlalchemy-0.2.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7f596efb1b9188cec16147111bd9f59810cf0c0906988c7b554de14f080e185
|
|
| MD5 |
f7e9660dbcf5b4e36490e2f35c34908e
|
|
| BLAKE2b-256 |
b9749b6bc2e730ecbe2b7aa45852fccf5f3ca11653469f40802ae6dc54ae1a9d
|
File details
Details for the file userharbor_sqlalchemy-0.2.0-py3-none-any.whl.
File metadata
- Download URL: userharbor_sqlalchemy-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
479c1bab969c5c40e2a5d8c8b63f4424bae8b7b0da5f8eaccbdb861d24ef0a56
|
|
| MD5 |
1118bb1208353e5d83a7b48e662754b5
|
|
| BLAKE2b-256 |
cb841352f3dad943125655f44a334038ad02df1d45996e46d1ffe01675ee8759
|