Metadata-Version: 2.5
Name: cad-to-bom
Version: 0.1.2
Summary: Bill of materials, build checklist and cost tracker for CAD projects: shop listings across Amazon and AliExpress, alternatives with spec checks, 3D printed parts from your exports.
Project-URL: Homepage, https://github.com/moaazsidat/cad-to-bom
Project-URL: Source, https://github.com/moaazsidat/cad-to-bom
Project-URL: Issues, https://github.com/moaazsidat/cad-to-bom/issues
Project-URL: Changelog, https://github.com/moaazsidat/cad-to-bom/releases
Author: cad-to-bom contributors
License-Expression: MIT
License-File: LICENSE
Keywords: 3d printing,bill of materials,bom,build123d,cad,checklist
Classifier: Environment :: Web Environment
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.11
Provides-Extra: test
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# cad-to-bom

A bill of materials, build checklist and cost tracker for hardware projects designed in code-CAD.

- **Off-the-shelf parts** come from a `bom.toml` file. Each part links to listings on Amazon (any country store), AliExpress or any shop you add.
- **3D printed parts** come from the STL or 3MF files your CAD exports. Each gets a 3D preview, its size, and an estimate of filament weight and cost.
- **Alternative listings** sit next to the original. Each one is checked against the part's specs and flagged until you approve it.
- **Costs** are shown in any currency, using daily exchange rates. Pack sizes are handled: 4 screws from a 100-pack costs the whole pack.
- **Tracking:** each part is *to buy*, *ordered* or *have*, and can carry notes. Filter, sort and search the list.
- **Local and plain:** it runs on your computer and has no dependencies. Your progress is a JSON file you can commit next to your design.

