# Open-Source Garment Industry Calculators — npm + PyPI Toolkit

> Eight free, production-tested garment manufacturing calculators on npm and PyPI: SMV, piece-rate, AQL sampling, DHU, line efficiency, fabric consumption, CMT cost, and bundle IDs. Built and used in production by Scan ERP.

**Source:** [https://scanerp.pro/blog/open-source-garment-toolkit.html](https://scanerp.pro/blog/open-source-garment-toolkit.html)

---

Open-Source Garment Industry Calculators — npm + PyPI Toolkit | Scan ERP

# The Open-Source Garment Industry Toolkit — Eight Free Calculators on npm and PyPI

 S
 Santosh Rijal

 ·
 May 11, 2026
 ·
 9 min read
 Garment Industry

 Over the last two years building [Scan ERP](https://scanerp.pro/) for our own CMT factory in Nepal, I kept writing the same garment-industry formulas in different places — SMV calculation, AQL sample sizing, DHU benchmarks, line efficiency, fabric consumption, CMT cost. Then I would lose them. Then I would write them again.

 So I published them. Eight production-tested, MIT-licensed packages on **npm** (for Node.js / TypeScript) and **PyPI** (for Python) — the exact same code we use in production every day. No accounts, no email signup, no paywall. `npm install` or `pip install` and you have the formula.

## Why these formulas needed packages

 Most garment-industry quality and costing formulas live in spreadsheets, PDF reference books, or articles on OnlineClothingStudy and Fibre2Fashion. They are accurate, but if you are a developer building software for a factory — an Industrial Engineer dashboard, a costing tool, a quality-control app — you have to read the article, transcribe the formula into code, decide your own validation rules, and hope you got the edge cases right.

 I got them wrong more than once. For example, the AQL sampling table from *ISO 2859-1:1999 Table II-A* has a specific column-offset pattern where the accept/reject numbers slide diagonally as inspection level changes — transcribing it from a PDF is fragile. We caught and fixed a column-offset bug after cross-verifying against published QIMA reference values. Tests caught it. Without tests, that bug would have been silently rejecting good shipments or accepting bad ones.

## The eight packages

### 1. SMV / SAM Calculator

 **What it does:** Stopwatch-method SMV calculation with PA (performance rating) and allowance percentages. Returns basic time, normal time, and standard time.

 **Why it matters:** SMV (Standard Minute Value) is the foundation of every other metric — piece-rate, line efficiency, CMT cost, capacity planning. If your SMV is wrong, everything downstream is wrong.

- npm: [garment-smv-calculator](https://www.npmjs.com/package/garment-smv-calculator)
- PyPI: [garment-smv-calculator](https://pypi.org/project/garment-smv-calculator/)

### 2. Piece-Rate Calculator

 **What it does:** Calculates operator earnings from piece-rate, with optional quality bonus (15% for 90+ score with no defects), speed bonus (10% for 10%+ faster than target), and overtime (1.5× after 8 hours).

 **Why it matters:** Piece-rate is how most operators in garment factories are paid. Disputes over earnings are the #1 source of factory floor unrest. A single source of truth eliminates "the supervisor calculated it wrong" arguments.

- npm: [garment-piece-rate](https://www.npmjs.com/package/garment-piece-rate)
- PyPI: [garment-piece-rate](https://pypi.org/project/garment-piece-rate/)

### 3. AQL Sampling Calculator (NEW)

 **What it does:** Implements **ISO 2859-1:1999 Table II-A** — given lot size, inspection level (GI/GII/GIII) and AQL level, returns sample size, accept/reject numbers, and an accept/reject decision function. Includes 3-tier garment inspection (critical AQL 0.65 + major AQL 2.5 + minor AQL 4.0).

 **Why it matters:** Every shipment to a brand buyer is inspected against AQL. If you sample wrong, you either ship defective product or reject good lots. Cross-verified against QIMA's published reference (L+AQL2.5 = Accept 10, Reject 11).

- npm: [garment-aql-calculator](https://www.npmjs.com/package/garment-aql-calculator)
- PyPI: [garment-aql-calculator](https://pypi.org/project/garment-aql-calculator/)

### 4. DHU Calculator (NEW)

 **What it does:** Calculates *Defects Per Hundred Units* — the standard daily QC metric. Supports breakdown by defect type (broken-stitch, sizing, color-shade), aggregation across multiple checkers, and classification against industry benchmarks (EXCELLENT ≤5%, GOOD ≤10%, ACCEPTABLE ≤15%, POOR ≤25%, CRITICAL >25%).

 **Why it matters:** Read more in our deep dive on [how we cut rejection from 8% to under 3%](reduce-rejection-rate-dhu-garment-factory.html). DHU is the leading indicator — rejection rate is the trailing one.

- npm: [garment-dhu-calculator](https://www.npmjs.com/package/garment-dhu-calculator)
- PyPI: [garment-dhu-calculator](https://pypi.org/project/garment-dhu-calculator/)

### 5. Line Efficiency Calculator (NEW)

 **What it does:** Efficiency % = (Output × SAM) / (Workers × Hours × 60) × 100. Also computes target output for a desired efficiency, required worker count for a target, and line-balance / bottleneck analysis from per-operation SAM data.

 **Why it matters:** Bangladesh/India/Nepal industry average is ~50%. World-class is 75%+. Every percentage point of efficiency improvement reduces your CMT cost directly. Knowing the bottleneck is the first step.

- npm: [garment-line-efficiency](https://www.npmjs.com/package/garment-line-efficiency)
- PyPI: [garment-line-efficiency](https://pypi.org/project/garment-line-efficiency/)

### 6. Fabric Consumption Calculator (NEW)

 **What it does:** Knit method (GSM × area for T-shirts, polos, hoodies) and woven method (marker length / pieces per marker for shirts and trousers). Adds wastage allowance, converts between GSM and oz/yd².

 **Why it matters:** Fabric is 60-70% of garment cost. Quoting CMT without accurate fabric consumption is how factories lose money on contracts.

- npm: [garment-fabric-consumption](https://www.npmjs.com/package/garment-fabric-consumption)
- PyPI: [garment-fabric-consumption](https://pypi.org/project/garment-fabric-consumption/)

### 7. CMT Cost Calculator (NEW)

 **What it does:** Per-garment CMT cost = (SAM × CPM / Efficiency) + Trims + Packaging. Calculates CPM from your factory's monthly cost. Compares CMT across countries using built-in CPM defaults (Bangladesh $0.10, India $0.18, Vietnam $0.16, USA $1.00, etc.).

 **Why it matters:** When a brand asks "why is your quote $4.20 when Bangladesh is $3.50?", you need to be able to defend each input — not just the bottom line.

- npm: [garment-cmt-cost](https://www.npmjs.com/package/garment-cmt-cost)
- PyPI: [garment-cmt-cost](https://pypi.org/project/garment-cmt-cost/)

### 8. Bundle ID Generator

 **What it does:** Generates and parses garment-industry bundle QR codes in the format `STYLE-LOT-COLOR-SIZE-BUNDLE#-COMPONENT`. Includes validation.

- npm: [garment-bundle-id](https://www.npmjs.com/package/garment-bundle-id)
- PyPI: [garment-bundle-id](https://pypi.org/project/garment-bundle-id/)

## Five-minute quickstart

### Node.js

```
npm install garment-aql-calculator garment-dhu-calculator garment-line-efficiency garment-fabric-consumption garment-cmt-cost

// Quote a T-shirt from Nepal at 50% line efficiency
const { calculateCMTCost } = require('garment-cmt-cost');
const { calculateKnitConsumption } = require('garment-fabric-consumption');

const fabric = calculateKnitConsumption({
 bodyLength: 70, chest: 56, sleeveLength: 22, sleeveWidth: 22,
 gsm: 180, wastagePercent: 8,
});
// → per garment 0.190 kg, per dozen 2.28 kg

const cmt = calculateCMTCost({ sam: 15, cpm: 0.09, efficiency: 0.5, trims: 0.30, packaging: 0.20 });
// → CMT $3.20 per garment

```

### Python

```
pip install garment-aql-calculator garment-dhu-calculator garment-line-efficiency garment-fabric-consumption garment-cmt-cost

from garment_aql_calculator import calculate_aql

# QC sampling for a 2,400-piece shipment
plan = calculate_aql(lot_size=2400, inspection_level="GII", aql=2.5)
# → sample 125 garments, accept ≤7 defects, reject ≥8
print(plan["sample_size"], plan["accept_number"], plan["reject_number"])

```

## What's tested, what's not

 Every package ships with an inline test suite that cross-verifies against published industry references — QIMA's AQL examples, OnlineClothingStudy's DHU worked examples, hand-checked GSM-area calculations. As of release, 327 tests pass across the five new calculators (npm + PyPI combined).

 What is *not* tested: country-specific labour cost defaults will go stale as wages rise. They are intentionally exposed as a constant (`COUNTRY_CPM_DEFAULTS`) so you can override per-factory rather than relying on the bundled value.

## Why we open-sourced this

 Three reasons.

 **First:** the formulas are not proprietary. ISO 2859-1, DHU, line-efficiency, fabric GSM — these are public knowledge that hundreds of factories already use. The only value-add of keeping them internal would be artificial scarcity.

 **Second:** our actual product is the integrated ERP, not the calculators. [Scan ERP](https://scanerp.pro/) connects the SMV to the work pool to the operator earnings to the QC dashboard to the Pi-attached label printer. Anyone can use these calculators standalone; the integrated workflow is what factories pay for.

 **Third:** if a junior IE in a Bangladesh or Vietnam factory uses these to build a tool that helps their plant, that is a good outcome regardless of whether they ever become a Scan ERP customer.

## Roadmap

 Likely additions over 2026, ordered by how often we use them internally:

- Cut-order planning — lay length, layer count, marker utilization
- 4-point fabric inspection score — points per 100 m² with grading
- Operator skill matrix — multi-skill premium, training-curve estimation
- Capacity planning — production day SAM total, hour-by-hour target schedule
- Garment-industry KPI dashboard package — combines everything above

 Issue requests and PRs are welcome on the individual GitHub repos.

## Related reading

- [How to calculate SMV using the stopwatch method](how-to-calculate-smv-stopwatch-method-garment-industry.html)
- [Piece-rate payment calculation in a garment factory](piece-rate-payment-calculation-garment-factory.html)
- [Reducing rejection rate from 8% to under 3% (DHU deep-dive)](reduce-rejection-rate-dhu-garment-factory.html)
- [Sewing line efficiency calculation](sewing-line-efficiency-calculation-garment-factory.html)
- [SMV-based costing and CMT pricing](smv-costing-cmt-pricing-garment-factory.html)

---

 *About: Santosh Rijal is a medical doctor and the founder of [Scan ERP](https://scanerp.pro/), a manufacturing ERP for CMT garment factories. He owns and operates a knit garment factory in Nepal. Connect on [GitHub](https://github.com/drmcoder).*

---

Built by [Scan ERP](https://scanerp.pro/) — QR-based ERP for CMT garment factories.
