Stock Log is a terminal-based stock portfolio tracker written in Python, built as a final project for CS50’s Introduction to Programming with Python (CS50P).
This lightweight app helps you record and manage stock transactions using a clean command-line interface and stores entries in a portable CSV file.
- 🖥️ Menu-driven interaction via Python’s
matchstatement - 💹 Track Buy/Sell actions for stocks
- 🔢 Input fields: ticker symbol, quantity, price, and date
- 📄 CSV-based persistence (no database needed)
- 📊 Display entries in a formatted table using
tabulate - ❗ Robust error handling for invalid inputs
- 🧪 Unit tested with
pytest(includes I/O simulation)
- ➕ Add a new entry
- ✏️ Update an existing entry
- ❌ Delete an entry
- 📋 View all entries
- 🚪 Exit
| File | Purpose |
|---|---|
project.py |
Main logic, interactive menu, and helper functions (main(), etc.) |
test_project.py |
Unit tests for core logic using pytest |
stock.csv |
Stores your stock entries (auto-created and updated) |
requirements.txt |
Lists required libraries (tabulate, cowsay) |
- CSV file is used to keep things simple and portable—ideal for beginners.
- Functions like
validate_action()andcalculate_total_price()are broken out for modularity and testability. - Focus was kept on clarity, correctness, and clean code, rather than excessive features.
- ✅ Input validation and calculation logic are unit-tested
- ✅ Uses
tmp_pathfixture inpytestto safely test file-writing logic without touching your real CSV file
- Managing updates and deletions in CSV required careful file rewrites
- Simulating file I/O for tests was tricky at first—learned
tmp_pathfixture to solve it! - Improving input error handling took time but made the app much smoother to use
Stock Log is a beginner-friendly, real-world application that combines essential programming concepts like:
- File handling
- User input validation
- Error management
- Modular design
- Automated testing
Whether you're just learning Python or want a basic terminal app for tracking your stocks, Stock Log is ready to use and extend.
Sanjay Kumar Sakamuri Kamalakar
📧 sksanjaykumar010307@gmail.com
🔗 LinkedIn
🧪 ORCID: 0009-0009-1021-2297
This project is licensed under the MIT License.
See the LICENSE file for full details.
- Thanks to the CS50 team and all open-source developers behind Python libraries
- Special appreciation to my professors and peers who supported this learning journey
🎉 Thank you for checking out Stock Log! If you like it, feel free to star ⭐ the repo or fork it and build your own version!