Extract and re-insert gcode from Bambu Lab .gcode.3mf files
Project description
bambuuzle
Extract and re-insert G-code from Bambu Lab .gcode.3mf files.
What is this?
Bambu Lab printers use .gcode.3mf files — which are just ZIP archives containing G-code, metadata, thumbnails, and MD5 checksums. bambuuzle lets you:
- Extract plate G-code for editing
- Re-insert modified G-code (with automatic MD5 recomputation)
- Create
.gcode.3mffiles from scratch - Programmatically transform G-code via the Python API
Zero dependencies — uses only Python stdlib (zipfile, hashlib, json).
Installation
pip install bambuuzle
CLI Usage
Extract G-code from a plate
# Extract plate 1 (default) → writes plate_1.gcode
bambuuzle get_plate my_print.gcode.3mf
# Extract plate 2 → writes plate_2.gcode
bambuuzle get_plate my_print.gcode.3mf --plate 2
Re-insert modified G-code
# Edit plate_1.gcode however you like, then:
bambuuzle put_plate my_print.gcode.3mf
# Write to a new file instead of overwriting
bambuuzle put_plate my_print.gcode.3mf --output modified.gcode.3mf
The MD5 checksum is automatically recomputed — no manual hash wrangling needed.
Python API
Read and modify
from bambuuzle import BambuFile
bf = BambuFile.open("my_print.gcode.3mf")
# Access plate gcode
plate = bf.plate(1)
print(f"Gcode length: {len(plate.gcode)} chars")
# Modify
plate.gcode = plate.gcode.replace("M104 S200", "M104 S210")
# Save (MD5 auto-recomputed)
bf.save("modified.gcode.3mf")
Create from scratch
from bambuuzle import BambuFile
bf = BambuFile()
bf.add_plate(gcode="G28\nG1 X100 Y100 F3000\nM84\n")
bf.save("new_print.gcode.3mf")
Transform helper
from bambuuzle.bambu_file import transform
def add_pause_at_layer(gcode: str) -> str:
return gcode.replace(
"; LAYER_CHANGE",
"; LAYER_CHANGE\nM400\nM25 ; pause",
1, # only first occurrence
)
transform("input.gcode.3mf", "output.gcode.3mf", add_pause_at_layer)
The .gcode.3mf format
A .gcode.3mf is a ZIP archive with this structure:
├── [Content_Types].xml
├── _rels/.rels
├── 3D/3dmodel.model
└── Metadata/
├── plate_1.gcode ← The actual G-code
├── plate_1.gcode.md5 ← MD5 hex digest (must match gcode)
├── plate_1.json ← Plate metadata
├── plate_1.png ← Thumbnail
└── ...
Key gotcha: if the MD5 doesn't match the G-code, Bambu Studio and the printer will reject the file. bambuuzle handles this automatically.
Development
git clone https://github.com/retospect/bambuuzle.git
cd bambuuzle
pip install -e ".[dev]"
pytest
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 bambuuzle-0.1.0.tar.gz.
File metadata
- Download URL: bambuuzle-0.1.0.tar.gz
- Upload date:
- Size: 44.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c455a8209189e520ce37e8cb11af70e1a2ccd71c1667263c3b874aa8b8b8e59e
|
|
| MD5 |
b59d7cd4347ef4d10997bb86f3808498
|
|
| BLAKE2b-256 |
8eee10ff24faaec9fba8755b16b91c261129157ad778f6abc5b8ada4dc9aa242
|
Provenance
The following attestation bundles were made for bambuuzle-0.1.0.tar.gz:
Publisher:
publish.yml on retospect/bambuuzle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bambuuzle-0.1.0.tar.gz -
Subject digest:
c455a8209189e520ce37e8cb11af70e1a2ccd71c1667263c3b874aa8b8b8e59e - Sigstore transparency entry: 1209380116
- Sigstore integration time:
-
Permalink:
retospect/bambuuzle@e50e325ec37ce3bc67f23604e0cc8d4c5a13ca45 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/retospect
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e50e325ec37ce3bc67f23604e0cc8d4c5a13ca45 -
Trigger Event:
release
-
Statement type:
File details
Details for the file bambuuzle-0.1.0-py3-none-any.whl.
File metadata
- Download URL: bambuuzle-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.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 |
dd3a6c2beb3c6c0cba028bd06807f512645c5f72ee335654484c9f364e83406e
|
|
| MD5 |
345993635e25708af3bde65b4f33b248
|
|
| BLAKE2b-256 |
ce6fd3517b102159dc31be392b037129f2dfcafef2dabda76f32c2a3f860b19b
|
Provenance
The following attestation bundles were made for bambuuzle-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on retospect/bambuuzle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bambuuzle-0.1.0-py3-none-any.whl -
Subject digest:
dd3a6c2beb3c6c0cba028bd06807f512645c5f72ee335654484c9f364e83406e - Sigstore transparency entry: 1209380189
- Sigstore integration time:
-
Permalink:
retospect/bambuuzle@e50e325ec37ce3bc67f23604e0cc8d4c5a13ca45 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/retospect
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e50e325ec37ce3bc67f23604e0cc8d4c5a13ca45 -
Trigger Event:
release
-
Statement type: