Generate hierarchical BOMs from Mermaid flowchart diagrams
Project description
blockbom
A Python library to generate hierarchical Bills of Materials (BOMs) from Mermaid flowchart diagrams.
Installation
# Using uv
uv add blockbom
# Using pip
pip install blockbom
Quick Start
from blockbom import generate_bom
# Generate a BOM from a Mermaid diagram
items = generate_bom("diagram.mmd", "output.csv")
# With part metadata
items = generate_bom("diagram.mmd", "output.csv", "parts.yaml")
Usage
Input: Mermaid Flowchart
Create a Mermaid flowchart file (.mmd):
flowchart LR
subgraph enclosure["Main Enclosure"]
A["Power Supply"]
B["Controller"]
C["Sensor"]
end
A --> B
B --> C
C --> D["External Display"]
Optional: Part Metadata
Create a YAML file to enrich your BOM with part numbers, links, and costs:
# parts.yaml
A:
part_number: "PS-12V-5A"
link: "https://example.com/power-supply"
cost: 25.99
B:
part_number: "MCU-ARM-01"
link: "https://example.com/controller"
cost: 15.00
Output: CSV BOM
Level,Qty,Description,Part Number,Purchase Link,Cost
0,1,Main Enclosure,,,
1,1,Power Supply,PS-12V-5A,https://example.com/power-supply,25.99
1,1,Controller,MCU-ARM-01,https://example.com/controller,15.00
1,1,Sensor,,,
0,1,External Display,,,
The Level column indicates hierarchy:
- Level 0: Top-level assemblies or standalone components
- Level 1+: Components nested within subgraphs
API Reference
generate_bom(mermaid_file, output_file, metadata_file=None)
Generate a BOM CSV from a Mermaid flowchart.
Parameters:
mermaid_file: Path to the.mmdfileoutput_file: Path for the output CSVmetadata_file: Optional path to.yamlmetadata file
Returns: List of BOMItem objects
parse_mermaid(content)
Parse Mermaid flowchart content into a structured format.
from blockbom import parse_mermaid
diagram = parse_mermaid('''
flowchart LR
A["Component 1"] --> B["Component 2"]
''')
for node_id, node in diagram.nodes.items():
print(f"{node_id}: {node.label}")
Returns: ParsedDiagram with nodes, edges, subgraphs, and root_node_ids
Supported Mermaid Syntax
- Diagram types:
flowchartandgraph(TD, LR, TB, BT, RL) - Node shapes:
[],(),{},(()),[[]],[()],{{}}, and@{}extended syntax - Edges:
-->,-- label -->,-->|label| - Multiple targets:
A --> B & C & D - Subgraphs:
subgraph id["Title"] ... end - YAML frontmatter (stripped automatically)
Development
# Clone and install
git clone https://github.com/keen/blockbom.git
cd blockbom
uv sync --dev
# Run tests
uv run pytest -v
# Type checking
uv run mypy src/blockbom
# Linting
uv run ruff check src/blockbom
License
MIT
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 blockbom-0.1.0.tar.gz.
File metadata
- Download URL: blockbom-0.1.0.tar.gz
- Upload date:
- Size: 46.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4be9f1f9761f8846608bd72204cd9c304318213918f1c8c5ce5036dec5c88cd
|
|
| MD5 |
08af0d028a7e7be802c49862f0fd6489
|
|
| BLAKE2b-256 |
30e6631c658fb44b009e88c9d5ffeff8d5800064d5cf0f4a0fac07f692bcd58f
|
File details
Details for the file blockbom-0.1.0-py3-none-any.whl.
File metadata
- Download URL: blockbom-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c18391b195a6a369a68f16401104534bffbb69fd904488f645d78396f23d3177
|
|
| MD5 |
ba3a9c78168f1c6baefc9c74097f5a38
|
|
| BLAKE2b-256 |
803ac6d100129676113eb39ad26336b3763e65df1ae7fca6ba81fe2f2668966b
|