This is a simple Student Management REST API built using Python's Flask framework and SQLite for storage. It demonstrates basic CRUD operations (Create, Read, Update, Delete) and showcases how to write API tests with Keploy by auto-capturing HTTP calls as test cases.
- 🧑 Add, retrieve, update, and delete students
- 💾 Uses SQLite — no external DB setup required
- 🔌 RESTful API with JSON input/output
- ✅ Auto-generate test cases using Keploy CLI
- 🔄 Replay & validate API responses with Keploy
- Flask — Lightweight web framework
- Flask-SQLAlchemy — ORM for SQLite
- SQLite — Built-in relational DB
- Keploy — Testing toolkit for API auto-mocking and regression testing
- Clone the repository
git clone https://github.com/<your-username>/samples-python.git
cd samples-python/flask-sqlite- Set up virtual environment (optional)
python3 -m venv venv
source venv/bin/activate- Install Dependencies
pip install -r requirements.txt- Run the Flask app
python app.py| Method | Endpoint | Description |
| ------ | ---------------- | -------------------- |
| GET | `/students` | Get all students |
| POST | `/students` | Add a new student |
| PUT | `/students/<id>` | Update student by ID |
| DELETE | `/students/<id>` | Delete student by ID |
{
"message": "Flask Student API"
}curl -X POST http://localhost:5000/students \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "age": 21}'curl http://localhost:5000/students
curl -X PUT http://localhost:5000/students/1
-H "Content-Type: application/json"
-d '{"name": "Alice Updated", "age": 22}'
curl -X DELETE http://localhost:5000/students/1
---
## Running Keploy Tests
Step 1: Record Tests
Start Keploy in record mode:
```bash
keploy record --command "python app.py"
Send some API requests via curl or Postman to generate test cases.
Step 2: Replay Tests After recording, stop the app and run:
keploy test --command "python app.py"Keploy will replay the previously captured requests and validate responses.
flask-sqlite/
├── app.py # Flask app entry point
├── models.py # Student model
├── requirements.txt # Python dependencies
├── keploy.yml # Keploy config file
├── keploy/ # Auto-generated test cases
└── README.md # You are here!Want to improve or add another example (e.g. FastAPI, SQLModel, etc.)? Contributions are welcome! Fork this repo, create your example folder, and submit a PR.
Keploy is a developer-friendly open-source testing toolkit that auto-generates test cases from API calls in real-time and replays them to catch regressions — without writing any test code.
Built with ❤️ for the Open Source Community.
| Stage | Improvement Type | Description |
|---|---|---|
| Stage 1 | Validation & Pagination | Add search, filter, pagination for students |
| Stage 2 | Security | Add authentication, role-based access |
| Stage 3 | Code Quality | Integrate Marshmallow/Pydantic, add tests |
| Stage 4 | Documentation & Deployment | Add Swagger, Dockerize, CI/CD pipeline |
| Stage 5 | Frontend & Realtime Features | Build React UI, add WebSocket updates |
Get End points
/students?page=1&per_page=5 — Gets first 5 students.
/students?name=John — Filters students whose names contain "John".
/students?age=20 — Filters students aged 20.
/students?page=2&per_page=3&name=ann — Combination.