Obtaining Your Printer Credentials and Save in settings.toml

  1. Login to MakerWorld.

  2. Open the dev-tools (F12 in most browsers) and select Application > Cookies > https://makerworld.com.

  3. Copy the token string and save it as BAMBU_ACCESS_TOKEN in settings.toml.

  4. Access https://makerworld.com/api/v1/design-user-service/my/preference and copy uid as USER_ID.

  5. Access https://makerworld.com/api/v1/iot-service/api/user/bind and copy dev_id as DEVICE_ID.

  6. 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:

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.MQTT instance.

  • 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 True if the MQTT client is currently connected.

Queries

pushall()

Request a full state snapshot from the printer.

Returns:

A PrinterStatus instance, or None on timeout.

get_version()

Request hardware and firmware version information.

Returns:

The raw JSON response dict, or None on timeout.

get_firmware_history()

Request the firmware version history.

Returns:

The raw JSON response dict, or None on 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 True if the MQTT client is currently connected.

pushall()

Request a full state snapshot from the printer.

Returns:

A PrinterStatus instance, or None on timeout.

get_version()

Request hardware and firmware version information.

Returns:

The raw JSON response dict, or None on timeout.

get_firmware_history()

Request the firmware version history.

Returns:

The raw JSON response dict, or None on timeout.

PrinterStatus

class bambulabs.PrinterStatus(data)

Wraps the raw JSON dict returned by a pushall response and exposes each printer field as a named, readable property.

All values come from the snapshot captured at the time pushall was called. Use raw to 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 0 if 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 None if 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_report field.

Firmware

firmware_version

Current OTA firmware version string, or None if 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 0 if 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 None if 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_report field.

property firmware_version

Current OTA firmware version string, or None if not present.