Django-inspired CLI tool for managing FastAPI applications
Project description
FastAPI Admin CLI
A Django-inspired CLI tool for managing FastAPI applications with a modular structure. This tool helps developers quickly scaffold and manage FastAPI projects with a clean, organized architecture.
📚 Documentation: https://amal-babu-git.github.io/fastapi-admin-cli-docs/
Available Commands
| Command | Description |
|---|---|
fastapi-admin startproject |
Create a new FastAPI project |
fastapi-admin startapp |
Create a new app within a FastAPI project |
fastapi-admin docker build |
Build Docker containers |
fastapi-admin docker run |
Run Docker containers |
fastapi-admin docker down |
Stop and remove Docker containers |
fastapi-admin docker cmd |
Run custom Docker commands |
fastapi-admin db makemigrations |
Create new database migrations |
fastapi-admin db migrate |
Apply database migrations |
fastapi-admin db shell |
Open a shell in the API container |
fastapi-admin createsuperuser |
Create a superuser for the admin panel |
fastapi-admin shell |
Launch a shell inside a Docker container |
Features
- 🚀 Project Scaffolding: Create well-structured FastAPI projects with a single command
- 📦 App Management: Generate modular apps within your project
- 🐳 Docker Integration: Built-in Docker support with commands for building and running containers
- 🔄 Database Migrations: Easy database migration commands using Alembic
- 🛠️ Developer Tools: Shell access to Docker containers and more
Installation
Install the package from PyPI:
pip install fastapi-admin-cli
Usage
Create a New Project
fastapi-admin startproject myproject
cd myproject
This creates a new FastAPI project with the following structure:
- Docker configuration
- Database migration setup with Alembic
- Environment variable management
- Modular app structure
Create a New App
# Make sure you're in the project directory
fastapi-admin startapp blog
This creates a new app with the following files:
models.py: SQLAlchemy modelsschemas.py: Pydantic schemasroutes.py: FastAPI routesservices.py: Business logicadmin.py: Admin interface configuration
Docker Operations
Build, run, and manage your application using Docker:
# Build Docker containers
fastapi-admin docker build
# Run Docker containers
fastapi-admin docker run
# Stop and remove Docker containers
fastapi-admin docker down
# Run custom Docker commands
fastapi-admin docker cmd "logs"
Database Migrations
# Create new migrations
fastapi-admin db makemigrations -m "create users table"
# Apply migrations
fastapi-admin db migrate
For other migration and related commands, use Alembic inside the Docker shell:
fastapi-admin shell
alembic upgrade head
Create a Superuser
fastapi-admin createsuperuser admin@example.com password123 --first-name Admin --last-name User
This command creates a superuser for the admin panel. If the user already exists, it updates the user to superuser status.
Shell Access
# Open a shell in the API container
fastapi-admin db shell
# Launch a shell inside a Docker container
fastapi-admin shell --container-name fastapi-app
Tech Stack
The FastAPI Admin CLI leverages the following technologies:
- FastAPI: A modern, fast (high-performance) web framework for building APIs with Python.
- Modular Structure: Projects are organized into modular apps for better scalability and maintainability.
- PostgreSQL: Default database backend for robust and scalable data storage.
- SQLModel: Combines the best of SQLAlchemy and Pydantic for ORM operations and schema validation.
- Alembic: Database migration management tool for versioning and applying schema changes.
- FastAPI-Users: Provides authentication with email and password by default, including JWT-based access and refresh tokens.
- SQL Admin: Built-in admin panel for managing database models with admin authentication.
Authentication
The project includes a pre-configured authentication module implemented with the fastapi-users package:
- JWT authentication with access and refresh tokens
- User registration, email verification, and password reset
To use authentication in your routes:
from app.auth.dependencies import current_active_user
@router.get("/protected-route")
def protected_route(user = Depends(current_active_user)):
return {"message": f"Hello, {user.email}!"}
ORM Integration
The project uses SQLModel for ORM operations, which combines the best of SQLAlchemy and Pydantic:
- Type-safe models that work as both Pydantic models and SQLAlchemy models
- Simplified query syntax while maintaining full SQLAlchemy power
- Automatic schema validation
Example model:
from sqlmodel import Field, SQLModel
from typing import Optional
class User(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
email: str = Field(unique=True, index=True)
username: str = Field(unique=True, index=True)
hashed_password: str
Admin Panel
The project includes an SQLAlchemy admin panel for database management:
- Automatic CRUD interface for all your models
- Customizable admin views
To access the admin panel, navigate to /admin after starting your application.
Project Structure
The generated project follows a modular structure inspired by Django:
myproject/
├── main.py # Main application entry point
├── manage.py # CLI wrapper script
├── docker/ # Docker configuration
│ └── compose/ # Docker Compose files
├── migrations/ # Database migrations
├── auth/ # Example app
│ ├── __init__.py
│ ├── models.py # SQLAlchemy models
│ ├── schemas.py # Pydantic schemas
│ ├── routes.py # FastAPI routes
│ ├── auth.py # Business logic
│ └── admin.py # Admin interface configuration
└── ...
Environment Variables
The project template includes an env.txt file that should be copied to .env for local development. The CLI will attempt to do this automatically when running docker build.
Using the Manage.py Wrapper
Each generated project includes a manage.py wrapper that provides the same functionality as the fastapi-admin CLI:
python manage.py startapp new_app
python manage.py docker build
python manage.py docker run
python manage.py db migrate
python manage.py shell
Local Development
For local development without Docker:
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt # Or if you have uv installed uv sync
-
Copy environment variables:
cp env.txt .env
Troubleshooting
Docker Issues
If you encounter issues with Docker containers:
- Check if Docker is installed and running
- Verify the container name with
docker ps - Check Docker Compose configuration in
docker/compose/docker-compose.yml
Database Migration Issues
If you have problems with database migrations:
- Ensure the database container is running
- Check if Alembic is properly installed in the container
- Verify your database connection settings
- Try running migrations manually inside the container shell:
fastapi-admin db shell alembic upgrade head
- Check Alembic logs for detailed error messages
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 fastapi_admin_cli-0.1.13.tar.gz.
File metadata
- Download URL: fastapi_admin_cli-0.1.13.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0cc3431006325af847afcc5314b3e31966971c64ea52ad98ae9bd9e9a7e7040
|
|
| MD5 |
0ce0d71b46bc5d2e90d0f3d155d02dee
|
|
| BLAKE2b-256 |
4222b33b95c0c6f1d1c419e5c6d744245ef532332d3dffc7d4facdcc9b253b50
|
File details
Details for the file fastapi_admin_cli-0.1.13-py3-none-any.whl.
File metadata
- Download URL: fastapi_admin_cli-0.1.13-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10b2f15872ef83983df30a8bdf920f1fa06f7515c11cbdf4eeebd50293ba0bfa
|
|
| MD5 |
14f29f1d1885fec81edf0adabdb0e42a
|
|
| BLAKE2b-256 |
9aea5e94d0ba3d4b9eadef38309b236b1b34002f846d31f2e85c41d0ae5f5b4b
|