Turn a Python inventory simulation into a single-page web app your team can use.
The app lets you test fixed-cycle replenishment under deterministic and stochastic demand, visualize Demand / Orders / IOH, and compare simple vs lead-time-aware ordering.
- Click Run simulation once; after that, any parameter change auto-recomputes and redraws.
- Results are reproducible (fixed random seed).
- Engine modules remain as-is, wrapped with a minimal Streamlit UI.
Click the image below to open the full video tutorial on YouTube:
- Deterministic and stochastic demand simulations
- Simple Ordering vs Lead-time Ordering (receipt timing aligned with cycle end)
- Compact 3-panel chart (Demand / Orders / IOH)
- Inline Quick Context cards (core inputs at a glance)
- KPIs: Stockout days, Min IOH, Avg IOH
- Auto re-run after initial click
This app is deployed on Streamlit Community Cloud:
👉 https://supplyscience-inventory.streamlit.app/
You can deploy your own copy to Streamlit Community Cloud by connecting your GitHub repo and selecting app.py as the main file.
Streamlit UI (app.py)
↓
Inventory Models (pydantic) — inventory_models.py
↓
Simulation Engine (pandas / numpy) — inventory_analysis.py
- The UI only orchestrates inputs, rendering, and calling the existing engine.
- You can later expose the engine via FastAPI or integrate with other frontends.
- Python 3.10+
- Git (optional)
- Inventory Management Tutorial Source Code: https://github.com/samirsaci/tuto_inventory
- One of:
- Linux:
uv(recommended) orpip - Windows:
pip(PowerShell / Command Prompt)
- Linux:
If you don’t have Python, install it from python.org or via your OS package manager.
tuto_inventory /
├─ app.py
├─ requirements.txt
└─ inventory/
├─ init.py
├─ inventory_analysis.py
└─ inventory_models.py
Keep your inventory_analysis.py and inventory_models.py as-is. Ensure
inventory/__init__.pyexists (can be empty).
# Install uv if needed
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create a virtual environment and activate it
uv init
uv venv
source .venv/bin/activate
# Install
uv pip install -r requirements.txtmkdir tuto_inventory
cd tuto_inventory
py -m venv .venv
.\.venv\Scripts\activate
pip install -r requirements.txt# Run the app
streamlit run app.py
- In the sidebar, set:
D(annual demand),T_total(days),LD(lead time),T(cycle),Q(order qty),initial_ioh(initial stock),sigma(daily demand std. dev.), and Method.
- Click Run simulation (first time only).
- Adjust any parameter: the app auto-recomputes.
- Read Quick Context and KPIs.
- Interpret the Demand / Orders / IOH chart.
Reproducibility: the app uses a fixed NumPy seed (
1991).
Defaults often used:
D = 2000,T_total = 365⇒D_day ≈ 5.48.
WithT = 10→Q ≈ 55andinitial_ioh ≈ 55. Keepsigma = 0unless noted.
“What if your inventory touched zero without ever stocking out?”
Scenario 1 — Lead time = 1 (receive next day)
Set: LD=1, T=10, Q≈55, initial_ioh≈55, sigma=0, Method: Simple Ordering
See: IOH drains to ~0 at cycle end; receipt next day → no negatives (clean sawtooth).
“Same policy, +1 day lead time—what breaks first?”
Scenario 2 — Lead time = 2 (receive two days later)
Set: LD=2, T=10, Q≈55, initial_ioh≈55, sigma=0, Method: Simple Ordering
See: Receipt arrives late; IOH dips below zero → stockouts (timing issue).
“Can we fix stockouts by just ordering more?”
Scenario 3 — Keep timing, increase quantity
Set: LD=2, T=10, Q≈ D_day × (T + (LD−1)) ≈ 60, initial_ioh=60, sigma=0, Method: Simple Ordering
See: Negatives avoided but excess inventory (higher holding costs).
Lesson: Treats the symptom (level), not the cause (timing).
“What if we keep quantity but fix the timing?”
Scenario 4 — Anticipate lead time (lead-time-aware trigger)
Set: LD=2, T=10, Q≈55, initial_ioh≈55, sigma=0, Method: Lead-time Ordering
See: Receipt realigns with cycle boundary; stable service without excess.
Interpretation: Approx. ROP ≈ D_day × LD.
“What does the EOQ sawtooth actually look like?”
Scenario 5 — EOQ cycle, lead time = 1 (manual)
Set: LD=1, Q=400, T≈73, initial_ioh=400, sigma=0, Method: Simple Ordering
See: Classic EOQ sawtooth; avg IOH ≈ Q*/2; no negatives.
“Add uncertainty—does timing still save you?”
Scenario 6 — Stochastic demand (Normal), lead time = 5
Set: LD=5, T=10, Q≈55, initial_ioh≈55, sigma=2.5, Method: Simple Ordering
See: IOH fluctuates; stockouts can appear despite fixed timing.
Lesson: You need safety stock for demand/lead-time variability.
-
ImportError
Ensureinventory/__init__.pyexists and both engine files are ininventory/. -
Blank page / chart not shown
Click Run simulation once; then changes auto-recompute. -
Charts not visible
Confirmmatplotlibis installed and no ad-blocker is blocking Streamlit content. -
Different numbers vs video
Check that your inputs match the scenario values above.
These are just suggestions to help you pursue the exercise.
- Add CSV export of results (table +
st.download_button) - Add Safety Stock / ROP helpers for stochastic cases
- Package the engine as a FastAPI microservice
- Deploy on Streamlit Community Cloud
Senior Supply Chain and Data Science consultant with international experience working on Logistics and Transportation operations. For consulting or advising on analytics and sustainable supply chain transformation, feel free to contact me via Logigreen Consulting or LinkedIn
