Todo API
A simple REST API for managing todo items built with FastAPI and SQLite.
Features
- Create, read, update, and delete todo items
- Filter todos by completion status
- Input validation with Pydantic
- Database migrations with Alembic
- Error handling and structured responses
- Health check endpoint
- API documentation with Swagger UI
Technologies Used
- FastAPI - Modern web framework for building APIs
- SQLAlchemy - SQL toolkit and ORM
- Pydantic - Data validation and settings management
- Alembic - Database migration tool
- SQLite - File-based SQL database
- Uvicorn - ASGI server
- Ruff - Python linter and formatter
Project Structure
todoapi/
├── alembic.ini # Alembic configuration
├── app/ # Application package
│ ├── api/ # API endpoints
│ │ ├── endpoints/ # Endpoint handlers
│ │ │ └── todos.py # Todo endpoints
│ │ ├── api.py # API router
│ │ └── errors.py # Error handling
│ ├── db/ # Database
│ │ └── database.py # Database configuration
│ ├── models/ # SQLAlchemy models
│ │ └── todo.py # Todo model
│ └── schemas/ # Pydantic schemas
│ └── todo.py # Todo schemas
├── main.py # Application entry point
├── migrations/ # Database migrations
│ ├── env.py # Alembic environment
│ ├── script.py.mako # Migration template
│ └── versions/ # Migration scripts
├── pyproject.toml # Project configuration
└── requirements.txt # Dependencies
API Endpoints
GET /health
- Health check endpointGET /todos
- List all todo items (with optional filtering)GET /todos/{todo_id}
- Get a specific todo itemPOST /todos
- Create a new todo itemPUT /todos/{todo_id}
- Update a todo itemDELETE /todos/{todo_id}
- Delete a todo item
Getting Started
Prerequisites
- Python 3.9 or higher
Installation
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Run the application:
uvicorn main:app --reload
- Visit the API documentation at http://localhost:8000/docs
Database Migrations
The application uses Alembic for database migrations:
# Apply migrations
alembic upgrade head
# Create a new migration (after modifying models)
alembic revision --autogenerate -m "description"
Development
To lint and format the code:
ruff check .
ruff check --fix .
Description
Languages
Python
96.9%
Mako
3.1%