Skip to main content

FastAPI Admin

Project description

fp-admin

Python 3.12+ License: MIT Development Status

โš ๏ธ Beta Version: This project is currently under active development and is in beta. APIs may change between versions. We recommend testing thoroughly in development environments before using in production.

A modern, FastAPI-based admin framework that provides automatic CRUD interfaces and admin panels for SQLModel-based applications.

๐ŸŽจ UI Framework

The admin interface is powered by a separate React-based UI project:

  • UI Repository: fp-admin-ui
  • Features: Modern React interface with TypeScript, responsive design, and rich components
  • Integration: Seamlessly integrates with the fp-admin backend API

๐Ÿš€ Features

  • ๐Ÿ”ง Automatic Admin Interface: Generate beautiful admin panels from SQLModel models
  • ๐Ÿ“Š Rich Field Types: Support for text, email, password, number, date, checkbox, textarea, file uploads, and more
  • ๐ŸŽจ Advanced Widgets: Select dropdowns, radio buttons, checkbox groups, autocomplete, toggles, sliders, rich text editors
  • ๐Ÿ”— Relationship Support: Handle foreign keys and many-to-many relationships
  • โœ… Validation: Built-in field validation with custom error messages
  • ๐ŸŽฏ Multi-Choice Fields: Tags, chips, multi-select dropdowns with constraints
  • ๐Ÿ“ File Uploads: Secure file upload handling with validation and thumbnails
  • ๐Ÿ” Authentication: Built-in user management and authentication system
  • ๐Ÿ“ฑ CLI Tools: Command-line interface for project management and database operations
  • โšก FastAPI Integration: Seamless integration with FastAPI applications
  • ๐Ÿงช Comprehensive Testing: Full test suite with unit, integration, and e2e tests
  • ๐ŸŽจ Modern UI: React-based frontend with TypeScript and responsive design

๐Ÿ“ฆ Installation

Using pip

pip install fp-admin

๐Ÿ”ง Dev Installation

Using uv (Recommended)

# Install with all dependencies
uv sync --all-extras --dev

# Install git hooks
uv run pre-commit install

Using pip

pip install fp-admin[dev]

๐Ÿ› ๏ธ Quick Start

1. Create a New Project

# Create a new fp-admin project
fp-admin startproject myapp
cd myapp

2. Create an App

# Create a new app (e.g., blog)
fp-admin startapp blog

3. Set Up Database

# Create initial migration
fp-admin make-migrations initial

# Apply migrations
fp-admin migrate

4. Create Admin User

# Create a superuser account
fp-admin createsuperuser

5. Run the Application

# Start the development server
fp-admin run

Visit http://localhost:8000/admin to access your admin interface!

๐Ÿ“š Core Concepts

FieldView System

The core of fp-admin is the FieldView system, which provides a flexible way to define form fields:

from fp_admin.admin.fields import FieldView

# Basic text field
name_field = FieldView.text_field("name", "Full Name", required=True)

# Email field with validation
email_field = FieldView.email_field("email", "Email Address")

# Multi-choice field
tags_field = MultiChoicesField.multi_choice_tags_field(
    "tags", "Tags", choices=choices, max_selections=5
)

Admin Model Configuration

Define admin interfaces for your SQLModel models:

from fp_admin.admin.models import AdminModel
from fp_admin.admin.fields import FieldView

class PostAdmin(AdminModel):
    model = Post
    label = "Blog Posts"

    # Define list view fields
    list_fields = ["title", "author", "status", "created_at"]
    search_fields = ["title", "content"]

    # Custom field configurations
    field_configs = {
        "content": FieldView.richtext_field("content", "Content"),
        "tags": MultiChoicesField.multi_choice_tags_field(
            "tags", "Tags", choices=tag_choices
        ),
        "featured_image": FieldView.file_field("featured_image", "Featured Image")
    }

Field Types and Widgets

fp-admin supports a wide variety of field types and widgets:

Basic Field Types

  • text - Regular text input
  • email - Email input with validation
  • password - Password input
  • number - Numeric input
  • date - Date picker
  • checkbox - Boolean checkbox
  • textarea - Multi-line text area
  • file - File upload

