Stock replenishment simulation library.
Project description
replenishment
replenishment is a Python library for stock replenishment simulation, policy optimization, and decision visualization.
It is designed for teams that want to:
- simulate replenishment policies against historical or synthetic demand
- optimize mean-forecast safety stock,
k*RMSE, and percentile-target policies - compare policies visually on replenishment time series
- move cleanly between CSV/DataFrame inputs and simulation configs
Supported Python Versions
The project is tested on Python 3.10, 3.11, 3.12, and 3.13.
Yes, Python 3.13 is out and stable. Python 3.13.0 was officially released on October 7, 2024.
Installation
Install from PyPI
pip install replenishment
Create a Development Environment with uv
Choose any supported Python version. 3.13 is the default below.
uv python install 3.13
uv venv --python 3.13
source .venv/bin/activate
uv sync --extra dev
To work on another supported version, replace 3.13 with 3.10, 3.11, or 3.12.
Run the test suite with:
uv run pytest
Quickstart
This example optimizes a mean-forecast safety stock factor on a backtest window and applies the learned policy on the forecast horizon.
from replenishment import (
generate_standard_simulation_rows,
optimize_point_forecast_policy_and_simulate_actuals,
plot_replenishment_decisions,
replenishment_decision_rows_to_dataframe,
split_standard_simulation_rows,
standard_simulation_rows_to_dataframe,
)
rows = generate_standard_simulation_rows(
n_unique_ids=1,
periods=18,
start_date="2031-01-01",
frequency_days=30,
forecast_start_period=10,
history_mean=52,
history_std=6,
forecast_mean=48,
forecast_std=5,
lead_time=2,
initial_on_hand=30,
current_stock=30,
seed=7,
)
backtest_rows, eval_rows = split_standard_simulation_rows(rows)
optimized, _, decision_rows = optimize_point_forecast_policy_and_simulate_actuals(
backtest_rows,
eval_rows,
candidate_factors=[0.8, 0.9, 1.0],
)
rows_df = standard_simulation_rows_to_dataframe(rows, library="pandas")
decision_df = replenishment_decision_rows_to_dataframe(decision_rows, library="pandas")
example_id = decision_df["unique_id"].iloc[0]
plot_replenishment_decisions(
rows_df,
decision_df,
unique_id=example_id,
title="Mean forecast + safety stock (optimized)",
decision_style="line",
)
Example Workflows
Mean Forecast + Safety Stock
Optimize a point-forecast safety stock factor on historical rows, then inspect the resulting replenishment decisions on the forecast horizon.
k*RMSE + Forecast-Level Buffering
Use k*RMSE for the base safety stock and optionally increase it when lead-time
forecast quantities rise above a baseline. The README plot below uses three
articles with progressively steeper ramps so the extra safety stock is visible
directly on the replenishment timeline.
Percentile Target Optimization
Optimize the percentile target per article on backtest rows, then simulate and visualize the chosen forecast target on the evaluation horizon.
Notebooks
Runnable walkthroughs live in notebooks/:
notebooks/mean_forecast_safety_stock_example.ipynb: mean forecast safety stock optimizationnotebooks/k_rmse_safety_stock_optimization_example.ipynb:k*RMSEoptimization and forecast-level bufferingnotebooks/percentile_optimization_example.ipynb: percentile-target optimizationnotebooks/mean_forecast_policy_variants_example.ipynb: compare policy variantsnotebooks/generated_data_example.ipynb: synthetic data generationnotebooks/stock_replenishment_example.ipynb: table-oriented data loading workflow
Development and Contribution
Contributions are welcome. If you open a PR, keep it easy to review:
- add or update tests for behavior changes
- update notebooks, README examples, and plot assets when public behavior changes
- include before/after plots when you change plotting behavior
- keep PRs focused rather than bundling unrelated refactors
See CONTRIBUTING.md for setup, test, and pull request guidance.
Good Areas for Collaboration
If you want to make the project more useful and more credible to other teams, these are high-leverage contribution areas:
- richer policy variants, such as minimum order quantities, case-pack constraints, and promotion-aware demand handling
- benchmark datasets and scenario packs for retail seasonality, long lead times, and stockout-heavy stress tests
- more notebook walkthroughs that compare service-level objectives and business tradeoffs
- packaging and docs polish, including API docs, changelogs, and release notes
- plotting improvements for aggregate dashboards and multi-SKU diagnostics
Project Links
- Homepage: https://github.com/janrth/replenishment
- Issues: https://github.com/janrth/replenishment/issues
- Changelog: CHANGELOG.md
- License: LICENSE
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 replenishment-0.1.2.tar.gz.
File metadata
- Download URL: replenishment-0.1.2.tar.gz
- Upload date:
- Size: 7.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39619855172c229751ef589e9997d3914261f6eca1a519042f0697b20487d7ea
|
|
| MD5 |
576925f60b59ddeb81c4badfcdcca20f
|
|
| BLAKE2b-256 |
0cd64f97c9c205241350aee4dee0a09cb90a163e3c4d6cd9264f562be9d3ca1b
|
Provenance
The following attestation bundles were made for replenishment-0.1.2.tar.gz:
Publisher:
release.yml on janrth/replenishment
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
replenishment-0.1.2.tar.gz -
Subject digest:
39619855172c229751ef589e9997d3914261f6eca1a519042f0697b20487d7ea - Sigstore transparency entry: 1117923613
- Sigstore integration time:
-
Permalink:
janrth/replenishment@cfe60d7f14d79933416cc75b7b3d82109cdad694 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/janrth
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cfe60d7f14d79933416cc75b7b3d82109cdad694 -
Trigger Event:
release
-
Statement type:
File details
Details for the file replenishment-0.1.2-py3-none-any.whl.
File metadata
- Download URL: replenishment-0.1.2-py3-none-any.whl
- Upload date:
- Size: 41.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f5b069dd3de5e836b11c1e30102587d965b4db1f666e5bd66db7f62d03324e7
|
|
| MD5 |
ccd0a178865f0aaca58fdf0e8449162b
|
|
| BLAKE2b-256 |
8e06ab654a891bf2f8d4a3b6cf6eb7c75e6e1e9475f76aab991e8ce9d42214fe
|
Provenance
The following attestation bundles were made for replenishment-0.1.2-py3-none-any.whl:
Publisher:
release.yml on janrth/replenishment
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
replenishment-0.1.2-py3-none-any.whl -
Subject digest:
4f5b069dd3de5e836b11c1e30102587d965b4db1f666e5bd66db7f62d03324e7 - Sigstore transparency entry: 1117923695
- Sigstore integration time:
-
Permalink:
janrth/replenishment@cfe60d7f14d79933416cc75b7b3d82109cdad694 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/janrth
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cfe60d7f14d79933416cc75b7b3d82109cdad694 -
Trigger Event:
release
-
Statement type: