This project converts an Ampla Project XML export into an ISA‑95 B2MML Equipment model. It replaces the original XSLT‑only approach with a Python implementation that provides a command‑line interface, a FastAPI service, and multiple output formats.
Ampla Project XML files contain equipment definitions, hierarchy, classes, and properties. This tool reads that XML and produces:
- B2MML Equipment XML
- JSON model
- Excel workbook (.xlsx) with Equipment and Classes sheets
- CSV files for equipment and classes
It also provides:
- Validation warnings for structural issues in the source data
- Diff mode to compare two Ampla configurations and report what changed
- Stats summary with equipment counts, class counts, property totals, and hierarchy depth
The transformer is fully tested and suitable for automation, integration, and comparison of Ampla project configurations.
This project is a direct Python reimplementation of the original XSLT stylesheet published at https://github.com/Ampla/Project-To-B2MML. It reproduces the transformation logic faithfully and adds a CLI, REST API, multiple output formats, and a full test suite including a regression fixture verified against the original XSLT behaviour.
git clone https://github.com/<your-username>/amplab2mml.git
cd amplab2mml
python -m venv .venv
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
pip install -r requirements.txt
b2mml convert input.xml output.xml
b2mml json input.xml output.json
If no output file is provided, JSON is written to stdout:
b2mml json input.xml
b2mml excel input.xml output.xlsx
b2mml stats input.xml
Output as JSON:
b2mml stats --format json input.xml
b2mml html input.xml report.html
b2mml diff baseline.xml updated.xml
Output as JSON:
b2mml diff --format json baseline.xml updated.xml
Save to file:
b2mml diff baseline.xml updated.xml diff.txt
Exits with code 0 if no differences, 1 if differences found — suitable for CI.
Start the FastAPI server:
uvicorn app.api:app --reload
| Method | Path | Description |
|---|---|---|
| GET | /health |
Health check |
| POST | /convert/json |
Receive JSON model |
| POST | /convert/xml |
Receive B2MML XML |
| POST | /convert/excel |
Receive Excel workbook |
| POST | /convert/csv/equipment |
Receive equipment CSV |
| POST | /convert/csv/classes |
Receive classes CSV |
| POST | /convert/html |
Receive HTML report |
| POST | /stats |
Receive model statistics |
| POST | /diff/json |
Diff two files, receive JSON |
| POST | /diff/text |
Diff two files, receive plain text |
All /convert/* and /stats endpoints accept a single file upload field.
/diff/* endpoints accept file_a and file_b.
Interactive API docs are available at http://localhost:8000/docs once the server is running.
Examples:
curl -X POST -F "file=@input.xml" http://localhost:8000/convert/json
curl -X POST -F "file=@input.xml" http://localhost:8000/stats
curl -X POST -F "file_a=@baseline.xml" -F "file_b=@updated.xml" http://localhost:8000/diff/text
The project includes a Docker Compose setup for running the API with hot‑reload and without needing to rebuild the image on every change.
make up
The service will be available at:
http://localhost:8000
make down
app/parsers— parses Ampla Project XML into an lxml element treeapp/transformers— converts the parsed tree into an internal equipment and class modelapp/builders— serialises the model to B2MML XMLapp/validators.py— validates the model and returns human-readable warningsapp/diff.py— compares two models and reports structural differencesapp/stats.py— computes summary statistics from the modelapp/excel_export.py— exports the model to an Excel workbookapp/csv_export.py— exports the model to CSVapp/cli.py— command-line interfaceapp/api.py— FastAPI applicationapp/html_report.py— exports the model to a self-contained HTML reportapp/schemas.py— Pydantic response models for the FastAPI endpointstests/— full test suite including regression fixtures verified against the original XSLT
This project is licensed under the BSD 3‑Clause License.
It includes third‑party material derived from the original
Ampla_to_Equipment_B2MML.xslt by Oleg Tkachenko (2005),
also under the BSD 3‑Clause License.