Advanced Widgets

  • select - Dropdown selection
  • radio - Radio button group
  • checkbox-group - Multiple checkbox selection
  • autocomplete - Autocomplete input
  • toggle - Toggle switch
  • switch - Switch component
  • range - Range slider
  • slider - Slider input
  • richtext - Rich text editor
  • markdown - Markdown editor

Multi-Choice Widgets

  • multi-select - Multi-select dropdown
  • tags - Tag input with chips
  • chips - Chip selection
  • checkbox-group - Checkbox group for multiple selection

๐Ÿ—๏ธ Project Structure

fp-admin/
โ”œโ”€โ”€ fp_admin/                    # Main package
โ”‚   โ”œโ”€โ”€ admin/                   # Admin interface
โ”‚   โ”‚   โ”œโ”€โ”€ fields/             # Field definitions and widgets
โ”‚   โ”‚   โ”œโ”€โ”€ views/              # View configurations
โ”‚   โ”‚   โ”œโ”€โ”€ models/             # Admin model definitions
โ”‚   โ”‚   โ””โ”€โ”€ apps/               # App configurations
โ”‚   โ”œโ”€โ”€ api/                    # REST API endpoints
โ”‚   โ”œโ”€โ”€ cli/                    # Command-line interface
โ”‚   โ”œโ”€โ”€ core/                   # Core functionality
โ”‚   โ”œโ”€โ”€ apps/                   # Built-in apps (auth, etc.)
โ”‚   โ””โ”€โ”€ services/               # Business logic services
โ”œโ”€โ”€ examples/                    # Example applications
โ”‚   โ””โ”€โ”€ blog_app/              # Complete blog example
โ”œโ”€โ”€ tests/                      # Test suite
โ”œโ”€โ”€ docs/                       # Documentation
โ””โ”€โ”€ migrations/                 # Database migrations

๐Ÿ“– Examples

Blog Application

A complete blog application demonstrating fp-admin's capabilities:

# Navigate to the blog example
cd examples/blog_app

# Install dependencies
pip install fp-admin sqlmodel fastapi uvicorn

# Set up the database
fp-admin make-migrations initial
fp-admin migrate

# Create sample data
python scripts/sample_data.py

# Run the application
python app.py

Features demonstrated:

  • User management with authentication
  • Blog post creation with rich text editor
  • Category and tag management
  • Comment system with moderation
  • File uploads for featured images
  • Admin interface customization

Custom Field Configuration

from fp_admin.admin.fields import FieldView, MultiChoicesField, FieldChoices

# Define choices for a select field
status_choices = [
    FieldChoices(title="Draft", value="draft"),
    FieldChoices(title="Published", value="published"),
    FieldChoices(title="Archived", value="archived")
]

# Configure admin model with custom fields
class PostAdmin(AdminModel):
    model = Post
    label = "Posts"

    field_configs = {
        "title": FieldView.text_field("title", "Title", required=True),
        "content": FieldView.richtext_field("content", "Content"),
        "status": FieldView.select_field("status", "Status", options=status_choices),
        "tags": MultiChoicesField.multi_choice_tags_field(
            "tags", "Tags", choices=tag_choices, max_selections=5
        ),
        "featured_image": FieldView.file_field("featured_image", "Featured Image"),
        "published_at": FieldView.date_field("published_at", "Published Date")
    }

๐Ÿ› ๏ธ CLI Commands

Project Management

# Create new project
fp-admin startproject myproject

# Create new app
fp-admin startapp blog

# Show project info
fp-admin info

Running the Application

# Run the development server
fp-admin run

# Run with custom host and port
fp-admin run --host 0.0.0.0 --port 8080

# Run without auto-reload
fp-admin run --no-reload

# Run with different log level
fp-admin run --log-level info

# Run with custom app module
fp-admin run --app main:app

Database Operations

# Create migration
fp-admin make-migrations create_tables

# Apply migrations
fp-admin migrate

# Show migration status
fp-admin database status

User Management

# Create superuser
fp-admin createsuperuser

# Create regular user
fp-admin user create

System Commands

# Show version
fp-admin version

# Check system status
fp-admin system status

