📊 Automated Reporting with SQL & Python
This project demonstrates how to automate the process of querying data from a SQL database, generating reports using Python, and exporting the results into structured Excel files. It is particularly useful for business analysts, data engineers, or teams that require daily/weekly automated reports.
- ✅ Connects to a SQL Server database using
pyodbc
- ✅ Executes parameterized SQL queries
- ✅ Automates daily or scheduled report generation
- ✅ Exports results to Excel (.xlsx) with formatted sheets
- ✅ Handles exceptions and logging for reliability
- Language: Python 3.x
- Database: Microsoft SQL Server
- Libraries Used:
pandas
pyodbc
openpyxl
os
,datetime
,time
Automated-Reporting-with-SQL-Python/
├── sql\_query.sql # Contains the SQL query for the report
├── config.py # Configuration (DB credentials, file paths)
├── report\_generator.py # Main script to run the automation
├── requirements.txt # Required libraries
└── README.md # Project documentation
-
Connect to the Database:
pyodbc
establishes a secure connection to the SQL Server using credentials inconfig.py
. -
Run SQL Query:
The script reads a.sql
file and executes it dynamically. -
Generate Report:
Results are loaded into a pandas DataFrame and written to Excel usingopenpyxl
. -
Automation Ready:
You can schedule this script using Task Scheduler (Windows) orcron
(Linux/macOS) for regular execution.
-
Clone the Repo
git clone https://github.com/3m0r9/Automated-Reporting-with-SQL-Python.git cd Automated-Reporting-with-SQL-Python
-
Install Dependencies
pip install -r requirements.txt
-
Edit
config.py
Add your database credentials and output directory. -
Run the Script
python report_generator.py
- A retail company wants to send daily sales summaries to regional managers.
- This tool runs at 6:00 AM every day and generates Excel reports from their database.
- The report is emailed via a separate integration (can be extended).
✍️ Author
- Imran Abu Libda
- GitHub - 3m0r9
- LinkedIn - Imran Abu Libda
- Email - imranabulibda@gmail.com
- Medium - Imran Abu Libda
This project is licensed under the MIT License – see the LICENSE file for details.
Pull requests and feedback are welcome. For major changes, please open an issue first to discuss what you would like to change.