Skip to content

CLI & Helpers

The authfort command is available after installing the package.

Run bundled Alembic migrations to create or update AuthFort database tables.

Terminal window
authfort migrate --database-url "postgresql+asyncpg://user:pass@localhost/mydb"
FlagRequiredDescription
--database-urlYesAsync SQLAlchemy database URL

The command is idempotent — it only applies pending migrations. Run it once on initial setup and again after upgrading AuthFort.

Also works with uvx:

Terminal window
uvx authfort migrate --database-url "sqlite+aiosqlite:///auth.db"

Helpers for applications that share a database with AuthFort and use their own Alembic setup.

Register stub tables in your MetaData so your models can use ForeignKey("authfort_users.id").

from sqlalchemy.orm import DeclarativeBase
from authfort import register_foreign_tables
class Base(DeclarativeBase):
pass
register_foreign_tables(Base.metadata)

Call this before defining models that FK to AuthFort tables. Registers authfort_users and authfort_user_roles stubs (minimal — just the primary key column).

Idempotent — safe to call multiple times.

Returns a dict with include_name and include_object filter functions that skip all AuthFort-managed tables.

from authfort import alembic_filters
context.configure(
connection=connection,
target_metadata=target_metadata,
**alembic_filters(),
)

Returns: {"include_name": Callable, "include_object": Callable}

Filtered tables: authfort_users, authfort_accounts, authfort_refresh_tokens, authfort_user_roles, authfort_signing_keys, authfort_verification_tokens, authfort_alembic_version.