๐Ÿงช Testing

Run the comprehensive test suite:

# Run all tests
pytest

# Run specific test categories
pytest -m unit
pytest -m integration
pytest -m e2e

# Run with coverage
pytest --cov=fp_admin

๐Ÿ”ง Development

Setup Development Environment

# Install development dependencies
uv sync --all-extras --dev

# Install pre-commit hooks
uv run pre-commit install

# Run pre-commit on all files
uv run pre-commit run --all-files

Code Quality

The project uses several tools for code quality:

  • Black: Code formatting
  • isort: Import sorting
  • flake8: Linting
  • mypy: Type checking
  • pre-commit: Git hooks

Running Tests

# Run all tests
pytest

# Run specific test file
pytest tests/unit/admin/fields/test_base.py

# Run with verbose output
pytest -v

# Run with coverage
pytest --cov=fp_admin --cov-report=html

๐Ÿ“„ API Reference

FieldView Factory Methods

# Basic fields
FieldView.text_field(name, title, **kwargs)
FieldView.email_field(name, title, **kwargs)
FieldView.password_field(name, title, **kwargs)
FieldView.number_field(name, title, **kwargs)
FieldView.date_field(name, title, **kwargs)
FieldView.checkbox_field(name, title, **kwargs)
FieldView.textarea_field(name, title, **kwargs)
FieldView.file_field(name, title, **kwargs)

# Widget-specific fields
FieldView.select_field(name, title, **kwargs)
FieldView.radio_field(name, title, **kwargs)
FieldView.checkbox_group_field(name, title, **kwargs)
FieldView.autocomplete_field(name, title, **kwargs)
FieldView.toggle_field(name, title, **kwargs)
FieldView.switch_field(name, title, **kwargs)
FieldView.range_field(name, title, **kwargs)
FieldView.slider_field(name, title, **kwargs)
FieldView.richtext_field(name, title, **kwargs)
FieldView.markdown_field(name, title, **kwargs)

MultiChoicesField Factory Methods

# Multi-choice fields
MultiChoicesField.multi_choice_select_field(name, title, choices, **kwargs)
MultiChoicesField.multi_choice_tags_field(name, title, choices, **kwargs)
MultiChoicesField.multi_choice_chips_field(name, title, choices, **kwargs)
MultiChoicesField.multi_choice_checkbox_group_field(name, title, choices, **kwargs)

AdminModel Configuration

class MyAdmin(AdminModel):
    model = MyModel
    label = "My Models"

    # List view configuration
    list_fields = ["field1", "field2", "field3"]
    search_fields = ["field1", "field2"]
    list_per_page = 20

    # Field configurations
    field_configs = {
        "field1": FieldView.text_field("field1", "Field 1"),
        "field2": FieldView.email_field("field2", "Field 2")
    }

    # Custom actions
    actions = ["publish", "archive"]

๐Ÿค Contributing

We welcome contributions from the community! This project is in active development and your help is greatly appreciated.

๐Ÿšง Development Status

  • Current Version: Beta (0.0.3beta)
  • Development Phase: Active development
  • API Stability: May change between versions
  • Production Ready: Not yet recommended for production use

๐Ÿ“‹ How to Contribute

1. Setup Development Environment

# Fork and clone the repository
git clone https://github.com/your-username/fp-admin.git
cd fp-admin

# Install dependencies
uv sync --all-extras --dev

# Install pre-commit hooks
uv run pre-commit install

# Set up the database
fp-admin make-migrations initial
fp-admin migrate

2. Choose an Area to Contribute

  • Backend Development: Core framework, field types, validation, API endpoints
  • Frontend Development: React UI components, TypeScript interfaces
  • Documentation: Code docs, tutorials, examples
  • Testing: Unit tests, integration tests, e2e tests
  • Bug Fixes: Issue triage and resolution
  • Feature Requests: New field types, widgets, or functionality

3. Development Workflow

# Create a feature branch
git checkout -b feature/your-feature-name

# Make your changes
# ... edit files ...

# Run tests
pytest

# Run linting and formatting
uv run pre-commit run --all-files

# Commit your changes
git add .
git commit -m "feat: add your feature description"

