Obtaining Your Printer Credentials and Save in settings.toml
Login to MakerWorld.
Open the dev-tools (F12 in most browsers) and select
Application > Cookies > https://makerworld.com.Copy the
tokenstring and save it asBAMBU_ACCESS_TOKENinsettings.toml.Access https://makerworld.com/api/v1/design-user-service/my/preference and copy
uidasUSER_ID.Access https://makerworld.com/api/v1/iot-service/api/user/bind and copy
dev_idasDEVICE_ID.On your printer, go to Settings and obtain the IP address and copy it as
BAMBU_IP.
Misc. information
This library queries your Bambu Labs 3D printer via the Bambu Cloud using MQTT 5.0. Local mode is not supported due to it using MQTT 3.1.1. Issuing commands to your Bambu printer is out of scope for this library.
API Reference
bambulabs
A library to interface with a Bambu Labs 3D printer and query status.
Author(s): Paul Cutler
Implementation Notes
Hardware:
Requires a Bambu Labs 3D printer and Bambu Labs Makerworld account.
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
BambuPrinter
- class bambulabs.BambuPrinter(serial_number, response_timeout=10)
Connect to a Bambu Labs printer over MQTT and query its status.
- Parameters:
mqtt_client – A configured
adafruit_minimqtt.MQTTinstance.serial_number – The printer’s serial number, used to build MQTT topics.
response_timeout – Seconds to wait for a printer response (default 10).
Connection
- connect()
Establish the MQTT connection to the printer.
- loop()
Process pending MQTT messages. Call regularly in your main loop.
- loop_forever()
Block and loop indefinitely, processing MQTT messages.
- is_connected()
Return
Trueif the MQTT client is currently connected.
Queries
- pushall()
Request a full state snapshot from the printer.
- Returns:
A
PrinterStatusinstance, orNoneon timeout.
- get_version()
Request hardware and firmware version information.
- Returns:
The raw JSON response dict, or
Noneon timeout.
- get_firmware_history()
Request the firmware version history.
- Returns:
The raw JSON response dict, or
Noneon timeout.
- connect()
Establish the MQTT connection to the printer.
- loop()
Process pending MQTT messages. Call regularly in your main loop.
- loop_forever()
Block and loop indefinitely, processing MQTT messages.
- is_connected()
Return
Trueif the MQTT client is currently connected.
- pushall()
Request a full state snapshot from the printer.
- Returns:
A
PrinterStatusinstance, orNoneon timeout.
- get_version()
Request hardware and firmware version information.
- Returns:
The raw JSON response dict, or
Noneon timeout.
- get_firmware_history()
Request the firmware version history.
- Returns:
The raw JSON response dict, or
Noneon timeout.
PrinterStatus
- class bambulabs.PrinterStatus(data)
Wraps the raw JSON dict returned by a
pushallresponse and exposes each printer field as a named, readable property.All values come from the snapshot captured at the time
pushallwas called. Userawto access the complete original dict.- Parameters:
data – The raw JSON dict received from the printer’s report topic.
Raw data
- raw
The complete raw JSON dict from the printer.
Print state
- gcode_state
Printer gcode state string (e.g.
RUNNING,PAUSE,FINISH).
- print_percentage
Current print completion percentage (0–100).
- remaining_time
Estimated remaining print time in minutes.
- current_layer
Current layer number being printed.
- total_layers
Total number of layers in the print job.
- gcode_file
Filename of the currently active gcode file.
- subtask_name
Current print subtask / job name.
- print_speed
Print speed level (0=silent, 1=standard, 2=sport, 3=ludicrous).
- print_error_code
Current print error code, or
0if none.
Temperatures
- nozzle_temperature
Current nozzle temperature in degrees Celsius.
- nozzle_temperature_target
Target nozzle temperature in degrees Celsius.
- bed_temperature
Current bed temperature in degrees Celsius.
- bed_temperature_target
Target bed temperature in degrees Celsius.
- chamber_temperature
Current chamber temperature in degrees Celsius.
Fan speeds
- part_fan_speed
Part cooling fan speed (0–255).
- aux_fan_speed
Auxiliary fan speed (0–255).
- chamber_fan_speed
Chamber fan speed (0–255).
Nozzle
- nozzle_type
Installed nozzle type string (e.g.
"brass").
- nozzle_diameter
Installed nozzle diameter in mm.
Filament / AMS
- ams_status
AMS filament / tray status dict, or
Noneif no AMS present.
- vt_tray
External spool (virtual tray) properties dict.
System
- wifi_signal
WiFi signal strength string (e.g.
"-45dBm").
- light_state
Chamber light state list from the system
lights_reportfield.
Firmware
- firmware_version
Current OTA firmware version string, or
Noneif not present.
- property raw
The complete raw JSON dict from the printer.
- property gcode_state
Printer gcode state string (e.g.
RUNNING,PAUSE,FINISH).
- property print_percentage
Current print completion percentage (0–100).
- property remaining_time
Estimated remaining print time in minutes.
- property current_layer
Current layer number being printed.
- property total_layers
Total number of layers in the print job.
- property gcode_file
Filename of the currently active gcode file.
- property subtask_name
Current print subtask / job name.
- property print_speed
Print speed level (0=silent, 1=standard, 2=sport, 3=ludicrous).
- property print_error_code
Current print error code, or
0if none.
- property nozzle_temperature
Current nozzle temperature in degrees Celsius.
- property nozzle_temperature_target
Target nozzle temperature in degrees Celsius.
- property bed_temperature
Current bed temperature in degrees Celsius.
- property bed_temperature_target
Target bed temperature in degrees Celsius.
- property chamber_temperature
Current chamber temperature in degrees Celsius.
- property part_fan_speed
Part cooling fan speed (0–255).
- property aux_fan_speed
Auxiliary fan speed (0–255).
- property chamber_fan_speed
Chamber fan speed (0–255).
- property nozzle_type
Installed nozzle type string (e.g.
"brass").
- property nozzle_diameter
Installed nozzle diameter in mm.
- property ams_status
AMS filament / tray status dict, or
Noneif no AMS present.
- property vt_tray
External spool (virtual tray) properties dict.
- property wifi_signal
WiFi signal strength string (e.g.
"-45dBm").
- property light_state
Chamber light state list from the system
lights_reportfield.
- property firmware_version
Current OTA firmware version string, or
Noneif not present.