A comprehensive task management API built with FastAPI, SQLModel, and SQLite. This API provides full CRUD operations for managing tasks with features like filtering, pagination, and data validation.
- Full CRUD Operations: Create, Read, Update, and Delete tasks
- Data Validation: Comprehensive input validation using Pydantic
- Filtering: Filter tasks by
statusandpriorityquery parameters - Pagination: Support for
skip/limitquery parameters - Sorting: Sort tasks by
title,created_at,due_date,priority,status - Full-text Search: Search tasks by text across
titleanddescription - Bulk Operations: Bulk update and bulk delete tasks
- Author Tracking: Optional
authorfield on tasks - Database Integration: SQLModel/SQLAlchemy with SQLite
- API Documentation: Automatic OpenAPI/Swagger documentation
- Error Handling: Proper error responses with meaningful messages
- CORS Support: Cross-origin requests enabled
- FastAPI - Modern, fast web framework for building APIs
- SQLModel - SQL databases in Python, designed for simplicity, compatibility, and robustness
- SQLite - Lightweight, serverless database
- Pydantic - Data validation and settings management using Python type annotations
- Uvicorn - Lightning-fast ASGI server
- Clone the repository:
git clone https://github.com/Muawia24/Task-Management-API
cd Task-Management-API- Install dependencies:
pip install -r requirements.txtpython -m app.mainuvicorn app.main:app --host 0.0.0.0 --port 8000 --reloaddocker build -t task-management-api .
docker run -p 8000:8000 task-management-apidocker-compose up -ddocker-compose --profile dev up task-api-devThe API will be available at:
- API Base URL: http://localhost:8000
- Interactive Documentation: http://localhost:8000/docs
- Alternative Documentation: http://localhost:8000/redoc
- OpenAPI Schema: http://localhost:8000/openapi.json
The Docker container includes a health check that monitors the /health endpoint. You can check container health with:
docker psGET /- API information and available endpointsGET /health- API health status
POST /tasks/- Create a new taskGET /tasks/- List all tasks (with pagination)GET /tasks/{task_id}- Get a specific task by IDPUT /tasks/{task_id}- Update an existing taskDELETE /tasks/{task_id}- Delete a taskPUT /tasks/bulk-update- Bulk update multiple tasksDELETE /tasks/bulk-delete- Bulk delete multiple tasks
GET /tasks/sort-by/{field}- Sort tasks by a field- Valid fields:
title,created_at,due_date,priority,status priorityorder: urgent > high > medium > lowstatusorder: pending > in_progress > completed > cancelled
- Valid fields:
GET /tasks/search?text=...&skip=0&limit=10- Search intitleanddescriptionwith pagination
GET /tasks/?status={status}- Filter tasks by statusGET /tasks/?priority={priority}- Filter tasks by priority- Both filters can be combined with pagination:
GET /tasks/?status={status}&priority={priority}&skip=0&limit=10
PUT /tasks/bulk-update- Update multiple tasks in one request- Body:
{ "updates": [{ "id": 1, "status": "completed", ... }, ...] } - Returns:
{ "updated_count": <number> } - Validation: 400 for empty updates, 404 if any ID is not found, 422 for invalid data
- Body:
DELETE /tasks/bulk-delete- Delete multiple tasks in one request- Body:
{ "task_ids": [1, 2, 3] } - Returns:
{ "deleted": <number> }
- Body:
| Field | Type | Constraints | Description |
|---|---|---|---|
| id | Integer | Primary Key, Auto-increment | Unique task identifier |
| title | String | Required, Max 200 chars | Task title |
| description | String | Optional, Max 1000 chars | Task description |
| status | Enum | Required, Default: "pending" | Task status |
| priority | Enum | Required, Default: "medium" | Task priority |
| created_at | DateTime | Auto-generated | Creation timestamp |
| updated_at | DateTime | Optional | Last update timestamp |
| due_date | DateTime | Optional | Task deadline |
| assigned_to | String | Optional, Max 100 chars | Assignee name |
| author | String | Optional, Max 100 chars | Author name |
TaskStatus:
pendingin_progresscompletedcancelled
TaskPriority:
lowmediumhighurgent
curl -X POST "http://localhost:8000/tasks/" \
-H "Content-Type: application/json" \
-d '{
"title": "Complete project documentation",
"description": "Write comprehensive documentation for the project",
"priority": "high",
"assigned_to": "John Doe",
"author": "Alice"
}'curl "http://localhost:8000/tasks/"curl "http://localhost:8000/tasks/?skip=0&limit=5"curl "http://localhost:8000/tasks/?status=pending"
curl "http://localhost:8000/tasks/?priority=high"
curl "http://localhost:8000/tasks/?status=in_progress&priority=urgent&skip=0&limit=10"curl "http://localhost:8000/tasks/sort-by/title"
curl "http://localhost:8000/tasks/sort-by/priority"curl "http://localhost:8000/tasks/search?text=report&skip=0&limit=10"curl "http://localhost:8000/tasks/1"curl -X PUT "http://localhost:8000/tasks/1" \
-H "Content-Type: application/json" \
-d '{
"status": "in_progress",
"assigned_to": "Jane Smith"
}'curl -X PUT "http://localhost:8000/tasks/bulk-update" \
-H "Content-Type: application/json" \
-d '{
"updates": [
{ "id": 1, "status": "completed" },
{ "id": 2, "priority": "urgent", "due_date": "2030-01-01T00:00:00Z" }
]
}'curl -X DELETE "http://localhost:8000/tasks/bulk-delete" \
-H "Content-Type: application/json" \
-d '{
"task_ids": [1, 2, 3]
}'- Case-insensitive search across
titleanddescription - Empty
textreturns400 - No matches return
404
curl -X DELETE "http://localhost:8000/tasks/1"The API includes comprehensive validation:
- Title Validation: Cannot be empty or whitespace only, automatically trimmed
- Due Date Validation: Must be in the future if provided
- Field Length Validation: Enforced maximum lengths for string fields
- Enum Validation: Status and priority must be valid enum values
The API returns appropriate HTTP status codes:
200- Successful retrieval/update201- Successful creation204- Successful deletion400- Bad request/validation error404- Resource not found422- Unprocessable entity (validation error)
The application uses SQLite for data storage. The database file (db.sqlite3) is automatically created when the application starts. Tables are created automatically based on the SQLModel definitions.
This project uses Alembic for schema migrations. Existing migrations are stored under migrations/versions/ (e.g., the migration adding the author field).
alembic upgrade head- Update your SQLModel definitions (e.g., in
app/models/Task.py). - Generate a migration script:
alembic revision --autogenerate -m "describe your change"- Review the generated file in
migrations/versions/and adjust if needed. - Apply the migration:
alembic upgrade headalembic downgrade -1Notes:
- On Windows/PowerShell inside the provided
venv, use the bundledalembic.exeor runpython -m alembic .... - With SQLite, some operations (e.g., dropping columns) may require Alembic to emit batch operations; check the generated script before applying.
Task-Management-API/
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI application entry point
│ ├── db/
│ │ ├── __init__.py
│ │ ├── database.py # Database operations
│ │ ├── dependancies.py # Database dependencies
│ │ └── session.py # Database session management
│ ├── models/
│ │ ├── __init__.py
│ │ └── Task.py # SQLModel task model
│ ├── routers/
│ │ ├── __init__.py
│ │ └── task_routes.py # API route definitions
│ └── schemas/
│ ├── __init__.py
│ └── task.py # Pydantic schemas
├── tests/
│ └── __init__.py
├── requirements.txt
├── README.md
└── todo.md
pytest- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is part of a FastAPI assessment and is intended for educational purposes.
For questions or issues, please open an issue on the GitHub repository.