Creating Projects
A detailed guide on how to create various types of FastAPI projects with FastAPI-fastkit.
Basic Project Creation
1. Interactive Mode Project Creation
The most basic way to create a project interactively:
$ fastkit init
Enter the project name: my-awesome-api
Enter the author name: John Doe
Enter the author email: john@example.com
Enter the project description: Awesome FastAPI project
Project Information
┌──────────────┬─────────────────────────┐
│ Project Name │ my-awesome-api │
│ Author │ John Doe │
│ Author Email │ john@example.com │
│ Description │ Awesome FastAPI project │
└──────────────┴─────────────────────────┘
2. Stack Selection
Choose the dependency stack to include in your project:
MINIMAL Stack (Default)
The most basic FastAPI project:
fastapi- FastAPI frameworkuvicorn- ASGI serverpydantic- Data validationpydantic-settings- Settings management
Best for:
- Learning FastAPI
- Simple APIs
- Prototypes
- Microservices
STANDARD Stack
Includes database support and testing:
- All MINIMAL dependencies
sqlalchemy- ORM for database operationsalembic- Database migrationspytest- Testing framework
Best for:
- Most web applications
- APIs with database storage
- Production-ready applications
- Team projects
FULL Stack
Complete development environment:
- All STANDARD dependencies
redis- Caching and session storagecelery- Background task processing
Best for:
- Large applications
- High-performance requirements
- Complex business logic
- Enterprise applications
Advanced Project Options
Custom Project Configuration
You can customize your project during creation:
$ fastkit init
Enter the project name: advanced-api
Enter the author name: Development Team
Enter the author email: dev@company.com
Enter the project description: Advanced FastAPI application with custom features
# Choose STANDARD stack for database support
Select stack (minimal, standard, full): standard
Do you want to proceed with project creation? [y/N]: y
Project Structure Explanation
When you create a project, FastAPI-fastkit generates this structure:
my-awesome-api/
├── .venv/ # Virtual environment
├── src/ # Source code
│ ├── __init__.py
│ ├── main.py # Application entry point
│ ├── core/ # Core configuration
│ │ ├── __init__.py
│ │ └── config.py # Settings and configuration
│ ├── api/ # API layer
│ │ ├── __init__.py
│ │ ├── api.py # Main API router
│ │ └── routes/ # Individual route modules
│ │ ├── __init__.py
│ │ └── items.py # Example items endpoints
│ ├── crud/ # Database operations
│ │ ├── __init__.py
│ │ └── items.py # CRUD operations for items
│ ├── schemas/ # Pydantic models
│ │ ├── __init__.py
│ │ └── items.py # Data validation schemas
│ └── mocks/ # Test data
│ ├── __init__.py
│ └── mock_items.json # Sample data for development
├── tests/ # Test suite
│ ├── __init__.py
│ ├── conftest.py # Test configuration
│ └── test_items.py # Example tests
├── scripts/ # Utility scripts
│ ├── test.sh # Run tests
│ ├── coverage.sh # Test coverage
│ └── lint.sh # Code linting
├── requirements.txt # Python dependencies
├── setup.py # Package configuration
└── README.md # Project documentation
3. Package Manager Selection
FastAPI-fastkit supports multiple Python package managers. Choose the one that best fits your development workflow:
Available Package Managers
Available Package Managers:
Package Managers
┌────────┬────────────────────────────────────────────┐
│ PIP │ Standard Python package manager │
│ UV │ Fast Python package manager │
│ PDM │ Modern Python dependency management │
│ POETRY │ Python dependency management and packaging │
└────────┴────────────────────────────────────────────┘
Select package manager (pip, uv, pdm, poetry) [uv]: uv
Each package manager has its advantages:
UV (Default - Recommended)
Fast Rust-based package manager
- ⚡ Ultra-fast: 10-100x faster than pip
- 🔧 Drop-in replacement: Compatible with pip workflows
- 📦 Modern: Full PEP 621 support
- 🛠️ Reliable: Deterministic resolution
Generated files:
pyproject.toml(PEP 621 format)uv.lock(lockfile)
Usage after creation:
cd my-project
uv sync # Install dependencies
uv add requests # Add new dependency
uv run pytest # Run tests
PDM
Modern Python dependency management
- 🚀 Modern: PEP 582 and PEP 621 support
- 🧠 Smart: Advanced dependency resolution
- 💼 Professional: Workspace and multi-project support
- 📊 Analytics: Dependency analysis tools
Generated files:
pyproject.toml(PEP 621 format)pdm.lock(lockfile)
Usage after creation:
cd my-project
pdm install # Install dependencies
pdm add requests # Add new dependency
pdm run pytest # Run tests
Poetry
Mature dependency management and packaging
- ✅ Established: Mature and widely adopted
- 📦 Integrated: Build and publish support
- 🔒 Reproducible: poetry.lock for exact versions
- 🏗️ Complete: Full project lifecycle management
Generated files:
pyproject.toml(Poetry format)poetry.lock(lockfile)
Usage after creation:
cd my-project
poetry install # Install dependencies
poetry add requests # Add new dependency
poetry run pytest # Run tests
PIP
Standard Python package manager
- 🏠 Built-in: Included with Python
- 🌍 Universal: Works everywhere
- 📚 Familiar: Most developers know it
- 🔧 Simple: Straightforward workflow
Generated files:
requirements.txt
Usage after creation:
cd my-project
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
pip install -r requirements.txt
pip install requests
pytest
Specifying Package Manager
You can specify your preferred package manager:
Interactive selection (default):
Command line option:
$ fastkit init --package-manager poetry
$ fastkit init --package-manager pdm
$ fastkit init --package-manager uv
$ fastkit init --package-manager pip
Understanding Each Directory
src/ Directory
Contains all your application source code following the src layout pattern, which is a Python packaging best practice.
core/ Module
- config.py: Application settings, environment variables, and configuration
- Centralizes all configuration management
- Supports
.envfile for environment-specific settings
api/ Module
- api.py: Main API router that includes all sub-routers
- routes/: Individual route modules for different resources
- Clean separation of concerns for different API endpoints
crud/ Module
- Database operations and business logic
- Create, Read, Update, Delete operations
- Abstraction layer between API routes and data storage
schemas/ Module
- Pydantic models for data validation
- Request/response schemas
- Type definitions and data models
tests/ Directory
- Complete test suite for your application
- Includes unit tests and integration tests
- Pre-configured with pytest
Stack Comparison
| Feature | MINIMAL | STANDARD | FULL |
|---|---|---|---|
| FastAPI & Uvicorn | ✅ | ✅ | ✅ |
| Data Validation | ✅ | ✅ | ✅ |
| Database Support | ❌ | ✅ | ✅ |
| Migrations | ❌ | ✅ | ✅ |
| Testing Framework | ❌ | ✅ | ✅ |
| Caching (Redis) | ❌ | ❌ | ✅ |
| Background Tasks | ❌ | ❌ | ✅ |
| Best For | Learning, Simple APIs | Most Applications | Enterprise, Complex Apps |
Project Creation Examples
Example 1: Learning Project
Example 2: E-commerce API
Example 3: High-Performance Application
$ fastkit init
Enter the project name: enterprise-api
Enter the author name: Enterprise Team
Enter the author email: enterprise@company.com
Enter the project description: High-performance enterprise API
Select stack (minimal, standard, full): full
Do you want to proceed with project creation? [y/N]: y
After Project Creation
1. Activate Virtual Environment
2. Verify Installation
3. Start Development
Configuration Management
Environment Variables
Your project supports environment-based configuration through .env files:
Create a .env file in your project root:
# .env
APP_NAME=My Awesome API
APP_VERSION=1.0.0
DEBUG=True
DATABASE_URL=sqlite:///./app.db
SECRET_KEY=your-secret-key-here
Configuration in Code
The generated src/core/config.py automatically loads these variables:
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
APP_NAME: str = "FastAPI Application"
APP_VERSION: str = "1.0.0"
DEBUG: bool = False
DATABASE_URL: str = "sqlite:///./app.db"
SECRET_KEY: str = "dev-secret-key"
class Config:
env_file = ".env"
settings = Settings()
Customization Options
Adding Custom Dependencies
After project creation, you can add more dependencies:
Modifying Project Structure
While the generated structure follows best practices, you can modify it:
- Add new modules in
src/ - Create additional route files in
api/routes/ - Extend CRUD operations in
crud/ - Add more schemas in
schemas/
Best Practices
1. Virtual Environment
Always use virtual environments to isolate project dependencies:
# Create project with virtual environment
$ fastkit init # Automatically creates .venv/
# Activate when working
$ source .venv/bin/activate
2. Version Control
Initialize git repository after project creation:
3. Environment Configuration
- Use
.envfiles for local development - Use environment variables for production
- Never commit sensitive data to version control
4. Testing
Leverage the included test framework:
Next Steps
After creating your project:
- Adding Routes: Learn to add new API endpoints
- CLI Reference: Master all available commands
- Your First Project Tutorial: Build a complete application
Project Creation Tips
- Choose the stack that matches your project requirements
- Start with MINIMAL for learning, use STANDARD for most projects
- The project structure is designed for scalability and maintainability
- All generated code follows FastAPI best practices