This project is a tutorial demonstration of a course query system, featuring a FastAPI-based backend and a real-time terminal animation client. It demonstrates how to interact with external APIs, manage data simulation, and create engaging command-line visualizations.
- ⚡ FastAPI Backend - High-performance asynchronous API for course data management.
- 🔄 Real-time Simulation - Background worker for simulating enrollment changes.
- 🎨 Terminal Animation - Dynamic terminal UI with color-coded enrollment tracking.
- 🛠️ Modern Tooling - Dependency management with
uv, type safety withPydantic. - 🌐 Async HTTP - Efficient external API calls using
httpx.
- Python 3.13+
- uv (recommended package manager)
# Install uv package manager
pip install uv
# Clone the repository
git clone https://github.com/GDG-NTUST/course-1141-3.git
cd course-1141-3
# Install dependencies
uv syncThe project consists of two main components that should be run in separate terminals.
The backend provides the course data API and handles simulations.
# Using uv script
uv run backend
# Or directly running the module
python src/backend/backend.pyThe server will be available at http://localhost:8000.
The client fetches data from the backend and displays it with animations.
# Using uv script
uv run animate
# Or directly running the file
python src/animate.py- Root:
GET /- Welcome message. - Health Check:
GET /healthz- System status. - Course Query:
POST /QueryCourse/api//courses- Search for courses using criteria.
The terminal client provides a live view of courses:
- Yellow: Current enrollment count.
- Red (+): Enrollment increased since the last update.
- Green (-): Enrollment decreased since the last update.
- Cyan: Course number and name.
course-1141-3/
├── src/
│ ├── backend/
│ │ └── backend.py # FastAPI server & Data logic
│ └── animate.py # Terminal visualization client
├── pyproject.toml # Project configuration & dependencies
└── README.md # Project documentation
backend.py:- Implements
CourseRepositoryfor data fetching and in-memory storage. - Features a
simulation_workerthat randomly updates course enrollment to demonstrate real-time tracking. - Uses FastAPI
lifespanfor managed startup and shutdown.
- Implements
animate.py:- Implements a polling loop to fetch data from the backend.
- Uses
coloramafor cross-platform terminal coloring. - Uses
wcwidthto ensure correct alignment for multi-byte characters (Chinese).
This project is licensed under the MIT License
Made with ❤️ by GDG NTUST
