Skip to main content

Core authentication logic for Belgie

Project description

Belgie Core: Authentication Primitives for Belgie Apps

[!WARNING] Belgie is currently in beta. The core API may change before v1.0 as the broader package set stabilizes.

Belgie Core is the orchestration layer behind Belgie's authentication flow. It wires settings, sessions, request-scoped clients, and FastAPI integration around the shared protocol interfaces in belgie-proto.

Use it when you want the core auth primitives without the higher-level package extras. If you only need the shared interfaces, see belgie-proto.

Installation

uv add belgie-core

[!NOTE] belgie-core depends on belgie-proto, and in this monorepo both packages are resolved from the workspace.

What It Includes

  • Belgie for wiring settings, adapters, sessions, and FastAPI routes.
  • BelgieClient for request-scoped auth operations against an injected database session.
  • BelgieSettings, SessionSettings, CookieSettings, and URLSettings.
  • SessionManager for session lifecycle handling.
  • Session and state token helpers, plus scope validation utilities.
  • Belgie-specific exception types for auth and configuration failures.

Quick Start

Here is the smallest useful setup for embedding Belgie Core in a FastAPI app:

Project Structure:

my-app/
├── server.py
└── models.py

server.py:

from collections.abc import AsyncGenerator

from fastapi import Depends, FastAPI, Request
from fastapi.security import SecurityScopes

from belgie_core import Belgie, BelgieClient, BelgieSettings
from belgie_proto.core.connection import DBConnection

from models import adapter, session_maker

settings = BelgieSettings(
    secret="your-secret-key",
    base_url="http://localhost:8000",
)


async def get_db() -> AsyncGenerator[DBConnection, None]:
    async with session_maker() as session:
        yield session


belgie = Belgie(settings=settings, adapter=adapter, database=get_db)
app = FastAPI()
app.include_router(belgie.router)


@app.get("/me")
async def me(
    request: Request,
    client: BelgieClient = Depends(belgie),
):
    individual = await client.get_individual(SecurityScopes(), request)
    return {"email": individual.email}

Belgie Core also gives you Depends(belgie) for request-scoped client access and a router that mounts the auth endpoints for any plugins you register.

Configuration

  • BELGIE_SECRET and BELGIE_BASE_URL are required by BelgieSettings().
  • BELGIE_SESSION_*, BELGIE_COOKIE_*, and BELGIE_URLS_* control session lifetime, cookie behavior, and redirect URLs.
  • Session cookies default to secure, HTTP-only, and SameSite=Lax.
  • URL helpers default sign-in and sign-out redirects to /dashboard and /.

API Surface

  • Import from belgie_core for the main package entry point.
  • Import the shared connection protocol from belgie_proto.core.connection.
  • Use belgie.router to mount auth routes in FastAPI.
  • Use BelgieClient for authenticated request handlers and scope checks.

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

belgie_core-0.14.3.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

belgie_core-0.14.3-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file belgie_core-0.14.3.tar.gz.

File metadata

  • Download URL: belgie_core-0.14.3.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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

Hashes for belgie_core-0.14.3.tar.gz
Algorithm Hash digest
SHA256 6090840a73b9ee7a67496149f82183ebe7e4db552e9f2492a823cd187c13d7b4
MD5 7c0b75eb18fb4c798b8d681aecdc4069
BLAKE2b-256 f5b4bfc00f6e21fd923fa087f7078b1afe1d043ece11418c83d93a5a1f37376d

See more details on using hashes here.

File details

Details for the file belgie_core-0.14.3-py3-none-any.whl.

File metadata

  • Download URL: belgie_core-0.14.3-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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

Hashes for belgie_core-0.14.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9e46379c021e26a98bdf030e1f1e0660b13a3b87bd6d4817cce8e6777d5ed245
MD5 2b0a2e5fcb736c86dbf8d2733acf2c61
BLAKE2b-256 bdee98068852cb83a108f2c9435e05d82ba108783f325e700875eb7a976a8862

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page