This is an Expense Tracking System built with FastAPI for the backend and Streamlit for the frontend. The system allows users to add, update, and analyze their expenses. It interacts with a MySQL database to store and retrieve expense data.
- Expense Management: Add, update, and delete expenses by date.
- Analytics: Generate summary and visualize expenses by category and bar chart with area chart.
- User Interface: Simple and interactive UI built with Streamlit.
- Backend: FastAPI
- Frontend: Streamlit
- Database: MySQL
- Data Visualization: Matplotlib for charts
- Logging: Python logging for error and information tracking
- Python 3.7+
- MySQL database running locally or on a server.
requirements.txt(see below for dependencies).
-
Clone this repository to your local machine:
git clone https://github.com/your-repo/expense-tracking.git cd expense-tracking -
Install the required Python dependencies:
pip install -r requirements.txt
-
Set up the MySQL database:
- Make sure you have MySQL installed and running.
- Create a database called
expense_managerand set up theexpensestable.
-
Configure the database connection in
db_connection.py:connection = mysql.connector.connect( host="localhost", user="root", password="root", # Change the password if needed database="expense_manager" )
-
Run the FastAPI server:
uvicorn server:app --reload
-
Run the Streamlit UI:
streamlit run app.py
db_connection.py: Handles MySQL database connections and CRUD operations for expenses.logging_setup.py: Sets up logging for the application.server.py: FastAPI app, which provides API endpoints to manage expenses and generate analytics.add_update_ui.py: Streamlit UI for adding and updating expenses.analytics_ui.py: Streamlit UI for visualizing expense data with graphs and pie charts.app.py: Main entry point for the Streamlit application that integratesadd_update_ui.pyandanalytics_ui.py.test_db_connection.py: Unit tests for database connection and CRUD functionality.conftest.py: Configures project root path for testing.
GET /expenses/{expense_date}: Fetch all expenses for a specific date.POST /expenses/{expense_date}: Add or update expenses for a specific date.POST /analytics/: Fetch expense summary and analytics within a date range.
To test the database connection and CRUD operations, you can run the tests in test_db_connection.py using:
pytest test_db_connection.py- Add/Update Expenses: Use the "Add/Update" tab in the Streamlit UI to input new expenses or modify existing ones.
- Expense Analytics: Use the "Analytics" tab in Streamlit to view detailed charts and category-wise summaries of your expenses.
Sample response for GET /expenses/2024-08-15:
[
{
"amount": 10.0,
"category": "Shopping",
"notes": "Bought potatoes"
}
]Sample response for POST /analytics/:
[
{
"category": "Food",
"total": 150.0
},
{
"category": "Rent",
"total": 500.0
}
]Feel free to fork this project and create a pull request. Contributions to improve the functionality or UI are welcome!
This project is open-source and available under the MIT License.