ETL logic for Smart Data Manager.
Project description
smart-data-manager
TODO
- Create ETL tickets
📦 Project Dependencies
This project uses several Python libraries to support ETL workflows, data cleaning, reporting, and automated analytics. Below is a summary of each dependency and its role in the Smart Data Manager system.
1. pandas
Used for data extraction, transformation, and cleaning.
Provides DataFrame structures and powerful functions for manipulating customer, order, and product datasets.
2. SQLAlchemy
A Python ORM & database toolkit used to connect to Azure SQL Database.
Handles querying, inserts, updates, and writing transformed data back to SQL.
3. python-dotenv
Loads environment variables from a .env file.
Prevents exposing database credentials in code and keeps secrets out of GitHub.
4. openpyxl
Used for generating Excel-based reports (e.g., monthly BI report).
Enables writing multi-sheet, formatted reporting files.
5. matplotlib
Creates charts and visualizations for automated reports.
Used in daily sales reports, product performance graphs, and monthly summaries.
6. seaborn
Built on top of matplotlib.
Provides visually appealing statistical graphics for trends and analytics.
7. jinja2 (optional)
A templating engine used to generate AI-ready summaries or structured report templates.
Useful for creating consistent text-based reports (HTML, Markdown, TXT).
Here is the Installation Requirements section in raw Markdown, ready to paste into your README:
🔧 Installation & Setup
Follow the steps below to set up the Python environment for the Smart Data Manager ETL pipeline.
Prerequisites
Before you begin, ensure the following are installed on your system:
-
Python 3.10+
Download from: https://www.python.org/downloads/ -
pip (comes with Python)
-
Access to the Azure SQL Database (connection details)
🐍 1. Create and Activate a Virtual Environment
Navigate to the project folder:
cd smart-data-manager
Create the virtual environment:
python -m venv venv
Activate the environment:
Windows
venv\Scripts\activate
macOS / Linux
source venv/bin/activate
📦 2. Install Dependencies
Ensure you are inside the activated virtual environment, then run:
pip install -r requirements.txt
This installs all required packages for:
- Database connectivity
- ETL pipeline (extract, transform, load)
- Reporting and visualizations
- Environment variable management
🛠️ Database Seeding Script
The project includes a script to populate the database with realistic test data for Customers, Products, Orders, and OrderItems. This is useful for testing, development, and analytics purposes without relying on live production data.
File: seed.py
Features
-
Customers
- Generates a configurable number of customers (
NUM_CUSTOMERS). - Random first and last names from a predefined list.
- Emails are mostly valid but ~20% intentionally corrupted for testing validation.
- Guarantees uniqueness of email addresses.
- Generates a configurable number of customers (
-
Products
- Inserts products from a pre-defined catalog with categories (e.g., Mobile, Audio, Computing, Appliances).
- Prices are mostly valid, but ~15% are intentionally corrupted to test downstream validation and reporting (negative, zero, or extreme values).
- Random stock quantities between 0–200.
-
Orders & OrderItems
- Creates a configurable number of orders (
NUM_ORDERS) linked to seeded customers. - Each order contains 1–5 order items with random products and quantities.
- Order totals are calculated and stored in the
Orderstable. - Includes intentional corruption for testing (e.g., invalid order dates, slight price/quantity modifications).
- Creates a configurable number of orders (
-
Utility Functions
clear_tables()– Clears all related tables (Customers,Products,Orders,OrderItems) before seeding.corrupt_price()– Safely generates invalid product prices for testing.random_date()– Generates a random datetime within the last 30 days.
-
Safe Database Insertion
- Uses
pandas.to_sql()for bulk inserts. - Handles duplicates and ensures SQL-safe corruption.
- Performs bulk updates for order totals to optimize performance.
- Uses
Configuration
Adjust the following constants at the top of the script to control seeding behavior:
NUM_CUSTOMERS = 50
NUM_PRODUCTS = 30
NUM_ORDERS = 200
CORRUPTION_RATE = 0.15 # proportion of intentionally corrupted data
Usage Example
Run the script directly to seed the database:
python seed_database.py
Output:
🧹 Tables cleared
👥 Customers seeded: 50
📦 Products seeded: 30
🧾 Orders inserted: 200
🧺 OrderItems inserted: 450
🎉 Seeding complete!
This script is intended for development and testing environments only—do not run on production databases.
ETL Pipeline Overview
The project implements a full ETL (Extract, Transform, Load) pipeline to process sales data from SQL Server into an analytics-ready star schema. This pipeline is designed to support dashboards, reporting, and business intelligence in Power BI.
1. Extraction
-
File:
extract.py -
Description: Connects to the SQL Server database using
db.pyand extracts the following tables into pandas DataFrames:CustomersProductsOrdersOrderItems
-
Features:
- Handles connection errors and empty tables.
- Prints a preview of extracted data for verification.
2. Cleaning
-
File:
clean.py -
Description: Cleans and normalizes raw data before transformation.
-
Key Steps:
-
Removes duplicates.
-
Normalizes text (emails, names).
-
Handles nulls and invalid values (e.g., negative prices or quantities).
-
Adds derived fields:
full_nameinCustomersfull_descriptioninProductsline_totalinOrderItems
-
Logs detailed cleaning operations both to console and
transform.log.
-
3. Transformation
-
File:
transform.py -
Description: Reshapes cleaned data into analytics-ready tables following a star schema:
-
Dimensions
DimCustomers: Customer details.DimProducts: Product details.DimDate: Date dimension created fromOrders.order_date.
-
Facts
FactOrders: Order-level metrics.FactOrderItems: Item-level metrics (quantities, line totals).
-
-
Features:
- Wraps cleaning functions for end-to-end processing.
- Generates additional keys (
date_key) and derived columns. - Returns a dictionary of transformed DataFrames ready for loading.
4. Loading
-
File:
load.py -
Description: Loads transformed tables into SQL Server in proper dependency order:
- Dimensions first (
DimCustomers,DimProducts,DimDate) - Facts next (
FactOrders,FactOrderItems)
- Dimensions first (
-
Features:
- Supports
replaceorappendmodes. - Logs success and errors to both console and
load.log.
- Supports
5. Running the Pipeline
-
File:
run_etl_pipeline.py -
Description: Orchestrates the ETL flow end-to-end:
- Extract raw data from SQL Server.
- Clean and transform the data.
- Build dimensions and facts.
- Load the processed tables into SQL Server for Power BI consumption.
Usage Example:
python run_etl_pipeline.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smart_data_manager-1.0.10.tar.gz.
File metadata
- Download URL: smart_data_manager-1.0.10.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ed7b5d5a2827148ac9602498beface4eea50760f4c7cf4873ef68f1f635df15
|
|
| MD5 |
e01c843cf0be6cdf8ba1715fc23c2023
|
|
| BLAKE2b-256 |
c813bac9a34d81b93707942137aa329ac6e7adf2881f8cc0da1fc12c1bbe8868
|
File details
Details for the file smart_data_manager-1.0.10-py3-none-any.whl.
File metadata
- Download URL: smart_data_manager-1.0.10-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2d8176e5dd27fe6a10ea08205fe8832eed959db2d40d5b2c88d4f7ca198822c
|
|
| MD5 |
8ff3674698f4f30c58abb9886a1bc39b
|
|
| BLAKE2b-256 |
d7ac193221722fddc72b28b962803cb918d957abc1cf70465da9c92802527c72
|