It pairs well with [text-to-cad](https://github.com/earthtojake/text-to-cad) (build123d models built with `cadgen`): export your printed parts and point `bom.toml` at the folder. Any CAD that writes STL or 3MF works the same way.

## Install

```bash
pip install cad-to-bom        # or: pipx install cad-to-bom / uv tool install cad-to-bom
```

This needs Python 3.11 or newer. The 3D preview loads three.js from a CDN, so it needs internet access; everything else works offline.

## Quick start

```bash
cad-to-bom init my-robot       # writes my-robot/bom.toml
cad-to-bom serve -c my-robot --open
```

To try the example project:

```bash
cad-to-bom serve -c examples/desk-lamp --open
```

## bom.toml

```toml
title = "My robot"
currency = "USD"                                  # default display currency
markets = ["amazon.com", "amazon.ca", "aliexpress"]

[[sections]]
id = "drive"
title = "Drive"

[[parts]]
section = "drive"
qty = 2                                           # a number, or text such as "1 m", "~60" or "4 + 2"
# buy = 1                                         # optional: how many listings to buy, when qty doesn't say
name = "608-2RS bearing"
search = "608 2RS bearing"                        # optional; the default is name
notes = "lead screw ends"
specs = { bore_mm = 8, od_mm = 22, width_mm = 7, seal = "2RS" }

  [[parts.links]]                                 # optional: listings can also be added on the page
  market = "amazon.com"
  url = "https://..."
  price = 9.99                                    # in the market's currency unless currency = "..." is set
  pack = 10
  specs = { bore_mm = 8, od_mm = 22, width_mm = 7, seal = "2RS" }

[[printed]]
section = "drive"
paths = ["STL/*.stl", "3MF/*.3mf"]                # globs, relative to bom.toml
material = "PETG"
qty = { motor_mount = 2 }                         # or name a file part_x2.stl

[printing]
price_per_kg = { PLA = 20, PETG = 22 }            # or a single number
currency = "USD"                                  # defaults to the project currency
fill = 0.6                                        # printed mass as a fraction of a solid part; a rough estimate
density = { PETG = 1.27 }                         # g/cm³; common materials are built in
```

Each part gets a stable id made from its section and name, such as `drive-bought-608-2rs-bearing`. Your progress is stored under that id. If you rename a part, set `id = "..."` on it to keep its history.

### Marketplaces

The built-in marketplaces are:

- Amazon: `amazon.com`, `amazon.ca`, `amazon.co.uk`, `amazon.de`, `amazon.fr`, `amazon.it`, `amazon.es`, `amazon.nl`, `amazon.se`, `amazon.pl`, `amazon.co.jp`, `amazon.com.au`, `amazon.in`, `amazon.com.mx`, `amazon.com.br`, `amazon.sg`, `amazon.ae`
- `aliexpress`

You can add any other shop, or override a built-in one:

```toml
markets = [
  "amazon.co.uk",
  { id = "aliexpress", currency = "EUR" },        # the currency your AliExpress account shows
  { id = "mcmaster", name = "McMaster-Carr", currency = "USD", search = "https://www.mcmaster.com/{q}" },
]
```

### Finding parts

cad-to-bom does not scrape shops. Each part shows a **Find** link for every marketplace, which opens that shop's search for the part. When you choose a listing, paste its URL, price and pack size into the side panel, or use the CLI (`cad-to-bom link ...`). Because the CLI and the JSON API are plain, a browser agent can fill in listings for you.

### Alternatives, spec checks and approval

Each marketplace can hold one **original** listing (the part as specified) and any number of **alternatives**.

- Give the part `specs`, and give each listing the specs it states. A listing's specs that don't match the part's, or that the listing doesn't state, show as a diff.
- A listing **needs review** if it is an alternative, or if its specs differ from the part's. Until you approve it:
  - the part is flagged (filter: *Review*);
  - the listing is left out of the cost.
- **Approve fit** marks it checked. **Reject** keeps it on record with a reason, so you don't evaluate it again.
- If you change a listing's URL or specs, its verdict goes back to *unverified*.

From the CLI:

```bash
cad-to-bom link drive-bought-608-2rs-bearing aliexpress https://... --alt --price 3.20 --pack 10 \
    --spec bore_mm=8 --spec od_mm=22 --spec width_mm=7 --spec seal=ZZ
cad-to-bom list --listings                        # shows verdicts and diffs
cad-to-bom verify drive-bought-608-2rs-bearing l2 rejected --reason "ZZ shields, need 2RS seals"
```

### Currencies

Prices are stored in the currency they were listed in, and converted when shown; converted prices are marked `≈`. Rates are the European Central Bank's daily reference rates, fetched from [frankfurter.app](https://frankfurter.app) and cached for 12 hours in `.cad-to-bom/`. To work offline, or to pin rates, set them per USD:

```toml
[fx]
rates = { CAD = 1.40, GBP = 0.79 }
```

### Costs

- **A bought part's cost** is the number of packs needed times the pack price. A quantity with a unit ("375 g", "2 m") counts as one listing; set `buy = n` on the part to say otherwise. It uses the listing you mark "use for cost"; otherwise it uses the cheapest usable listing.
- **A printed part's cost** is mesh volume × density × fill × price per kg. Treat it as an estimate.
- **The top bar** shows the total, what you have spent so far (*ordered* plus *have*), what is still to buy, and how many parts have no price yet.

## Using it with text-to-cad

Export your printed parts from the models. You can do this one at a time:

```bash
cadgen export <model id> STL/bracket.stl
```

Or let the project's `exports.py` write them all. Then list the folders in `[[printed]]`. The page rescans on every load, so a fresh export appears when you reload.

To print more than one copy of a part, add `_x<n>` to its file name (`clip_x4.stl`) or set a `qty` table.

## Command line

| Command | What it does |
| --- | --- |
| `cad-to-bom init [dir]` | Writes a starter `bom.toml`. |
| `cad-to-bom serve [-c bom.toml] [--host] [--port] [--open]` | Serves the page. |
| `cad-to-bom list [--missing] [--listings] [--currency EUR] [--json]` | Lists items, their listings and diffs. |
| `cad-to-bom summary [--currency EUR]` | Shows cost totals per section. |
| `cad-to-bom search [ids...] [--market amazon.de] [--open]` | Prints search links for parts that have no listing. |
| `cad-to-bom link <id> <market> <url> [--price] [--pack] [--currency] [--alt] [--spec k=v]` | Records a listing. |
| `cad-to-bom verify <id> <listing> approved\|rejected\|unverified [--reason]` | Records whether a listing fits. |
| `cad-to-bom status todo\|ordered\|have <ids...>` | Sets the status of one or more parts. |
| `cad-to-bom import-md BOM.md` | Turns markdown BOM tables (with Qty and Part columns) into `[[parts]]`. |

## Files

| File | Contents | Commit it? |
| --- | --- | --- |
| `bom.toml` | What the design needs. | Yes. |
| `bom-state.json` | Status, notes, listings and verdicts, written by the page and the CLI. | Yes, to share progress; ignore it to keep progress private. |
| `.cad-to-bom/` | Cached exchange rates and mesh measurements. | No. |

## Security

`serve` listens on `127.0.0.1` and has **no authentication**. Anyone who can reach the port can read and edit your BOM. To use it from other devices, put it behind something that does authenticate, such as an SSH tunnel, a VPN, or `tailscale serve`, rather than binding to `0.0.0.0` on an untrusted network.

## Development

```bash
python -m venv .venv && .venv/bin/pip install -e '.[test]' && .venv/bin/pytest
```

## License

MIT
