fabian/dev/: users-admin-0.0.1 metadata and description

Simple index

A FastAPI library for user administration and management

author_email Fabian Aichele <aichele@zykl.io>
description_content_type text/markdown
dynamic
  • license-file
keywords fastapi, library, user-management, admin
license MIT License Copyright (c) 2025 Fabian Aichele Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
license_file
  • LICENSE
project_urls
  • Homepage, https://github.com/faichele/users_admin
  • Repository, https://github.com/faichele/users_admin.git
requires_dist
  • pydantic<3,>=2.7
  • fastapi>=0.100.0
  • sqlalchemy>=2.0
  • python-multipart>=0.0.5
  • jinja2>=3.1.0
  • bcrypt>=4.0.0
  • pytest; extra == "dev"
  • pytest-cov; extra == "dev"
  • mypy; extra == "dev"
  • ruff; extra == "dev"
  • build; extra == "dev"
  • twine; extra == "dev"
requires_python >=3.9

Because this project isn't in the mirror_whitelist, no releases from root/pypi are included.

File Tox results History
users_admin-0.0.1-py3-none-any.whl
Size
6 KB
Type
Python Wheel
Python
3
  • Replaced 2 time(s)
  • Uploaded to fabian/dev by fabian 2026-01-09 20:58:03
users_admin-0.0.1.tar.gz
Size
6 KB
Type
Source
  • Replaced 2 time(s)
  • Uploaded to fabian/dev by fabian 2026-01-09 20:58:04

Users Admin Module

Ein wiederverwendbares Python-Modul für Benutzerverwaltung in FastAPI-Anwendungen.

Überblick

Das users_admin Modul bietet eine vollständige, produktionsreife Lösung für:

Architektur

Das Modul folgt einer sauberen, schichtweisen Architektur mit abstrakten Basisklassen:

users_admin/
├── models/              # Pydantic-Modelle
│   └── admin_models.py  # Admin-Datenmodelle
├── services/            # Business Logic Layer
│   ├── base_user_admin_service.py    # Abstrakte Basis-Klasse
│   ├── user_admin_service.py         # SQLAlchemy-Implementierung
│   └── user_crud_service.py          # CRUD-Hilfsfunktionen
├── utils/               # Utility-Funktionen
│   ├── security_utils.py  # Passwort-Hashing
│   └── email_utils.py     # E-Mail-Versand
├── dependencies/        # FastAPI Dependencies
│   └── admin_deps.py    # Auth-Dependencies für Admin
├── routers/             # FastAPI Router
│   └── user_admin_router.py  # Admin-Endpunkte
├── templates/           # HTML-Templates
│   └── admin_users.html # Admin-Interface
├── config/              # Konfiguration
│   └── admin_config.py  # Modul-Konfiguration
└── examples/            # Integrations-Beispiele

Features

Flexible Service-Architektur

Das Modul verwendet abstrakte Basisklassen (BaseUserAdminService), die es ermöglichen, verschiedene Backend-Implementierungen zu nutzen:

Benutzermodell

Admin-Interface

API-Endpunkte

Admin-Interface

Benutzerverwaltung (/api/users)

Installation & Integration

1. Installation

cd backend/users_admin
pip install -e .

2. Einfache Integration

from fastapi import FastAPI
from sqlalchemy.orm import Session

# Import des users_admin Moduls
from users_admin import UserAdminRouter
from users_admin.config import AdminConfig
from users_admin.utils import SecurityUtils

# Ihre existierenden Imports
from backend.database.base import get_db
from backend.database.models import User
from backend.api.deps import (
    get_current_user,
    get_current_active_superuser
)
from backend.utils.auth import superuser_or_redirect

app = FastAPI()

# Konfiguration erstellen
config = AdminConfig(
    templates_dir="backend/users_admin/templates",
    api_prefix="/api",
    router_tags=["users", "admin"],
    emails_enabled=False,
    enable_logging=True,
    log_file="logs/users_admin.log"
)

# Security Utils initialisieren
security_utils = SecurityUtils()

# Router erstellen
admin_router = UserAdminRouter(
    database_session=get_db,
    config=config,
    user_model=User,
    security_utils=security_utils,
    get_current_user=get_current_user,
    get_current_superuser=get_current_active_superuser,
    superuser_or_redirect=superuser_or_redirect
)

# Router in die App einbinden
app.include_router(admin_router.router)

3. Eigene Service-Implementierung

Sie können eigene Service-Implementierungen erstellen, z.B. für LDAP:

from users_admin.services import BaseUserAdminService

class LDAPUserAdminService(BaseUserAdminService):
    """LDAP-basierte Benutzerverwaltung."""
    
    def __init__(self, ldap_connection):
        self.ldap = ldap_connection
    
    def get_user_by_email(self, email: str):
        # LDAP-Implementierung
        return self.ldap.search(f"mail={email}")
    
    def create_user(self, user_data):
        # LDAP-Implementierung
        return self.ldap.add_user(user_data)
    
    # ... weitere Methoden

4. Multi-Provider-Setup mit Fallback

Sie können mehrere Service-Provider kombinieren:

from users_admin.examples.multi_provider_example import MultiProviderUserAdminService

# Services erstellen
ldap_service = LDAPUserAdminService(ldap_connection)
db_service = UserAdminService(db_session, User, SecurityUtils())

# Multi-Provider-Service mit Fallback
multi_service = MultiProviderUserAdminService(
    primary_service=ldap_service,    # Primär: LDAP
    fallback_service=db_service      # Fallback: lokale DB
)

Konfiguration

AdminConfig

from users_admin.config import AdminConfig

config = AdminConfig(
    # Template-Verzeichnis
    templates_dir="backend/users_admin/templates",
    
    # API-Präfix
    api_prefix="/api",
    
    # Router-Tags
    router_tags=["users", "admin"],
    
    # E-Mail-Einstellungen
    emails_enabled=True,
    smtp_host="smtp.example.com",
    smtp_port=587,
    smtp_user="user@example.com",
    smtp_password="password",
    emails_from_email="noreply@example.com",
    emails_from_name="My App",
    
    # Passwort-Reset-Token Gültigkeit
    password_reset_token_expire_minutes=60,
    
    # Logging
    enable_logging=True,
    log_file="logs/users_admin.log"
)

Anpassung

Eigene Templates

Sie können die HTML-Templates anpassen, indem Sie das Template-Verzeichnis in der Konfiguration angeben:

config = AdminConfig(
    templates_dir="my_custom_templates"
)

Eigene Dependencies

Sie können eigene Dependencies für Authentifizierung und Autorisierung bereitstellen:

from fastapi import Depends, HTTPException

def my_custom_auth(token: str = Depends(oauth2_scheme)):
    # Ihre eigene Auth-Logik
    return verify_token(token)

admin_router = UserAdminRouter(
    database_session=get_db,
    config=config,
    get_current_user=my_custom_auth,
    # ...
)

Testen

Unit-Tests ausführen

cd backend/users_admin
python test_module.py

Demo-Anwendung starten

cd backend/users_admin/examples
python complete_integration.py

Die Demo-Anwendung läuft auf http://localhost:8000:

Standard-Admin-Zugangsdaten:

Sicherheit

Abhängigkeiten

Beispiele

Einfache Integration

Siehe examples/integration_example.py

Multi-Provider mit Fallback

Siehe examples/multi_provider_example.py

Vollständige Demo-Anwendung

Siehe examples/complete_integration.py

Lizenz

MIT License - siehe LICENSE Datei

Autor

Fabian Aichele aichele@zykl.io

Changelog

Version 1.0.0 (2025-10-10)

Support

Bei Fragen oder Problemen: