A simple and clean REST API built with FastAPI for managing tasks. Perfect for learning FastAPI fundamentals.
- ✅ Create, read, update, and delete tasks (CRUD operations)
- ✅ Filter tasks by completion status
- ✅ SQLite database with SQLAlchemy ORM
- ✅ Pydantic models for data validation
- ✅ Comprehensive test suite with pytest
- ✅ Interactive API documentation (Swagger UI)
- ✅ Type hints throughout the codebase
- ✅ Clean project structure following best practices
- FastAPI - Modern web framework for building APIs
- SQLAlchemy - SQL toolkit and ORM
- Pydantic - Data validation using Python type hints
- SQLite - Lightweight database
- Pytest - Testing framework
- Uvicorn - ASGI server
fastapi-task-manager/
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI application and routes
│ ├── models.py # SQLAlchemy database models
│ ├── schemas.py # Pydantic schemas
│ ├── crud.py # Database operations
│ └── database.py # Database configuration
├── tests/
│ ├── __init__.py
│ └── test_main.py # API tests
├── requirements.txt # Project dependencies
├── README.md
└── .gitignore
- Python 3.8 or higher
- pip (Python package installer)
- Clone the repository:
git clone git@github.com:yourusername/fastapi-task-manager.git
cd fastapi-task-manager- Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtStart the development server using the FastAPI CLI:
fastapi dev app/main.pyFor production deployment:
fastapi run app/main.pyThe API will be available at http://127.0.0.1:8000
- Swagger UI:
http://127.0.0.1:8000/docs - ReDoc:
http://127.0.0.1:8000/redoc
GET /- Welcome message
POST /tasks/- Create a new taskGET /tasks/- Get all tasks (supports filtering and pagination)GET /tasks/{task_id}- Get a specific taskPUT /tasks/{task_id}- Update a taskDELETE /tasks/{task_id}- Delete a task
curl -X POST "http://127.0.0.1:8000/tasks/" \
-H "Content-Type: application/json" \
-d '{"title": "Learn FastAPI", "description": "Complete the tutorial", "completed": false}'curl "http://127.0.0.1:8000/tasks/"curl "http://127.0.0.1:8000/tasks/?completed=true"curl -X PUT "http://127.0.0.1:8000/tasks/1" \
-H "Content-Type: application/json" \
-d '{"completed": true}'curl -X DELETE "http://127.0.0.1:8000/tasks/1"Execute the test suite:
pytestRun tests with coverage:
pytest --cov=app tests/- Build the Docker image:
docker build -t fastapi-task-manager .- Run the container:
docker run -p 8000:8000 fastapi-task-managerdocker-compose upThe API will be available at http://localhost:8000
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
- Built with FastAPI
- Inspired by the FastAPI community