FastAPI Admin
Project description
fp-admin
โ ๏ธ 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 inputemail- Email input with validationpassword- Password inputnumber- Numeric inputdate- Date pickercheckbox- Boolean checkboxtextarea- Multi-line text areafile- File upload
Advanced Widgets
select- Dropdown selectionradio- Radio button groupcheckbox-group- Multiple checkbox selectionautocomplete- Autocomplete inputtoggle- Toggle switchswitch- Switch componentrange- Range sliderslider- Slider inputrichtext- Rich text editormarkdown- Markdown editor
Multi-Choice Widgets
multi-select- Multi-select dropdowntags- Tag input with chipschips- Chip selectioncheckbox-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
- Create a Pull Request from your feature branch
- Add a description of your changes
- Link any related issues using keywords (fixes #123, closes #456)
- Wait for review from maintainers
- Address feedback if requested
- 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 workingenhancement: New feature or requestdocumentation: Improvements or additions to documentationgood first issue: Good for newcomershelp wanted: Extra attention is neededquestion: Further information is requested
๐ฏ Development Priorities
Current development priorities:
- API Stability: Stabilizing the core API
- Field Types: Expanding field type support
- UI Components: Enhancing React components
- Documentation: Comprehensive guides and examples
- Testing: Improving test coverage
- Performance: Optimizing for large datasets
๐ Getting Help
- GitHub Issues: Report bugs and request features
- GitHub Discussions: Ask questions and share ideas
- Code of Conduct: Community guidelines
๐ 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4011f3482ffe589e9a180a8f1ea48ff3928936616b0de8a54fbb063ea1d640ea
|
|
| MD5 |
3c35506de518d6222f18e159b3ca9f24
|
|
| BLAKE2b-256 |
a7d3f1619eec6095bbe764f47c794e67705660c18ce0ec3d0585c18ed3ede014
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da0f8076edf2495977b9f053f9e7386d42d5b27276f15a7c064dba18bed14ca3
|
|
| MD5 |
9fc7d51a9c2d0af08bc511acfb492e60
|
|
| BLAKE2b-256 |
fbe74fe7229a0600cd8fb46aad23e85425e46a94cb6ec524f09deeba11b25e75
|