The Smart Expense Tracker API is a RESTful web service built with Python and FastAPI that helps users manage their personal expenses. It allows users to add, view, filter, calculate, and delete expenses. Data is stored in a local JSON file, making the application lightweight and easy to run without a database.
- Add a new expense
- View all expenses
- Filter expenses by category
- Calculate total expenses
- Calculate total expenses by category
- Delete an expense
- Interactive API documentation using Swagger UI
- Python 3.10+
- FastAPI
- Uvicorn
- Pydantic
- Pytest
- JSON (Local File Storage)
expense-tracker-api/
│
├── README.md
├── AI_NOTES.md
├── requirements.txt
├── expenses.json
│
├── src/
│ ├── __init__.py
│ ├── main.py
│ ├── models.py
│ └── storage.py
│
└── tests/
├── __init__.py
└── test_api.py
git clone https://github.com/<your-username>/expense-tracker-api.gitcd expense-tracker-apiWindows
python -m venv venv
venv\Scripts\activateLinux/macOS
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtStart the FastAPI development server:
uvicorn src.main:app --reloadThe API will be available at:
http://127.0.0.1:8000
Swagger UI:
http://127.0.0.1:8000/docs
ReDoc Documentation:
http://127.0.0.1:8000/redoc
Run all tests using:
pytest| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Welcome endpoint |
| POST | /expenses |
Add a new expense |
| GET | /expenses |
View all expenses |
| GET | /expenses?category=Food |
Filter expenses by category |
| GET | /expenses/total |
Calculate total expenses |
| GET | /expenses/total?category=Food |
Calculate total for a category |
| DELETE | /expenses/{expense_id} |
Delete an expense |
POST /expenses
Request Body
{
"title": "Lunch",
"amount": 250,
"category": "Food",
"date": "2026-08-02"
}Response
{
"message": "Expense added successfully",
"expense": {
"id": 1,
"title": "Lunch",
"amount": 250,
"category": "Food",
"date": "2026-08-02"
}
}The application stores all expense records in a local file named expenses.json. No external database is required.
The API validates user input and returns appropriate HTTP status codes and error messages. For example:
- Invalid input data returns a validation error.
- Attempting to delete a non-existent expense returns 404 Not Found.
- User authentication
- Database integration (SQLite or PostgreSQL)
- Update expense endpoint
- Pagination for large datasets
- Search by title or date
- Monthly expense summary
Vishal Vishwas Desai
GitHub: https://github.com/Vishal-desai