
- Created FastAPI application with CRUD operations for tasks - Implemented SQLAlchemy models with Task entity - Added Pydantic schemas for request/response validation - Set up Alembic for database migrations - Configured SQLite database with proper file structure - Added health check and root endpoints - Included comprehensive API documentation - Applied CORS middleware for development - Updated README with detailed setup and usage instructions - Applied code formatting with ruff linter
Task Manager API
A simple and efficient Task Manager API built with FastAPI and SQLite. This API allows you to create, read, update, and delete tasks with full CRUD operations.
Features
- Create new tasks with title and description
- List all tasks with pagination support
- Get individual task details
- Update existing tasks (title, description, completion status)
- Delete tasks
- Mark tasks as completed/incomplete
- Health check endpoint
- Interactive API documentation
Technology Stack
- FastAPI - Modern, fast web framework for building APIs
- SQLAlchemy - SQL toolkit and Object-Relational Mapping (ORM)
- SQLite - Lightweight, file-based database
- Alembic - Database migration tool
- Pydantic - Data validation using Python type annotations
- Uvicorn - ASGI web server
Installation
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- Start the development server:
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Documentation
- Interactive docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
API Endpoints
Root
GET /
- API information and links
Health Check
GET /health
- Application health status
Tasks
POST /api/tasks/
- Create a new taskGET /api/tasks/
- Get all tasks (supports pagination withskip
andlimit
parameters)GET /api/tasks/{task_id}
- Get a specific task by IDPUT /api/tasks/{task_id}
- Update a specific taskDELETE /api/tasks/{task_id}
- Delete a specific task
Task Schema
{
"id": 1,
"title": "Sample Task",
"description": "This is a sample task description",
"completed": false,
"created_at": "2024-01-01T12:00:00.000Z",
"updated_at": "2024-01-01T12:00:00.000Z"
}
Project Structure
├── main.py # FastAPI application entry point
├── requirements.txt # Python dependencies
├── alembic.ini # Alembic configuration
├── alembic/ # Database migrations
│ ├── versions/ # Migration files
│ ├── env.py # Alembic environment configuration
│ └── script.py.mako # Migration template
├── app/
│ ├── __init__.py
│ ├── api/ # API route handlers
│ │ ├── __init__.py
│ │ └── tasks.py # Task-related endpoints
│ ├── db/ # Database configuration
│ │ ├── __init__.py
│ │ ├── base.py # SQLAlchemy base
│ │ └── session.py # Database session management
│ ├── models/ # SQLAlchemy models
│ │ ├── __init__.py
│ │ └── task.py # Task model
│ └── schemas/ # Pydantic schemas
│ ├── __init__.py
│ └── task.py # Task schemas for validation
└── storage/
└── db/ # SQLite database storage
└── db.sqlite # Database file (created automatically)
Development
The application uses automatic CORS configuration to allow requests from any origin during development.
Database migrations are handled through Alembic. The initial migration creates the tasks table with all necessary fields and indexes.
Environment Variables
No environment variables are required for basic operation. The application uses SQLite with a local file-based database stored in /app/storage/db/db.sqlite
.
Description
Languages
Python
93.2%
Mako
6.8%