# Push to your fork
git push origin feature/your-feature-name

4. Code Quality Standards

  • Python: Follow PEP 8, use type hints, write docstrings
  • JavaScript/TypeScript: Follow ESLint rules, use TypeScript
  • Tests: Maintain >90% code coverage
  • Documentation: Update docs for new features
  • Commits: Use conventional commit messages

5. Testing Guidelines

# Run all tests
pytest

# Run specific test categories
pytest -m unit
pytest -m integration
pytest -m e2e

# Run with coverage
pytest --cov=fp_admin --cov-report=html

# Run linting
uv run pre-commit run --all-files

6. Submitting Changes

  1. Create a Pull Request from your feature branch
  2. Add a description of your changes
  3. Link any related issues using keywords (fixes #123, closes #456)
  4. Wait for review from maintainers
  5. Address feedback if requested
  6. Merge once approved

๐Ÿ› Reporting Issues

When reporting issues, please include:

  • Environment: Python version, OS, dependencies
  • Steps to reproduce: Clear, step-by-step instructions
  • Expected behavior: What should happen
  • Actual behavior: What actually happens
  • Error messages: Full error traces
  • Code examples: Minimal code to reproduce the issue

๐Ÿ’ก Feature Requests

For feature requests:

  • Describe the feature clearly and concisely
  • Explain the use case and why it's needed
  • Provide examples of how it would be used
  • Consider alternatives and discuss trade-offs

๐Ÿ“š Documentation Contributions

We welcome documentation improvements:

  • Code examples: Clear, working examples
  • Tutorials: Step-by-step guides
  • API documentation: Comprehensive API reference
  • Best practices: Development guidelines

๐Ÿท๏ธ Issue Labels

  • bug: Something isn't working
  • enhancement: New feature or request
  • documentation: Improvements or additions to documentation
  • good first issue: Good for newcomers
  • help wanted: Extra attention is needed
  • question: Further information is requested

๐ŸŽฏ Development Priorities

Current development priorities:

  1. API Stability: Stabilizing the core API
  2. Field Types: Expanding field type support
  3. UI Components: Enhancing React components
  4. Documentation: Comprehensive guides and examples
  5. Testing: Improving test coverage
  6. Performance: Optimizing for large datasets

๐Ÿ“ž Getting Help

๐Ÿ™ Acknowledgments

Thanks to all contributors who have helped shape fp-admin:

  • Core Contributors: [List of major contributors]
  • Community Members: Everyone who reports issues and suggests improvements
  • Open Source Projects: FastAPI, SQLModel, Pydantic, and other dependencies

Made with โค๏ธ by the fp-admin team

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

fp_admin-0.0.6b0.tar.gz (48.6 kB view details)

Uploaded Source

Built Distribution

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

fp_admin-0.0.6b0-py3-none-any.whl (53.5 kB view details)

Uploaded Python 3

File details

Details for the file fp_admin-0.0.6b0.tar.gz.

File metadata

  • Download URL: fp_admin-0.0.6b0.tar.gz
  • Upload date:
  • Size: 48.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for fp_admin-0.0.6b0.tar.gz
Algorithm Hash digest
SHA256 4011f3482ffe589e9a180a8f1ea48ff3928936616b0de8a54fbb063ea1d640ea
MD5 3c35506de518d6222f18e159b3ca9f24
BLAKE2b-256 a7d3f1619eec6095bbe764f47c794e67705660c18ce0ec3d0585c18ed3ede014

See more details on using hashes here.

File details

Details for the file fp_admin-0.0.6b0-py3-none-any.whl.

File metadata

  • Download URL: fp_admin-0.0.6b0-py3-none-any.whl
  • Upload date:
  • Size: 53.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for fp_admin-0.0.6b0-py3-none-any.whl
Algorithm Hash digest
SHA256 da0f8076edf2495977b9f053f9e7386d42d5b27276f15a7c064dba18bed14ca3
MD5 9fc7d51a9c2d0af08bc511acfb492e60
BLAKE2b-256 fbe74fe7229a0600cd8fb46aad23e85425e46a94cb6ec524f09deeba11b25e75

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