SQLAlchemy building blocks for Belgie
Project description
Belgie Alchemy
[!WARNING] Belgie Alchemy is a low-level SQLAlchemy layer. You own the concrete models, migrations, and schema changes in your app. It provides mixins and adapters, not a database framework.
Belgie Alchemy is the SQLAlchemy package behind Belgie's auth, organization, and team features. It gives you explicit adapter wiring and small composable mixins so you can build app-owned models without giving up type safety or clear schema boundaries.
Installation
uv add belgie[alchemy]
uv add belgie[alchemy,organization,team]
[!NOTE] Application code should import from
belgie.alchemy. The implementation package isbelgie_alchemy, but the public re-exports live underbelgie.alchemy.
What It Provides
BelgieAdapterfor core auth records.OrganizationAdapterfor organization membership and invitations.TeamAdapterfor organization-scoped teams.AccountMixin,IndividualMixin,OAuthAccountMixin,SessionMixin, andOAuthStateMixinfor account/auth models.OrganizationMixin,OrganizationMemberMixin, andOrganizationInvitationMixinfor organization models.TeamMixinandTeamMemberMixinfor team models.
Quick Start
from brussels.base import DataclassBase
from brussels.mixins import PrimaryKeyMixin, TimestampMixin
from belgie.alchemy import AccountMixin, BelgieAdapter, OAuthAccountMixin, OAuthStateMixin, SessionMixin, IndividualMixin
class Individual(DataclassBase, PrimaryKeyMixin, TimestampMixin, IndividualMixin):
pass
class Account(DataclassBase, PrimaryKeyMixin, TimestampMixin, AccountMixin):
pass
class OAuthAccount(DataclassBase, PrimaryKeyMixin, TimestampMixin, OAuthAccountMixin):
pass
class Session(DataclassBase, PrimaryKeyMixin, TimestampMixin, SessionMixin):
pass
class OAuthState(DataclassBase, PrimaryKeyMixin, TimestampMixin, OAuthStateMixin):
pass
adapter = BelgieAdapter(
account=Account,
individual=Individual,
oauth_account=OAuthAccount,
session=Session,
oauth_state=OAuthState,
)
This keeps your schema in your application while Belgie handles the adapter contract. You can add custom columns and relationships on top of the mixins without changing how the adapter works.
Auth Models
The auth mixins map to the common Belgie records:
IndividualMixinadds email, profile, scopes, and related OAuth account/session/state relationships.AccountMixinstores the shared account hierarchy fields used by individuals, organizations, and teams.SessionMixinstores session expiry plus request metadata.OAuthStateMixinstores OAuth state, PKCE verifier, redirect URL, and optional user linkage.
The default PostgreSQL variants use CITEXT for case-insensitive email, provider, and provider_account_id
columns.
[!NOTE] If you use the default PostgreSQL column variants, make sure the
citextextension is installed in your database.
Organization And Team
Use the organization and team mixins when your app needs shared org membership plus team-scoped access:
[!NOTE] The snippet below assumes you have already defined
Account,Individual,OAuthAccount,Session,OAuthState,Organization,OrganizationMember,OrganizationInvitation,Team, andTeamMemberfrom the mixins above.
from belgie.alchemy import (
AccountMixin,
BelgieAdapter,
OAuthAccountMixin,
OAuthStateMixin,
OrganizationInvitationMixin,
OrganizationMemberMixin,
OrganizationMixin,
SessionMixin,
TeamMemberMixin,
TeamMixin,
IndividualMixin,
)
from belgie.alchemy.organization import OrganizationAdapter
from belgie.alchemy.team import TeamAdapter
core_adapter = BelgieAdapter(
account=Account,
individual=Individual,
oauth_account=OAuthAccount,
session=Session,
oauth_state=OAuthState,
)
# Organizations only (no team plugin)
organization_adapter = OrganizationAdapter(
organization=Organization,
member=OrganizationMember,
invitation=OrganizationInvitation,
)
# Organization + team plugins: one adapter for both plugins
team_adapter = TeamAdapter(
organization=Organization,
member=OrganizationMember,
invitation=OrganizationInvitation,
team=Team,
team_member=TeamMember,
)
When you enable both plugins, use the team-capable adapter for both. If you only need organizations, the organization adapter is sufficient.
The organization and team protocols match the SQLAlchemy row shape, so your app models can stay plain SQLAlchemy
classes without adding explicit protocol bases just to satisfy ty.
The default PostgreSQL variants also use CITEXT for organization slug values and pending invitation email
addresses. Pending invitations are unique per (organization_id, email) while their status is pending.
Examples
examples/alchemy/auth_models.pyfor a compact auth-model reference.examples/organization_teamfor a runnable organization + team app.
Project details
Release history Release notifications | RSS feed
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 belgie_alchemy-0.19.3.tar.gz.
File metadata
- Download URL: belgie_alchemy-0.19.3.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","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 |
3a8ff5c0f2d9562af978281cb390f8d315f91d53469cc2d782615b2a42c2823a
|
|
| MD5 |
aa04a884d94acb55ab87e939f238ec97
|
|
| BLAKE2b-256 |
77e660b0f7686a4bc8d424ba139e6bbc5064cfaddba87fbae4fbe15e55256ad9
|
File details
Details for the file belgie_alchemy-0.19.3-py3-none-any.whl.
File metadata
- Download URL: belgie_alchemy-0.19.3-py3-none-any.whl
- Upload date:
- Size: 26.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","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 |
186dcb28bdf40c30be8167d2685b3e441552f68b9edf5e62250634b9d401a28f
|
|
| MD5 |
f5ce26deb98228f83963b57efbe639f7
|
|
| BLAKE2b-256 |
0e8ea2dc02983ccf5c9eb691a6998515afbea95a3e7686684c9bbac0f6111e9f
|