Introduction
In this tutorial, we'll explore how to monitor and analyze pricing changes in cloud services like Microsoft 365 using Python. The recent antitrust probe by Italy into Microsoft 365's AI price rise highlights the importance of transparency in software pricing. This tutorial will teach you how to build a simple monitoring system that can track pricing changes over time, which is crucial for businesses to make informed decisions about their software subscriptions.
Prerequisites
- Basic understanding of Python programming
- Python 3.7 or higher installed
- Knowledge of REST APIs and HTTP requests
- Basic understanding of data analysis with pandas
- Access to a Microsoft 365 subscription or test environment
Step-by-Step Instructions
Step 1: Setting Up Your Development Environment
Install Required Libraries
First, we need to install the necessary Python libraries for making HTTP requests and analyzing data. The key libraries we'll use are requests for API calls and pandas for data analysis.
pip install requests pandas
Why this step? These libraries provide the foundation for fetching data from APIs and organizing it for analysis. requests handles HTTP communication, while pandas helps us manipulate and visualize the pricing data.
Step 2: Understanding Microsoft 365 Pricing APIs
Research Available APIs
Microsoft provides several APIs related to licensing and pricing information. For this tutorial, we'll focus on the Microsoft 365 pricing information that can be accessed through their pricing pages or API endpoints. We'll create a simple script that fetches pricing data from a known endpoint.
Why this step? Understanding the available data sources is crucial for building a monitoring system. Microsoft's pricing information is typically available through their official APIs or web scraping methods.
Step 3: Creating a Pricing Data Fetcher
Building the Data Collection Script
Let's create a Python script that fetches pricing information from Microsoft's pricing API. This script will simulate what a monitoring system might do:
import requests
import pandas as pd
import json
from datetime import datetime
def fetch_microsoft_pricing():
# This is a placeholder URL - in reality, you'd use the actual Microsoft API endpoint
url = "https://api.microsoft.com/pricing/v1/microsoft365"
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
}
try:
response = requests.get(url, headers=headers)
response.raise_for_status() # Raises an HTTPError for bad responses
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error fetching data: {e}")
return None
# Fetch pricing data
pricing_data = fetch_microsoft_pricing()
if pricing_data:
print(json.dumps(pricing_data, indent=2))
else:
print("Failed to fetch pricing data")
Why this step? This script demonstrates how to make authenticated API calls to fetch pricing data. In practice, you'd need to register for a Microsoft API key or use their official pricing endpoints.
Step 4: Storing and Tracking Pricing Changes
Creating a Database for Historical Data
To track pricing changes over time, we need to store historical data. We'll use SQLite for this example:
import sqlite3
import json
def create_database():
conn = sqlite3.connect('microsoft_pricing.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS pricing_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
product TEXT,
price REAL,
currency TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
''')
conn.commit()
conn.close()
print("Database created successfully")
def store_pricing_data(product, price, currency):
conn = sqlite3.connect('microsoft_pricing.db')
cursor = conn.cursor()
cursor.execute('''
INSERT INTO pricing_history (product, price, currency)
VALUES (?, ?, ?)
''', (product, price, currency))
conn.commit()
conn.close()
print(f"Pricing data for {product} stored successfully")
# Create the database
create_database()
# Store some sample data
store_pricing_data("Microsoft 365 Business Premium", 12.50, "USD")
store_pricing_data("Microsoft 365 E3", 30.00, "USD")
Why this step? Storing historical data is essential for detecting pricing changes over time. This allows businesses to track when and how much prices have changed, which is critical for compliance and budgeting purposes.
Step 5: Implementing Price Change Detection
Building a Change Detection System
Now we'll create a system that compares current pricing with historical data to detect changes:
def detect_price_changes():
conn = sqlite3.connect('microsoft_pricing.db')
# Get the latest pricing for each product
query = """
SELECT product, price, currency, timestamp
FROM pricing_history
WHERE timestamp = (
SELECT MAX(timestamp)
FROM pricing_history ph2
WHERE ph2.product = pricing_history.product
)
"""
latest_data = pd.read_sql_query(query, conn)
# Get historical data for comparison
historical_query = """
SELECT product, price, currency, timestamp
FROM pricing_history
WHERE timestamp < (
SELECT MAX(timestamp)
FROM pricing_history ph2
WHERE ph2.product = pricing_history.product
)
AND timestamp = (
SELECT MAX(timestamp)
FROM pricing_history ph3
WHERE ph3.product = pricing_history.product
AND ph3.timestamp < (
SELECT MAX(timestamp)
FROM pricing_history ph4
WHERE ph4.product = pricing_history.product
)
)
"""
historical_data = pd.read_sql_query(historical_query, conn)
conn.close()
# Compare and identify changes
changes = []
for _, latest_row in latest_data.iterrows():
product = latest_row['product']
latest_price = latest_row['price']
# Find corresponding historical price
historical_row = historical_data[historical_data['product'] == product]
if not historical_row.empty:
historical_price = historical_row.iloc[0]['price']
if latest_price != historical_price:
change_amount = latest_price - historical_price
change_percentage = (change_amount / historical_price) * 100
changes.append({
'product': product,
'old_price': historical_price,
'new_price': latest_price,
'change_amount': change_amount,
'change_percentage': change_percentage
})
return changes
# Run change detection
changes = detect_price_changes()
if changes:
print("Price changes detected:")
for change in changes:
print(f"{change['product']}: {change['old_price']} → {change['new_price']} ({change['change_percentage']:.2f}%)")
else:
print("No significant price changes detected")
Why this step? This system automates the process of detecting pricing changes, which is exactly what regulators like Italy's competition authority are concerned about. It helps businesses stay informed about pricing modifications that could affect their budgeting and compliance.
Step 6: Creating a Reporting Dashboard
Generating Price Change Reports
Finally, let's create a simple reporting system that generates a summary of price changes:
def generate_price_report():
conn = sqlite3.connect('microsoft_pricing.db')
# Get all pricing data
query = "SELECT product, price, currency, timestamp FROM pricing_history ORDER BY timestamp"
df = pd.read_sql_query(query, conn)
conn.close()
# Group by product and show price trends
report = df.groupby('product').agg({
'price': ['min', 'max', 'mean'],
'timestamp': ['first', 'last']
}).round(2)
print("Price Change Report:")
print(report)
# Save to CSV for further analysis
report.to_csv('pricing_trends_report.csv')
print("Report saved to pricing_trends_report.csv")
# Generate the report
generate_price_report()
Why this step? A comprehensive reporting system allows businesses to analyze long-term pricing trends, which is essential for compliance with regulations like those being investigated in Italy. It provides evidence of pricing changes that can be used for internal audits or regulatory compliance.
Summary
In this tutorial, we've built a system to monitor Microsoft 365 pricing changes using Python. We've created a data fetching mechanism, implemented a database for storing historical pricing data, built a price change detection system, and generated comprehensive reports. This system demonstrates the kind of monitoring that regulators are interested in when examining pricing practices in cloud services. By tracking these changes, businesses can ensure compliance with regulations and maintain transparency in their software licensing decisions.
The skills learned in this tutorial can be applied to any cloud service or software licensing scenario where price transparency and change tracking are important. This is particularly relevant in light of the recent antitrust investigations into Microsoft's pricing practices, where such monitoring systems could provide crucial evidence of pricing manipulation or lack of proper opt-out mechanisms.



