Skip to content

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 framework
  • uvicorn - ASGI server
  • pydantic - Data validation
  • pydantic-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 operations
  • alembic - Database migrations
  • pytest - 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 storage
  • celery - 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:

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):

$ fastkit init
# ... prompts for package manager selection

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 .env file 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

$ fastkit init
Enter the project name: fastapi-learning
Enter the author name: Student
Enter the author email: student@example.com
Enter the project description: Learning FastAPI basics

Select stack (minimal, standard, full): minimal
Do you want to proceed with project creation? [y/N]: y

Example 2: E-commerce API

$ fastkit init
Enter the project name: ecommerce-api
Enter the author name: E-commerce Team
Enter the author email: team@ecommerce.com
Enter the project description: E-commerce platform API

Select stack (minimal, standard, full): standard
Do you want to proceed with project creation? [y/N]: y

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

$ cd my-awesome-api
$ source .venv/bin/activate  # Linux/macOS
$ .venv\Scripts\activate     # Windows

2. Verify Installation

$ pip list
Package         Version
fastapi         0.104.1
uvicorn         0.24.0
pydantic        2.5.0
...

3. Start Development

$ fastkit runserver
INFO:     Uvicorn running on http://127.0.0.1:8000

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:

$ pip install requests httpx python-jose
$ pip freeze > requirements.txt

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:

$ cd my-awesome-api
$ git init
$ git add .
$ git commit -m "Initial commit - FastAPI project setup"

3. Environment Configuration

  • Use .env files for local development
  • Use environment variables for production
  • Never commit sensitive data to version control

4. Testing

Leverage the included test framework:

$ python -m pytest
$ bash scripts/test.sh

Next Steps

After creating your project:

  1. Adding Routes: Learn to add new API endpoints
  2. CLI Reference: Master all available commands
  3. 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