Introduction
In today's interconnected world, businesses are increasingly looking beyond traditional markets to reach underserved populations in emerging economies. Arpit Agrawal's work demonstrates how technology can be leveraged to create scalable distribution ecosystems that connect global brands with billions of consumers who have historically been left out of mainstream commerce. In this tutorial, you'll learn how to build a basic distribution network management system using Python and SQLite, which can help you understand the foundational concepts behind creating scalable distribution systems for emerging markets.
This tutorial will teach you how to:
- Set up a database to manage distribution networks
- Create a simple interface to track products and their distribution
- Build basic queries to analyze distribution patterns
Prerequisites
To follow along with this tutorial, you'll need:
- A computer with internet access
- Python 3.6 or higher installed on your system
- Basic understanding of Python programming concepts
- Text editor or IDE (like VS Code, PyCharm, or even Notepad)
No prior experience with databases is required, as we'll be using SQLite, which is included with Python.
Step-by-Step Instructions
Step 1: Install Python and Set Up Your Environment
First, make sure you have Python installed on your computer. You can check this by opening your terminal or command prompt and typing:
python --version
If Python is installed, you'll see a version number. If not, download and install Python from python.org.
Step 2: Create a New Project Folder
Create a new folder on your computer called distribution_system. This will be your project directory where we'll store all our files.
Step 3: Create the Database Structure
We'll use SQLite to create our database. SQLite is a lightweight database that doesn't require a separate server process and is perfect for small to medium-sized applications.
Create a new file called database.py in your project folder and add the following code:
import sqlite3
def create_database():
conn = sqlite3.connect('distribution.db')
cursor = conn.cursor()
# Create tables for our distribution system
cursor.execute('''
CREATE TABLE IF NOT EXISTS products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
category TEXT,
price REAL,
description TEXT
)''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS distribution_centers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
location TEXT,
capacity INTEGER
)''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS distribution_routes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
product_id INTEGER,
center_id INTEGER,
quantity INTEGER,
status TEXT,
FOREIGN KEY (product_id) REFERENCES products (id),
FOREIGN KEY (center_id) REFERENCES distribution_centers (id)
)''')
conn.commit()
conn.close()
if __name__ == '__main__':
create_database()
print("Database created successfully!")
Why we're doing this: This code sets up the basic structure of our distribution system. We're creating three tables: one for products, one for distribution centers, and one for tracking routes. These tables will help us manage the flow of goods from production to end consumers.
Step 4: Add Sample Data to the Database
Now, let's add some sample data to our database. Create a new file called sample_data.py:
import sqlite3
def insert_sample_data():
conn = sqlite3.connect('distribution.db')
cursor = conn.cursor()
# Insert sample products
products = [
('Rice', 'Grains', 2.50, 'Basmati rice from India'),
('Tea', 'Beverages', 1.20, 'Black tea blend'),
('Cooking Oil', 'Oils', 3.00, 'Vegetable cooking oil'),
('Salt', 'Seasonings', 0.50, 'Iodized salt'),
('Sugar', 'Sweeteners', 1.80, 'Granulated sugar')
]
cursor.executemany('INSERT INTO products (name, category, price, description) VALUES (?, ?, ?, ?)', products)
# Insert sample distribution centers
centers = [
('Mumbai Hub', 'Mumbai, India', 10000),
('Delhi Hub', 'Delhi, India', 15000),
('Bangalore Hub', 'Bangalore, India', 8000)
]
cursor.executemany('INSERT INTO distribution_centers (name, location, capacity) VALUES (?, ?, ?)', centers)
conn.commit()
conn.close()
if __name__ == '__main__':
insert_sample_data()
print("Sample data inserted successfully!")
Why we're doing this: Adding sample data helps us test our system. We're simulating a real-world scenario where we have different products and distribution centers that will be used in our distribution network.
Step 5: Create a Basic Distribution Management Interface
Now, let's create a simple interface to manage our distribution system. Create a file called manager.py:
import sqlite3
def display_products():
conn = sqlite3.connect('distribution.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM products')
products = cursor.fetchall()
print("\n--- Products ---")
for product in products:
print(f"ID: {product[0]}, Name: {product[1]}, Category: {product[2]}, Price: ${product[3]}")
conn.close()
def display_centers():
conn = sqlite3.connect('distribution.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM distribution_centers')
centers = cursor.fetchall()
print("\n--- Distribution Centers ---")
for center in centers:
print(f"ID: {center[0]}, Name: {center[1]}, Location: {center[2]}, Capacity: {center[3]}")
conn.close()
def add_distribution_route(product_id, center_id, quantity):
conn = sqlite3.connect('distribution.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO distribution_routes (product_id, center_id, quantity, status) VALUES (?, ?, ?, ?)',
(product_id, center_id, quantity, 'Active'))
conn.commit()
conn.close()
print(f"Distribution route added successfully!")
if __name__ == '__main__':
display_products()
display_centers()
Why we're doing this: This interface allows us to view our products and distribution centers, and to add new distribution routes. It simulates the kind of management system that would be used to oversee distribution networks in emerging markets.
Step 6: Run Your Distribution System
Now, let's run our system to see everything in action. Open your terminal or command prompt, navigate to your project directory, and run:
python database.py
This creates the database structure.
python sample_data.py
This adds our sample data to the database.
python manager.py
This runs the manager interface and displays our products and distribution centers.
Step 7: Test Adding a New Distribution Route
Let's modify our manager.py file to test adding a new distribution route:
import sqlite3
def display_products():
conn = sqlite3.connect('distribution.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM products')
products = cursor.fetchall()
print("\n--- Products ---")
for product in products:
print(f"ID: {product[0]}, Name: {product[1]}, Category: {product[2]}, Price: ${product[3]}")
conn.close()
def display_centers():
conn = sqlite3.connect('distribution.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM distribution_centers')
centers = cursor.fetchall()
print("\n--- Distribution Centers ---")
for center in centers:
print(f"ID: {center[0]}, Name: {center[1]}, Location: {center[2]}, Capacity: {center[3]}")
conn.close()
def add_distribution_route(product_id, center_id, quantity):
conn = sqlite3.connect('distribution.db')
cursor = conn.cursor()
cursor.execute('INSERT INTO distribution_routes (product_id, center_id, quantity, status) VALUES (?, ?, ?, ?)',
(product_id, center_id, quantity, 'Active'))
conn.commit()
conn.close()
print(f"Distribution route added successfully!")
if __name__ == '__main__':
display_products()
display_centers()
# Add a sample distribution route
add_distribution_route(1, 1, 500)
Run this updated manager.py file to see how a new distribution route is added to our system.
Summary
In this tutorial, you've learned how to build a basic distribution management system using Python and SQLite. You've created a database structure, added sample data, and built a simple interface to manage your distribution network. While this is a simplified version of what Arpit Agrawal and his team might build for serving 2.5 billion consumers in emerging markets, it demonstrates the foundational concepts of creating scalable distribution ecosystems.
This system can be expanded with more features like real-time tracking, inventory management, and integration with APIs for e-commerce platforms. The key takeaway is that even in emerging markets, technology can be used to create efficient and scalable distribution systems that connect products with underserved populations.



