gemini-2.5-pro| input-price: 1.25 output-price: 10 max-context-length: 200_000 (cost: $0.06) Β· Anfrage: 2025-10-05T11:09:51.553300
Generated by rs-summarizer Version unbekannt
Abstract:
This document provides the source code and documentation for fasthtml-admin, a Python library designed to add comprehensive user authentication, administration, and database management to FastHTML web applications. The library offers a modular toolkit for common backend functionalities, including user registration with email confirmation, secure login, and admin user creation. It features robust tools for administrators, such as SQLite database backup, restore, and upload capabilities, alongside a persistent maintenance mode to restrict site access. Key features include an extensible validation system with built-in rules for passwords and emails, seamless HTMX integration for real-time form validation, and OAuth support for third-party authentication with providers like GitHub. The library follows FastHTML best practices, utilizing Beforeware for centralized route protection and session management.
fasthtml-admin: A Guide to Features and Implementation
README.md Core Functionality: The library provides a complete solution for user management (registration, authentication, confirmation), admin management (user creation, database operations), and extensible validation. It is designed for seamless integration into new or existing FastHTML projects.auth.py User and Authentication Management:
UserManager class is the central component for handling user operations like create_user, authenticate_user, and confirm_user. It can work with a FastHTML database or a simple dictionary store.auth_before function, which integrates with FastHTML's Beforeware system to secure endpoints and define public paths that do not require login.get_current_user, is provided to easily retrieve the currently authenticated user's data from the session within any route handler.example.py Extensible User Class: The default UserCredential class can be easily extended to include custom profile fields (e.g., first_name, bio, profile_image). This custom class is then passed to the UserManager to automatically handle the additional data fields in the database.admin.py Admin and Database Tools:
AdminManager class provides high-level administrative functions. It can ensure an admin user exists (ensure_admin) and manage site-wide settings.validation.py Built-in and Custom Validation:
ValidationManager with pre-built validators for common tasks like checking password strength, validating email formats, and confirming that two password fields match.example.py Real-time Validation with HTMX: The validation endpoints are designed to integrate directly with HTMX. This allows for creating responsive user interfaces that provide real-time feedback on form fields as the user types, improving user experience and reducing submission errors.oauth.py OAuth Integration:
OAuthManager class simplifies the integration of third-party login providers (e.g., GitHub, Google).example.py, example_oauth.py Complete Examples: The repository includes two fully functional example applications. example.py demonstrates the standard email/password registration and login flow, while example_oauth.py shows how to implement "Login with GitHub" using the OAuthManager.