A modern, full-featured todo application built with Python, gRPC, FastAPI, and SQLAlchemy. This project demonstrates best practices for building scalable microservices with gRPC and provides both CLI and web interfaces.
- gRPC Backend: High-performance gRPC service with full CRUD operations
- Database Persistence: SQLite for development, PostgreSQL for production
- Multiple Interfaces: CLI client and web interface
- Task Management: Create, read, update, delete, complete, and archive tasks
- Advanced Filtering: Filter by status, priority, category, and search
- Rich CLI: Interactive command-line interface with beautiful output
- Modern Web UI: Responsive web interface with Bootstrap
- Type Safety: Full type hints and Pydantic models
- Error Handling: Comprehensive error handling and validation
- Python 3.8 or higher
- pip package manager
git clone <repository-url>
cd python-grpc-todo
pip install -r requirements.txtpython -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. proto/todo.protopython scripts/start_server.py# Interactive mode
python scripts/start_cli.py interactive
# Or use commands directly
python src/client/cli.py create "Buy groceries" --priority HIGH --category "Shopping"
python src/client/cli.py listpython scripts/start_web.pyVisit http://localhost:8000 to use the web interface.
pip install -r requirements-dev.txtThe application uses SQLite by default. For production, configure PostgreSQL:
# Set environment variable
export DATABASE_URL="postgresql://user:password@localhost/todo_db"The CLI client provides a rich command-line interface:
# Create a task
python src/client/cli.py create "Learn gRPC" --priority HIGH --category "Learning"
# List all tasks
python src/client/cli.py list
# List tasks with filters
python src/client/cli.py list --status TODO --priority HIGH
# Get task details
python src/client/cli.py get <task-id>
# Update a task
python src/client/cli.py update <task-id> --title "Updated title" --status IN_PROGRESS
# Complete a task
python src/client/cli.py complete <task-id>
# Archive a task
python src/client/cli.py archive <task-id>
# Delete a task
python src/client/cli.py delete <task-id>
# Interactive mode
python src/client/cli.py interactiveStart the web server:
python src/web/app.pyThe web interface provides:
- Create, edit, and delete tasks
- Filter and search tasks
- Mark tasks as complete
- Archive tasks
- Responsive design for mobile and desktop
Start the gRPC server:
python src/server/grpc_server.pyThe server provides:
- Full CRUD operations for tasks
- Filtering and pagination
- Health check endpoint
- Error handling and validation
The main service is TasksService with the following methods:
CreateTask(CreateTaskRequest) -> TaskGetTask(GetTaskRequest) -> TaskListTasks(ListTasksRequest) -> TaskListUpdateTask(UpdateTaskRequest) -> TaskDeleteTask(DeleteTaskRequest) -> EmptyResponseCompleteTask(GetTaskRequest) -> TaskArchiveTask(GetTaskRequest) -> TaskHealthCheck(HealthCheckRequest) -> HealthCheckResponse
The web interface exposes REST endpoints:
POST /api/tasks- Create taskGET /api/tasks/{id}- Get taskGET /api/tasks- List tasksPUT /api/tasks/{id}- Update taskDELETE /api/tasks/{id}- Delete taskPOST /api/tasks/{id}/complete- Complete taskPOST /api/tasks/{id}/archive- Archive taskGET /health- Health check
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ CLI Client │ │ Web Client │ │ Mobile Client │
│ (Rich CLI) │ │ (FastAPI) │ │ (Future) │
└─────────┬───────┘ └─────────┬───────┘ └─────────┬───────┘
│ │ │
└──────────────────────┼───────────────────────┘
│
┌─────────────▼─────────────┐
│ gRPC Server │
│ (TasksService) │
└─────────────┬─────────────┘
│
┌─────────────▼─────────────┐
│ Business Logic │
│ (TaskService) │
└─────────────┬─────────────┘
│
┌─────────────▼─────────────┐
│ Database Layer │
│ (SQLAlchemy) │
└───────────────────────────┘
-
gRPC Server (
src/server/grpc_server.py)- Handles gRPC requests
- Implements the TasksService
- Error handling and validation
-
Business Logic (
src/services/task_service.py)- Task management operations
- Data validation
- Business rules
-
Data Models (
src/models/task.py)- SQLAlchemy models
- Database operations
- Repository pattern
-
CLI Client (
src/client/cli.py)- Rich command-line interface
- Interactive mode
- Beautiful output formatting
-
Web Interface (
src/web/app.py)- FastAPI web server
- REST API endpoints
- HTML/JavaScript frontend
python-grpc-todo/
├── src/
│ ├── models/ # Database models
│ ├── services/ # Business logic
│ ├── server/ # gRPC server
│ ├── client/ # CLI client
│ ├── web/ # Web interface
│ └── utils/ # Utilities
├── proto/ # Protocol buffer definitions
├── config/ # Configuration
├── tests/ # Test files
├── scripts/ # Setup scripts
└── docs/ # Documentation
pytest# Format code
black src/ tests/
# Type checking
mypy src/
# Linting
flake8 src/ tests/
# Sort imports
isort src/ tests/# Create migration
alembic revision --autogenerate -m "Description"
# Apply migrations
alembic upgrade headDATABASE_URL: Database connection stringSERVER_HOST: Server host (default: 0.0.0.0)SERVER_PORT: Server port (default: 5000)LOG_LEVEL: Logging level (default: INFO)DEBUG: Debug mode (default: False)
The application supports multiple databases:
- SQLite (default):
sqlite:///./todo.db - PostgreSQL:
postgresql://user:password@localhost/todo_db
# Build image
docker build -t python-grpc-todo .
# Run container
docker run -p 5000:5000 -p 8000:8000 python-grpc-todo- Database: Use PostgreSQL for production
- Security: Implement authentication and authorization
- Monitoring: Add logging and metrics
- Scaling: Use load balancers and multiple instances
- SSL: Enable HTTPS/TLS for web interface
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run quality checks
- Submit a pull request
# Clone repository
git clone <repository-url>
cd python-grpc-todo
# Install dependencies
pip install -r requirements-dev.txt
# Install pre-commit hooks
pre-commit install
# Run tests
pytest
# Start development server
python src/server/grpc_server.pyThis project is licensed under the MIT License - see the LICENSE file for details.
- gRPC for the high-performance RPC framework
- FastAPI for the modern web framework
- SQLAlchemy for the ORM
- Rich for beautiful CLI output
- Bootstrap for the web interface
For questions and support:
- Create an issue on GitHub
- Check the documentation
- Review the examples in the
examples/directory
Happy coding!