This FastAPI application processes Excel data from a file and exposes API endpoints for interaction with the data. The application reads from the Excel file ./Data/capbudg.xls and provides endpoints to list tables, get table details, and calculate row sums.
- Excel file processing with pandas
- REST API with FastAPI
- Error handling for robust operation
- Automatic API documentation with Swagger UI
- Python 3.8 or higher
- pip package manager
- Clone the repository:
git clone <repository-url>
cd <repository-directory>- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Ensure the Excel file exists at
./Data/capbudg.xls
Run the application with:
uvicorn main:app --host 0.0.0.0 --port 9090 --reloadThe API will be available at http://localhost:9090.
Root endpoint with welcome message and basic information.
Lists all table names (sheet names) present in the Excel file.
Response Example:
{
"tables": ["Initial Investment", "Revenue Projections", "Operating Expenses"]
}Returns the names of the rows for the specified table.
Parameters:
table_name(query): Name of the table/sheet to get details for
Response Example:
{
"table_name": "Initial Investment",
"row_names": [
"Initial Investment=",
"Opportunity cost (if any)=",
"Lifetime of the investment",
"Salvage Value at end of project=",
"Deprec.method(1:St.line;2:DDB)=",
"Tax Credit (if any )=",
"Other invest.(non-depreciable)="
]
}Calculates and returns the sum of all numerical data points in the specified row.
Parameters:
table_name(query): Name of the table/sheetrow_name(query): Name of the row to calculate sum for
Response Example:
{
"table_name": "Initial Investment",
"row_name": "Tax Credit (if any )=",
"sum": 10
}FastAPI provides automatic Swagger documentation for the API.
Access the documentation at http://localhost:9090/docs.
The API handles various error scenarios:
- 404: Excel file not found, table not found, or row not found
- 500: Error reading Excel file or calculating row sum
.
├── Data/
│ └── capbudg.xls # Excel file with data
├── main.py # Main FastAPI application
├── requirements.txt # Project dependencies
└── README.md # Project documentation
A Postman collection for testing the API is provided in postman_collection.json.
Import this file into Postman to easily test the API endpoints.
- Authentication & Authorization: Implement user authentication for secure API access
- Caching: Add caching mechanisms for frequently accessed data
- Database Integration: Store processed Excel data in a database for improved performance
- Data Validation: Add more sophisticated data validation and sanitization
- File Upload: Allow users to upload Excel files through the API
- Dashboard: Develop a web-based dashboard for data visualization
- Excel Format Support: Support additional Excel formats beyond .xls
- Complex Calculations: Implement more advanced data analysis operations
- Logging: Add comprehensive logging for better debugging and monitoring
- Containerization: Docker support for easier deployment
The application addresses several edge cases:
- Non-existent Excel file
- Missing table (sheet) in the Excel file
- Missing row in a table
- Non-numerical data in rows
- Empty rows or tables
- Special characters in table or row names