Simple Todo App API
A simple Todo API built with FastAPI and SQLite.
Features
- Create, Read, Update, Delete (CRUD) operations for todo items
- Filter todos by completion status
- RESTful API with FastAPI
- SQLite database with SQLAlchemy ORM
- Alembic for database migrations
- API documentation with Swagger UI and ReDoc
Project Structure
.
├── alembic/ # Database migration files
│ ├── versions/ # Migration versions
│ ├── env.py # Alembic environment configuration
│ └── script.py.mako # Migration script template
├── app/ # Application code
│ ├── api/ # API endpoints
│ │ └── v1/ # API version 1
│ │ └── todos.py # Todo endpoints
│ ├── core/ # Core application code
│ │ └── config.py # Application configuration
│ ├── crud/ # CRUD operations
│ │ ├── base.py # Base CRUD operations
│ │ └── todo.py # Todo specific CRUD operations
│ ├── db/ # Database setup
│ │ ├── base.py # Import all models
│ │ ├── base_class.py # Base class for models
│ │ └── session.py # Database session
│ ├── models/ # SQLAlchemy models
│ │ └── todo.py # Todo model
│ └── schemas/ # Pydantic schemas
│ └── todo.py # Todo schemas
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Python dependencies
Getting Started
Prerequisites
- Python 3.7 or higher
Installation
-
Clone the repository
-
Install the dependencies:
pip install -r requirements.txt
-
Initialize the database directory:
python init_db.py
-
Apply the database migrations:
alembic upgrade head
-
Run the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Documentation
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Todos
GET /api/v1/todos
- Get all todosGET /api/v1/todos?is_completed=true|false
- Get todos filtered by completion statusGET /api/v1/todos/{id}
- Get a todo by idPOST /api/v1/todos
- Create a new todoPUT /api/v1/todos/{id}
- Update a todoDELETE /api/v1/todos/{id}
- Delete a todo
Health Check
GET /health
- Check if the API is running
Data Models
Todo
id
: Integer (Primary Key)title
: String (Required)description
: Text (Optional)is_completed
: Boolean (Default: false)created_at
: DateTime (Auto-generated)updated_at
: DateTime (Auto-updated)
Example
Create a Todo
curl -X 'POST' \
'http://localhost:8000/api/v1/todos/' \
-H 'Content-Type: application/json' \
-d '{
"title": "Learn FastAPI",
"description": "Build a simple todo app using FastAPI",
"is_completed": false
}'
Get All Todos
curl -X 'GET' 'http://localhost:8000/api/v1/todos/'
Description
Languages
Python
96.1%
Mako
3.9%