A RESTful API for personal task management built with FastAPI and MongoDB. Features complete CRUD operations, advanced filtering, search functionality, and task completion tracking.
- Complete CRUD Operations: Create, read, update, and delete tasks
- Advanced Filtering: Filter tasks by completion status
- Search Functionality: Search through task titles and descriptions
- Sorting: Sort tasks by different fields (title, completion status, creation date)
- Task Completion Toggle: Mark tasks as complete or incomplete
- Statistics: Get real-time statistics about task completion
- MongoDB Integration: Persistent data storage with MongoDB Atlas
- Async Operations: Fast, non-blocking database operations
- Data Validation: Robust input validation with Pydantic
- Auto Documentation: Interactive API documentation with Swagger UI
- Docker Support: Containerized deployment ready
Access interactive API documentation at /docs endpoint
Complete task management with all CRUD operations
Get real-time completion rates and productivity metrics
- FastAPI: Modern, fast web framework for building APIs
- MongoDB: NoSQL database for flexible data storage
- Motor: Async MongoDB driver for Python
- Beanie: Async MongoDB ODM (Object Document Mapper)
- Pydantic: Data validation using Python type annotations
- Uvicorn: Lightning-fast ASGI server
Task-Manager-API/
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI application and routes
│ ├── database.py # MongoDB connection configuration
│ └── models/
│ ├── __init__.py
│ └── task.py # Task data model
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── .dockerignore # Docker ignore file
├── .env # Environment variables
├── .gitignore # Git ignore file
└── README.md # Project documentation
- Python 3.8+
- MongoDB Atlas account (or local MongoDB installation)
- Docker (optional, for containerized deployment)
-
Clone the repository
git clone https://github.com/Swordship/personal-task-management-API cd personal-task-management-API -
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
Create a
.envfile in the project root:MONGODB_URL=mongodb+srv://username:password@cluster.mongodb.net/ DATABASE_NAME=task_manager
-
Run the application
uvicorn app.main:app --reload
-
Access the API
- API: http://localhost:8000
- Interactive Docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
-
Build the Docker image
docker build -t my-task-api . -
Run the container
docker run -p 8000:8000 my-task-api
GET /- API health checkGET /about- Project information
GET /tasks- Get all tasks with optional filtering, searching, and sortingGET /tasks/{task_id}- Get a specific taskPOST /add_task- Create a new taskPUT /update_task/{task_id}- Update an existing taskDELETE /remove_task/{task_id}- Delete a task
PATCH /task/{task_id}/completed/- Mark task as completedPATCH /task/{task_id}/incompleted/- Mark task as incomplete
GET /task/stats- Get task completion statistics
| Parameter | Type | Description | Example |
|---|---|---|---|
completed |
boolean | Filter by completion status | ?completed=true |
search |
string | Search in title and description | ?search=homework |
sort |
string | Sort by field (task, completed, created_at, updated_at) | ?sort=created_at |
order |
string | Sort order (asc, desc) | ?order=desc |
Example Queries:
GET /tasks?completed=false&search=work&sort=created_at&order=desc
POST /add_task
Content-Type: application/json
{
"task": "Complete FastAPI tutorial",
"description": "Learn FastAPI by building a task manager"
}Response:
{
"_id": "60f7b3b3b3b3b3b3b3b3b3b3",
"task": "Complete FastAPI tutorial",
"description": "Learn FastAPI by building a task manager",
"completed": false,
"created_at": "2024-01-15T10:30:00.123Z",
"updated_at": "2024-01-15T10:30:00.123Z"
}GET /task/statsResponse:
{
"total_tasks": 10,
"completed_tasks": 6,
"incomplete_tasks": 4,
"completion_percentage": 60.0,
"summary": "You completed 6 out of 10 tasks!"
}Cloud-hosted MongoDB database with automatic scaling and backup
{
"_id": "MongoDB ObjectId",
"task": "string (required, max 200 characters)",
"description": "string (optional, max 1000 characters)",
"completed": "boolean (default: false)",
"created_at": "datetime (auto-generated)",
"updated_at": "datetime (auto-updated)"
}pytestblack app/flake8 app/The application can be deployed on various cloud platforms:
- Railway: Automatic deployment from GitHub
- Render: Docker and Git-based deployment
- Heroku: Container deployment
- DigitalOcean App Platform: Docker deployment
- AWS/GCP: Container services
Set these environment variables in your deployment platform:
MONGODB_URL: MongoDB connection stringDATABASE_NAME: Database name (default: task_manager)
Testing API endpoints with various HTTP clients
Managing tasks data with MongoDB Compass GUI
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Create a Pull Request
Developer: Monish
Email: monishravi508@gmail.com
GitHub: @Swordship
Project Link: personal-task-management-API
- FastAPI documentation and community
- MongoDB documentation
- Beanie ODM documentation
- Python async programming resources